From 878a0f050e122ff97683aabbba60c987a725e852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Fri, 10 Aug 2018 17:05:10 +0200 Subject: [PATCH] ld: Put 'sizeof(struct device)' in the generated offsets header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename _DEVICE_STRUCT_SIZE to _DEVICE_STRUCT_SIZEOF. This causes it to be picked by the script 'gen_offset_header.py' and inserted into the header file 'include/generated/offsets.h'. Renaming from x_SIZE to x_SIZEOF will align it's name with the other symbols that denote a sctruct's size, like K_THREAD_SIZEOF. Furthermore, it will allow the symbol to be accessed through a header file define, instead of only as an extern symbol. This is more flexible, and more aligned with the other symbols in offsets. Finally, if we are able to move all of offsets.c symbols into the offsets.h header file we be able to remove offsets.o from the link and thereby simplify the linking process. Signed-off-by: Sebastian Bøe --- include/linker/linker-defs.h | 3 ++- kernel/include/kernel_offsets.h | 2 +- tests/ztest/include/offsets.h | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/ztest/include/offsets.h diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index b5f177cf12c..c915139e0c8 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -22,6 +22,7 @@ #include #include #include +#include /* include platform dependent linker-defs */ #ifdef CONFIG_X86 @@ -52,7 +53,7 @@ */ #ifdef CONFIG_DEVICE_POWER_MANAGEMENT #define DEVICE_COUNT \ - ((__device_init_end - __device_init_start) / _DEVICE_STRUCT_SIZE) + ((__device_init_end - __device_init_start) / _DEVICE_STRUCT_SIZEOF) #define DEV_BUSY_SZ (((DEVICE_COUNT + 31) / 32) * 4) #define DEVICE_BUSY_BITFIELD() \ FILL(0x00) ; \ diff --git a/kernel/include/kernel_offsets.h b/kernel/include/kernel_offsets.h index d129f7d4be5..7a35c956724 100644 --- a/kernel/include/kernel_offsets.h +++ b/kernel/include/kernel_offsets.h @@ -78,6 +78,6 @@ GEN_OFFSET_SYM(_thread_t, custom_data); GEN_ABSOLUTE_SYM(K_THREAD_SIZEOF, sizeof(struct k_thread)); /* size of the device structure. Used by linker scripts */ -GEN_ABSOLUTE_SYM(_DEVICE_STRUCT_SIZE, sizeof(struct device)); +GEN_ABSOLUTE_SYM(_DEVICE_STRUCT_SIZEOF, sizeof(struct device)); #endif /* ZEPHYR_KERNEL_INCLUDE_KERNEL_OFFSETS_H_ */ diff --git a/tests/ztest/include/offsets.h b/tests/ztest/include/offsets.h new file mode 100644 index 00000000000..2cfaadd2d85 --- /dev/null +++ b/tests/ztest/include/offsets.h @@ -0,0 +1,14 @@ +#ifndef __GEN_OFFSETS_H__ +#define __GEN_OFFSETS_H__ + +/* + * This file is a fake replacement for + * $build_dir/zephyr/include/generated/offsets.h + * + * The unittest infrastructure does not know how to generate + * offsets.h, so until this is supported we fake it with this + * file. This allows us to test source files that include offsets.h, + * but don't actually use anything from it when unit testing. + */ + +#endif