llext: build with debug info, strip at packaging time
This patch changes the way extensions are built to allow for debugging information to be collected. Debug flags are now used when compiling and linking the extension source code, generating a debuggable ELF file. The final .llext file is then stripped of unneeded symbols, including all debugging information, at packaging time. The debugging flag is still removed from the EDK-exported flags. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
parent
dda8d776ab
commit
5b66af8adb
@ -15,7 +15,6 @@ set(LLEXT_REMOVE_FLAGS
|
||||
-fno-pie
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-g.*
|
||||
-Os
|
||||
)
|
||||
|
||||
|
||||
@ -54,7 +54,6 @@ set(LLEXT_REMOVE_FLAGS
|
||||
-fno-pie
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-g.*
|
||||
-Os
|
||||
)
|
||||
|
||||
@ -67,8 +66,9 @@ set(LLEXT_APPEND_FLAGS
|
||||
list(APPEND LLEXT_EDK_REMOVE_FLAGS
|
||||
--sysroot=.*
|
||||
-fmacro-prefix-map=.*
|
||||
)
|
||||
-g.*
|
||||
)
|
||||
|
||||
list(APPEND LLEXT_EDK_APPEND_FLAGS
|
||||
-nodefaultlibs
|
||||
)
|
||||
)
|
||||
|
||||
@ -22,13 +22,13 @@ set(LLEXT_REMOVE_FLAGS
|
||||
-fno-pie
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-g.*
|
||||
-Os
|
||||
)
|
||||
|
||||
list(APPEND LLEXT_EDK_REMOVE_FLAGS
|
||||
--sysroot=.*
|
||||
-fmacro-prefix-map=.*
|
||||
-g.*
|
||||
)
|
||||
|
||||
list(APPEND LLEXT_EDK_APPEND_FLAGS
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
set(LLEXT_REMOVE_FLAGS
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-g.*
|
||||
-Os
|
||||
-mcpu=.*
|
||||
)
|
||||
|
||||
@ -7,7 +7,6 @@ include(${ZEPHYR_BASE}/cmake/compiler/xcc/target.cmake)
|
||||
set(LLEXT_REMOVE_FLAGS
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-g.*
|
||||
-Os
|
||||
-mcpu=.*
|
||||
)
|
||||
|
||||
@ -5700,7 +5700,7 @@ function(add_llext_target target_name)
|
||||
# to be used to support POST_BUILD commands on targets that do not use a
|
||||
# dynamic library.
|
||||
set(llext_proc_target ${target_name}_llext_proc)
|
||||
set(llext_pkg_input ${PROJECT_BINARY_DIR}/${target_name}.llext.pkg_input)
|
||||
set(llext_pkg_input ${PROJECT_BINARY_DIR}/${target_name}_debug.elf)
|
||||
add_custom_target(${llext_proc_target} DEPENDS ${llext_pkg_input})
|
||||
set_property(TARGET ${llext_proc_target} PROPERTY has_post_build_cmds 0)
|
||||
|
||||
@ -5733,49 +5733,19 @@ function(add_llext_target target_name)
|
||||
set(slid_inject_cmd ${CMAKE_COMMAND} -E true)
|
||||
endif()
|
||||
|
||||
# Type-specific packaging of the built binary file into an .llext file
|
||||
if(CONFIG_LLEXT_TYPE_ELF_OBJECT)
|
||||
|
||||
# No packaging required, simply copy the object file
|
||||
add_custom_command(
|
||||
OUTPUT ${llext_pkg_output}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${llext_pkg_input} ${llext_pkg_output}
|
||||
COMMAND ${slid_inject_cmd}
|
||||
DEPENDS ${llext_proc_target} ${llext_pkg_input}
|
||||
)
|
||||
|
||||
elseif(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE)
|
||||
|
||||
# Need to remove just some sections from the relocatable object
|
||||
# (using strip in this case would remove _all_ symbols)
|
||||
add_custom_command(
|
||||
OUTPUT ${llext_pkg_output}
|
||||
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag>
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>.xt.*
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${llext_pkg_input}
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${llext_pkg_output}
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
||||
COMMAND ${slid_inject_cmd}
|
||||
DEPENDS ${llext_proc_target} ${llext_pkg_input}
|
||||
)
|
||||
|
||||
elseif(CONFIG_LLEXT_TYPE_ELF_SHAREDLIB)
|
||||
|
||||
# Need to strip the shared library of some sections
|
||||
add_custom_command(
|
||||
OUTPUT ${llext_pkg_output}
|
||||
COMMAND $<TARGET_PROPERTY:bintools,strip_command>
|
||||
$<TARGET_PROPERTY:bintools,strip_flag>
|
||||
$<TARGET_PROPERTY:bintools,strip_flag_remove_section>.xt.*
|
||||
$<TARGET_PROPERTY:bintools,strip_flag_infile>${llext_pkg_input}
|
||||
$<TARGET_PROPERTY:bintools,strip_flag_outfile>${llext_pkg_output}
|
||||
$<TARGET_PROPERTY:bintools,strip_flag_final>
|
||||
COMMAND ${slid_inject_cmd}
|
||||
DEPENDS ${llext_proc_target} ${llext_pkg_input}
|
||||
)
|
||||
|
||||
endif()
|
||||
# Remove sections that are unused by the llext loader
|
||||
add_custom_command(
|
||||
OUTPUT ${llext_pkg_output}
|
||||
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag>
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_strip_unneeded>
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>.xt.*
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${llext_pkg_input}
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${llext_pkg_output}
|
||||
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
|
||||
COMMAND ${slid_inject_cmd}
|
||||
DEPENDS ${llext_proc_target} ${llext_pkg_input}
|
||||
)
|
||||
|
||||
# Add user-visible target and dependency, and fill in properties
|
||||
get_filename_component(output_name ${llext_pkg_output} NAME)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user