kernel: generate placeholders for kobj tables before final build
Due to the use of gperf to generate hash table for kobjects, the addresses of these kobjects cannot change during the last few phases of linking (especially between zephyr_prebuilt.elf and zephyr.elf). Because of this, the gperf generated data needs to be placed at the end of memory to avoid pushing symbols around in memory. This prevents moving these generated blocks to earlier sections, for example, pinned data section needed for demand paging. So create placeholders for use in intermediate linking to reserve space for these generated blocks. Due to uncertainty on the size of these blocks, more space is being reserved which could result in wasted space. Though, this retains the use of hash table for faster lookup. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
317dcd908f
commit
1117169980
19 changed files with 488 additions and 97 deletions
132
CMakeLists.txt
132
CMakeLists.txt
|
@ -350,6 +350,10 @@ if(CONFIG_USERSPACE)
|
|||
set(APP_SMEM_UNALIGNED_DEP app_smem_unaligned_linker)
|
||||
endif()
|
||||
|
||||
if(CONFIG_USERSPACE)
|
||||
set(KOBJECT_LINKER_DEP kobject_linker)
|
||||
endif()
|
||||
|
||||
get_property(TOPT GLOBAL PROPERTY TOPT)
|
||||
set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains,
|
||||
# while -Wl,-T works for both, gcc and clang
|
||||
|
@ -847,6 +851,7 @@ if(CONFIG_USERSPACE)
|
|||
COMMAND
|
||||
${GPERF}
|
||||
--output-file ${KOBJECT_HASH_OUTPUT_SRC_PRE}
|
||||
--multiple-iterations 10
|
||||
${KOBJECT_HASH_LIST}
|
||||
DEPENDS kobj_hash_list ${KOBJECT_HASH_LIST}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
|
@ -1062,10 +1067,137 @@ if(CONFIG_USERSPACE)
|
|||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_USERSPACE)
|
||||
# This CONFIG_USERSPACE block is to create place holders to reserve space
|
||||
# for the gperf generated structures for zephyr_prebuilt.elf.
|
||||
# These place holders are there so that the placement of kobjects would be
|
||||
# the same between linking zephyr_prebuilt.elf and zephyr.elf, as
|
||||
# the gperf hash table is hashed on the addresses of kobjects.
|
||||
# The placeholders are generated from app_smem_unaligned_prebuilt.elf.
|
||||
|
||||
set(KOBJECT_PREBUILT_HASH_LIST kobject_prebuilt_hash.gperf)
|
||||
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE kobject_prebuilt_hash_preprocessed.c)
|
||||
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC kobject_prebuilt_hash.c)
|
||||
set(KOBJECT_PREBUILT_HASH_OUTPUT_OBJ kobject_prebuilt_hash.c.obj)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${KOBJECT_PREBUILT_HASH_LIST}
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE}
|
||||
${GEN_KOBJ_LIST}
|
||||
--kernel $<TARGET_FILE:app_smem_unaligned_prebuilt>
|
||||
--gperf-output ${KOBJECT_PREBUILT_HASH_LIST}
|
||||
${gen_kobject_list_include_args}
|
||||
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
||||
DEPENDS
|
||||
app_smem_unaligned_prebuilt
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
add_custom_target(
|
||||
kobj_prebuilt_hash_list
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_LIST}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
||||
COMMAND
|
||||
${GPERF}
|
||||
--output-file ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
||||
--multiple-iterations 10
|
||||
${KOBJECT_PREBUILT_HASH_LIST}
|
||||
DEPENDS kobj_prebuilt_hash_list ${KOBJECT_PREBUILT_HASH_LIST}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
add_custom_target(
|
||||
kobj_prebuilt_hash_output_src_pre
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE}
|
||||
${PROCESS_GPERF}
|
||||
-i ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
||||
-o ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
||||
-p "struct z_object"
|
||||
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
||||
DEPENDS kobj_prebuilt_hash_output_src_pre ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
add_custom_target(
|
||||
kobj_prebuilt_hash_output_src
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
||||
)
|
||||
|
||||
add_library(
|
||||
kobj_prebuilt_hash_output_lib
|
||||
STATIC ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
||||
)
|
||||
|
||||
set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
|
||||
|
||||
set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
|
||||
PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}")
|
||||
|
||||
add_library(kobj_prebuilt_hash_output_lib_interface INTERFACE)
|
||||
|
||||
target_link_libraries(
|
||||
kobj_prebuilt_hash_output_lib
|
||||
kobj_prebuilt_hash_output_lib_interface
|
||||
)
|
||||
|
||||
foreach(incl ${include_dir_in_interface})
|
||||
target_include_directories(
|
||||
kobj_prebuilt_hash_output_lib_interface
|
||||
INTERFACE ${incl}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
foreach(incl ${sys_include_dir_in_interface})
|
||||
target_include_directories(
|
||||
kobj_prebuilt_hash_output_lib_interface
|
||||
SYSTEM INTERFACE ${incl}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
set(
|
||||
KOBJECT_PREBUILT_HASH_OUTPUT_OBJ_PATH
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/kobj_prebuilt_hash_output_lib.dir/${KOBJECT_PREBUILT_HASH_OUTPUT_OBJ}
|
||||
)
|
||||
|
||||
set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/linker-kobject-prebuilt-data.h")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${KOBJECT_LINKER_HEADER_DATA}
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE}
|
||||
${ZEPHYR_BASE}/scripts/gen_kobject_placeholders.py
|
||||
--object ${KOBJECT_PREBUILT_HASH_OUTPUT_OBJ_PATH}
|
||||
--outdir ${PROJECT_BINARY_DIR}/include/generated
|
||||
--datapct ${CONFIG_KOBJECT_DATA_AREA_RESERVE_EXTRA_PERCENT}
|
||||
--rodata ${CONFIG_KOBJECT_RODATA_AREA_EXTRA_BYTES}
|
||||
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
||||
DEPENDS
|
||||
kobj_prebuilt_hash_output_lib
|
||||
${KOBJECT_PREBUILT_HASH_OUTPUT_OBJ_PATH}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(
|
||||
${KOBJECT_LINKER_DEP}
|
||||
DEPENDS
|
||||
${KOBJECT_LINKER_HEADER_DATA}
|
||||
)
|
||||
endif()
|
||||
|
||||
configure_linker_script(
|
||||
linker_zephyr_prebuilt.cmd
|
||||
"-DLINKER_ZEPHYR_PREBUILT"
|
||||
${APP_SMEM_ALIGNED_DEP}
|
||||
${KOBJECT_LINKER_DEP}
|
||||
${CODE_RELOCATION_DEP}
|
||||
zephyr_generated_headers
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue