mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(system): discard eh_frame sections if disabled in sdkconfig
This commit is contained in:
@@ -1,33 +1,51 @@
|
||||
# For each supported target, a memory.ld.in and sections.ld.in is processed and dictate the
|
||||
# memory layout of the app.
|
||||
#
|
||||
# memory.ld.in goes through the preprocessor
|
||||
# sections.ld.in goes through linker script generator
|
||||
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
|
||||
set(ld_input "${CMAKE_CURRENT_LIST_DIR}/${target}/memory.ld.in")
|
||||
set(ld_output "${CMAKE_CURRENT_BINARY_DIR}/ld/memory.ld")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_output}")
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld")
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/${target}/sections.ld.in"
|
||||
# Cmake script that generates linker script from "*.ld.in" scripts using compiler preprocessor
|
||||
set(linker_script_generator "${CMAKE_CURRENT_BINARY_DIR}/ld/linker_script_generator.cmake")
|
||||
file(WRITE ${linker_script_generator}
|
||||
[=[
|
||||
execute_process(COMMAND "${CC}" "-C" "-P" "-x" "c" "-E" "-I" "${CONFIG_DIR}" "-I" "${LD_DIR}" "${SOURCE}"
|
||||
RESULT_VARIABLE RET_CODE
|
||||
OUTPUT_VARIABLE PREPROCESSED_LINKER_SCRIPT
|
||||
ERROR_VARIABLE ERROR_VAR)
|
||||
if(RET_CODE AND NOT RET_CODE EQUAL 0)
|
||||
message(FATAL_ERROR "Can't generate ${TARGET}\nRET_CODE: ${RET_CODE}\nERROR_MESSAGE: ${ERROR_VAR}")
|
||||
endif()
|
||||
string(REPLACE "\\n" "\n" TEXT "${PREPROCESSED_LINKER_SCRIPT}")
|
||||
file(WRITE "${TARGET}" "${TEXT}")
|
||||
]=])
|
||||
|
||||
function(preprocess_linker_file name_in name_out out_path)
|
||||
set(script_in "${CMAKE_CURRENT_LIST_DIR}/${target}/${name_in}")
|
||||
set(script_out "${CMAKE_CURRENT_BINARY_DIR}/ld/${name_out}")
|
||||
set(${out_path} ${script_out} PARENT_SCOPE)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${script_out}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
"-DCC=${CMAKE_C_COMPILER}"
|
||||
"-DSOURCE=${script_in}"
|
||||
"-DTARGET=${script_out}"
|
||||
"-DCONFIG_DIR=${config_dir}"
|
||||
"-DLD_DIR=${CMAKE_CURRENT_LIST_DIR}"
|
||||
-P "${linker_script_generator}"
|
||||
MAIN_DEPENDENCY ${script_in}
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating ${script_out} linker script..."
|
||||
VERBATIM)
|
||||
add_custom_target("${name_out}" DEPENDS "${script_out}")
|
||||
add_dependencies(${COMPONENT_LIB} "${name_out}")
|
||||
endfunction()
|
||||
|
||||
# Generage memory.ld
|
||||
preprocess_linker_file("memory.ld.in" "memory.ld" ld_out_path)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_out_path}")
|
||||
|
||||
# Generage sections.ld.in and pass it through linker script generator
|
||||
preprocess_linker_file("sections.ld.in" "sections.ld.in" ld_out_path)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_out_path}"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/sections.ld")
|
||||
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
# Preprocess memory.ld.in linker script to include configuration, becomes memory.ld
|
||||
add_custom_command(
|
||||
OUTPUT ${ld_output}
|
||||
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o ${ld_output} -I ${config_dir}
|
||||
-I "${CMAKE_CURRENT_LIST_DIR}" ${ld_input}
|
||||
MAIN_DEPENDENCY ${ld_input}
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating memory.ld linker script..."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(memory_ld DEPENDS ${ld_output})
|
||||
add_dependencies(${COMPONENT_LIB} memory_ld)
|
||||
|
||||
Reference in New Issue
Block a user