From 47a673f2f43018967772de3aa0f42abca98816cd Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 27 Jun 2022 10:08:37 -0400 Subject: [PATCH] build: generate symbols file Optional way for generating symbols file using binutils. This file will be generated on demand for tests which will then be parsed by twister to create an accurate test plan from the listed testcase/suites. Signed-off-by: Anas Nashif --- CMakeLists.txt | 15 +++++++++++++++ Kconfig.zephyr | 5 +++++ cmake/bintools/bintools_template.cmake | 15 +++++++++++++++ cmake/bintools/gnu/target_bintools.cmake | 7 +++++++ cmake/bintools/llvm/target_bintools.cmake | 12 ++++++++++++ cmake/modules/kernel.cmake | 1 + 6 files changed, 55 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73254bbdfc2..ffb255bb840 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1642,6 +1642,21 @@ if(CONFIG_OUTPUT_DISASSEMBLE_ALL) ) endif() +if(CONFIG_OUTPUT_SYMBOLS) + list(APPEND + post_build_commands + COMMAND $ + $ + $${KERNEL_ELF_NAME} + $${KERNEL_SYMBOLS_NAME} + $ + ) + list(APPEND + post_build_byproducts + ${KERNEL_SYMBOLS_NAME} + ) +endif() + if(CONFIG_OUTPUT_STAT) # zephyr_post_build(TOOLS bintools COMMAND readelf FLAGS headers INFILE file OUTFILE outfile) list(APPEND diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 411f1dd153f..e0a8804589e 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -377,6 +377,11 @@ config OUTPUT_STAT help Create a stat file using readelf -e +config OUTPUT_SYMBOLS + bool "Create a symbol file" + help + Create a symbol file using nm + config OUTPUT_DISASSEMBLY bool "Create a disassembly file" default y diff --git a/cmake/bintools/bintools_template.cmake b/cmake/bintools/bintools_template.cmake index 9667075dffe..4b48ffe005a 100644 --- a/cmake/bintools/bintools_template.cmake +++ b/cmake/bintools/bintools_template.cmake @@ -11,6 +11,7 @@ # - elfconvert : Tool for converting from elf into another format. # - readelf : Tool for elf file processing # - strip : Tool for symbol stripping +# - symbols : Tool for listing symbols in a binary # # Each tool will have the following minimum properties: # - _command : Name of executable to call @@ -108,6 +109,13 @@ # strip_flag_dwo : Flag for removing dwarf sections # strip_flag_infile : Flag for specifying the input file # strip_flag_outfile : Flag for specifying the output file +# +# - symbols : Name of command for printing out symbols +# For GNU binary utilities this is nm +# symbols_command : empty +# symbols_final : empty +# symbols_infile : ELF file name +# symbols_outfile : output file set(COMMAND_NOT_SUPPORTED "command not supported on bintools: ") @@ -156,3 +164,10 @@ set_property(TARGET bintools PROPERTY strip_flag_debug "") set_property(TARGET bintools PROPERTY strip_flag_dwo "") set_property(TARGET bintools PROPERTY strip_flag_infile "") set_property(TARGET bintools PROPERTY strip_flag_outfile "") + +# list symbols in a binary +set_property(TARGET bintools PROPERTY symbols_command ${CMAKE_NM}) +set_property(TARGET bintools PROPERTY symbols_flag "") +set_property(TARGET bintools PROPERTY symbols_final "") +set_property(TARGET bintools PROPERTY symbols_infile "") +set_property(TARGET bintools PROPERTY symbols_outfile ">;" ) diff --git a/cmake/bintools/gnu/target_bintools.cmake b/cmake/bintools/gnu/target_bintools.cmake index a35f6ed6ac5..e8cb6e181d5 100644 --- a/cmake/bintools/gnu/target_bintools.cmake +++ b/cmake/bintools/gnu/target_bintools.cmake @@ -124,3 +124,10 @@ set_property(TARGET bintools PROPERTY readelf_flag_outfile ">;" ) #set_property(TARGET bintools PROPERTY readelf_flag_headers -E) #set_property(TARGET bintools PROPERTY readelf_flag_infile "") #set_property(TARGET bintools PROPERTY readelf_flag_outfile "-O file=" ) + + +set_property(TARGET bintools PROPERTY symbols_command ${CMAKE_NM}) +set_property(TARGET bintools PROPERTY symbols_flag "") +set_property(TARGET bintools PROPERTY symbols_final "") +set_property(TARGET bintools PROPERTY symbols_infile "") +set_property(TARGET bintools PROPERTY symbols_outfile ">;" ) diff --git a/cmake/bintools/llvm/target_bintools.cmake b/cmake/bintools/llvm/target_bintools.cmake index 7828e07ea84..3a3e04e4388 100644 --- a/cmake/bintools/llvm/target_bintools.cmake +++ b/cmake/bintools/llvm/target_bintools.cmake @@ -70,6 +70,18 @@ set_property(TARGET bintools PROPERTY disassembly_flag_all "") set_property(TARGET bintools PROPERTY disassembly_flag_infile "") set_property(TARGET bintools PROPERTY disassembly_flag_outfile ">;" ) +# +# - symbols : Name of command for printing out symbols +# symbols_command : empty +# symbols_final : empty +# symbols_infile : ELF file name +# symbols_outfile : output file +set_property(TARGET bintools PROPERTY symbols_command ${CMAKE_NM}) +set_property(TARGET bintools PROPERTY symbols_flag "") +set_property(TARGET bintools PROPERTY symbols_final "") +set_property(TARGET bintools PROPERTY symbols_infile "") +set_property(TARGET bintools PROPERTY symbols_outfile ">;" ) + # # - strip: Name of command for stripping symbols # In this implementation `strip` is used diff --git a/cmake/modules/kernel.cmake b/cmake/modules/kernel.cmake index 7b3bcba679b..461072cfe0b 100644 --- a/cmake/modules/kernel.cmake +++ b/cmake/modules/kernel.cmake @@ -162,6 +162,7 @@ set(KERNEL_EXE_NAME ${KERNEL_NAME}.exe) set(KERNEL_STAT_NAME ${KERNEL_NAME}.stat) set(KERNEL_STRIP_NAME ${KERNEL_NAME}.strip) set(KERNEL_META_NAME ${KERNEL_NAME}.meta) +set(KERNEL_SYMBOLS_NAME ${KERNEL_NAME}.symbols) include(${BOARD_DIR}/board.cmake OPTIONAL)