cmake: toolchain: bintools abstraction

GNU/bintools abstraction completed.
The following commands and flags are now available in bintools:
- memusage
- elfconvert
- dissassembly
- readelf
- strip

The bintools template has now been updated with more description which
will be useful when adding support for more toolchains in future.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-08-18 14:46:06 +02:00 committed by Carles Cufí
parent c55c64e242
commit c060b075a6
9 changed files with 150 additions and 405 deletions

View file

@ -717,18 +717,15 @@ if(CONFIG_GEN_ISR_TABLES)
# isr_tables.c is generated from ${ZEPHYR_PREBUILT_EXECUTABLE} by
# gen_isr_tables.py
set(obj_copy_cmd "")
bintools_objcopy(
RESULT_CMD_LIST obj_copy_cmd
TARGET_INPUT ${OUTPUT_FORMAT}
TARGET_OUTPUT "binary"
SECTION_ONLY ".intList"
FILE_INPUT $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
FILE_OUTPUT "isrList.bin"
)
add_custom_command(
OUTPUT isr_tables.c
${obj_copy_cmd}
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
$<TARGET_PROPERTY:bintools,elfconvert_flag>
$<TARGET_PROPERTY:bintools,elfconvert_flag_intarget>${OUTPUT_FORMAT}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>binary
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_only>.intList
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>$<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>isrList.bin
COMMAND ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/arch/common/gen_isr_tables.py
--output-source isr_tables.c
@ -738,6 +735,7 @@ if(CONFIG_GEN_ISR_TABLES)
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug>
${GEN_ISR_TABLE_EXTRA_ARG}
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
COMMAND_EXPAND_LISTS
)
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c)
endif()
@ -857,23 +855,18 @@ if(CONFIG_USERSPACE)
set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ})
set(obj_copy_cmd "")
set(obj_copy_sections_rename
.data=.kobject_data.data
.text=.kobject_data.text
.rodata=.kobject_data.rodata
)
bintools_objcopy(
RESULT_CMD_LIST obj_copy_cmd
SECTION_RENAME ${obj_copy_sections_rename}
FILE_INPUT ${OUTPUT_OBJ_PATH}
FILE_OUTPUT ${OUTPUT_OBJ_RENAMED}
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}
${obj_copy_cmd}
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
$<TARGET_PROPERTY:bintools,elfconvert_flag>
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.data=.kobject_data.data
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.text=.kobject_data.text
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.rodata=.kobject_data.rodata
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${OUTPUT_OBJ_PATH}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${OUTPUT_OBJ_RENAMED}
DEPENDS output_lib
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND_EXPAND_LISTS
)
add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED})
@ -1187,8 +1180,8 @@ if(CONFIG_OUTPUT_DISASSEMBLE_ALL)
COMMAND $<TARGET_PROPERTY:bintools,disassembly_command>
$<TARGET_PROPERTY:bintools,disassembly_flag>
${disassembly_type}
$<TARGET_PROPERTY:bintools,disassembly_flag_infile> ${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,disassembly_flag_outfile> ${KERNEL_LST_NAME}
$<TARGET_PROPERTY:bintools,disassembly_flag_infile>${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,disassembly_flag_outfile>${KERNEL_LST_NAME}
)
list(APPEND
post_build_byproducts
@ -1198,44 +1191,33 @@ if(CONFIG_OUTPUT_DISASSEMBLE_ALL)
endif()
if(CONFIG_OUTPUT_STAT)
set(out_stat_cmd "")
set(out_stat_byprod "")
bintools_readelf(
RESULT_CMD_LIST out_stat_cmd
RESULT_BYPROD_LIST out_stat_byprod
HEADERS
FILE_INPUT ${KERNEL_ELF_NAME}
FILE_OUTPUT ${KERNEL_STAT_NAME}
)
# zephyr_post_build(TOOLS bintools COMMAND readelf FLAGS headers INFILE file OUTFILE outfile)
list(APPEND
post_build_commands
${out_stat_cmd}
COMMAND $<TARGET_PROPERTY:bintools,readelf_command>
$<TARGET_PROPERTY:bintools,readelf_flag>
$<TARGET_PROPERTY:bintools,readelf_flag_headers>
$<TARGET_PROPERTY:bintools,readelf_flag_infile> ${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,readelf_flag_outfile> ${KERNEL_STAT_NAME}
)
list(APPEND
post_build_byproducts
${KERNEL_STAT_NAME}
${out_stat_byprod}
)
endif()
if(CONFIG_BUILD_OUTPUT_STRIPPED)
set(out_stripped_cmd "")
set(out_stripped_byprod "")
bintools_strip(
RESULT_CMD_LIST out_stripped_cmd
RESULT_BYPROD_LIST out_stripped_byprod
STRIP_ALL
FILE_INPUT ${KERNEL_ELF_NAME}
FILE_OUTPUT ${KERNEL_STRIP_NAME}
)
list(APPEND
post_build_commands
${out_stripped_cmd}
COMMAND $<TARGET_PROPERTY:bintools,strip_command>
$<TARGET_PROPERTY:bintools,strip_flag>
$<TARGET_PROPERTY:bintools,strip_flag_all>
$<TARGET_PROPERTY:bintools,strip_flag_infile>${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,strip_flag_outfile>${KERNEL_STRIP_NAME}
)
list(APPEND
post_build_byproducts
${KERNEL_STRIP_NAME}
${out_stripped_byprod}
)
endif()

View file

@ -9,13 +9,10 @@ find_program(CMAKE_AR ${CROSS_COMPILE}ar PATHS ${TOOLCHAIN_HOME} NO_DE
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_STRIP ${CROSS_COMPILE}strip PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB ${CROSS_COMPILE}gdb PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB gdb-multiarch PATHS ${TOOLCHAIN_HOME} )
# Include bin tool abstraction macros
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_memusage.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objcopy.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objdump.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_readelf.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_strip.cmake)
# Include bin tool properties
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_bintools.cmake)

View file

@ -0,0 +1,116 @@
# SPDX-License-Identifier: Apache-2.0
#
# - elfconvert : Name of command for elf file conversion.
# In this implementation `objcopy` is used
# elfconvert_formats : Formats supported: ihex, srec, binary
# elfconvert_flag : empty
# elfconvert_flag_strip_all : -S
# elfconvert_flag_strip_debug : -g
# elfconvert_flag_intarget : --input-target=
# elfconvert_flag_outtarget : --output-target=
# elfconvert_flag_section_remove: --remove-section=
# elfconvert_flag_section_only : --only-section=
# elfconvert_flag_section_rename: --rename-section;
# elfconvert_flag_gapfill : --gap-fill;
# Note: The ';' will be transformed into an
# empty space when executed
# elfconvert_flag_srec_len : --srec-len=
# elfconvert_flag_infile : empty, objcopy doesn't take arguments for filenames
# elfconvert_flag_outfile : empty, objcopy doesn't take arguments for filenames
#
# elfconvert to use for transforming an elf file into another format,
# such as intel hex, s-rec, binary, etc.
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_OBJCOPY})
# List of format the tool supports for converting, for example,
# GNU tools uses objectcopyy, which supports the following: ihex, srec, binary
set_property(TARGET bintools PROPERTY elfconvert_formats ihex srec binary)
set_property(TARGET bintools PROPERTY elfconvert_flag "")
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-S")
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-g")
set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "--input-target=")
set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "--output-target=")
set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "--remove-section=")
set_property(TARGET bintools PROPERTY elfconvert_flag_section_only "--only-section=")
set_property(TARGET bintools PROPERTY elfconvert_flag_section_rename "--rename-section;")
# Note, placing a ';' at the end results in the following param to be a list,
# and hence space separated.
# Thus the command line argument becomes:
# `--gap-file <value>` instead of `--gap-fill<value>` (The latter would result in an error)
set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "--gap-fill;")
set_property(TARGET bintools PROPERTY elfconvert_flag_srec_len "--srec-len=")
set_property(TARGET bintools PROPERTY elfconvert_flag_infile "")
set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "")
#
# - disassembly : Name of command for disassembly of files
# In this implementation `objdump` is used
# disassembly_flag : -d
# disassembly_flag_inline_source : -S
# disassembly_flag_all : -SDz
# disassembly_flag_infile : empty, objdump doesn't take arguments for filenames
# disassembly_flag_outfile : '>', objdump doesn't take arguments for output file, but result is printed to standard out, and is redirected.
set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_OBJDUMP})
set_property(TARGET bintools PROPERTY disassembly_flag -d)
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source -S)
set_property(TARGET bintools PROPERTY disassembly_flag_all -SDz)
set_property(TARGET bintools PROPERTY disassembly_flag_infile "")
set_property(TARGET bintools PROPERTY disassembly_flag_outfile > )
#
# - strip: Name of command for stripping symbols
# In this implementation `strip` is used
# strip_flag : empty
# strip_flag_all : --strip-all
# strip_flag_debug : --strip-debug
# strip_flag_dwo : --strip-dwo
# strip_flag_infile : empty, strip doesn't take arguments for input file
# strip_flag_outfile : -o
# This is using strip from bintools.
set_property(TARGET bintools PROPERTY strip_command ${CMAKE_STRIP})
# Any flag the strip command requires for processing
set_property(TARGET bintools PROPERTY strip_flag "")
set_property(TARGET bintools PROPERTY strip_flag_all --strip-all)
set_property(TARGET bintools PROPERTY strip_flag_debug --strip-debug)
set_property(TARGET bintools PROPERTY strip_flag_dwo --strip-dwo)
set_property(TARGET bintools PROPERTY strip_flag_infile "")
set_property(TARGET bintools PROPERTY strip_flag_outfile -o )
#
# - readelf : Name of command for reading elf files.
# In this implementation `readelf` is used
# readelf_flag : empty
# readelf_flag_headers : -e
# readelf_flag_infile : empty, readelf doesn't take arguments for filenames
# readelf_flag_outfile : '>', readelf doesn't take arguments for output
# file, but result is printed to standard out, and
# is redirected.
# This is using readelf from bintools.
set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_READELF})
set_property(TARGET bintools PROPERTY readelf_flag "")
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 > )
# Example on how to support dwarfdump instead of readelf
#set_property(TARGET bintools PROPERTY readelf_command dwarfdump)
#set_property(TARGET bintools PROPERTY readelf_flag "")
#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=" )

View file

@ -1,32 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Add and/or prepare print of memory usage report
#
# Usage:
# bintools_print_mem_usage(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
# )
#
macro(bintools_print_mem_usage)
# Here we make use of the linkers ability to produce memory usage output
# and thus we have no need for the above provided arguments, but another
# toolchain with a different set of binary tools, most likely will...
#
# Use --print-memory-usage with the first link.
#
# Don't use this option with the second link because seeing it twice
# could confuse users and using it on the second link would suppress
# it when the first link has a ram/flash-usage issue.
set(option ${LINKERFLAGPREFIX},--print-memory-usage)
string(MAKE_C_IDENTIFIER check${option} check)
set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${option}")
zephyr_check_compiler_flag(C "" ${check})
set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
target_link_libraries_ifdef(${check} ${ZEPHYR_PREBUILT_EXECUTABLE} ${option})
endmacro(bintools_print_mem_usage)

View file

@ -1,126 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Construct a commandline suitable for calling the toolchain binary tools
# version of objcopy.
#
# Usage:
# bintools_objcopy(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# STRIP_ALL <When present, remove relocation and symbol info>
# STRIP_DEBUG <When present, remove debugging symbols and sections>
#
# TARGET_INPUT <Input file format type>
# TARGET_OUTPUT <Output file format type>
#
# GAP_FILL <Value used for gap fill, empty or not set, no gap fill>
# SREC_LEN <For srec format only, max length of the records>
#
# SECTION_ONLY <One or more section names to be included>
# SECTION_REMOVE <One or more section names to be excluded>
# SECTION_RENAME <One or more section names to be renamed 'from=to'>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_objcopy)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_OBJCOPY
# List of argument names without values, hence boolean
"STRIP_ALL;STRIP_DEBUG"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;TARGET_INPUT;TARGET_OUTPUT;GAP_FILL;SREC_LEN;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
"SECTION_ONLY;SECTION_RENAME;SECTION_REMOVE"
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_OBJCOPY_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_OBJCOPY_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_OBJCOPY_FILE_INPUT OR NOT DEFINED BINTOOLS_OBJCOPY_FILE_OUTPUT)
message(FATAL_ERROR "Both FILE_INPUT and FILE_OUTPUT is required.")
endif()
# Handle stripping
set(obj_copy_strip "")
if(${BINTOOLS_OBJCOPY_STRIP_ALL})
set(obj_copy_strip "-S")
elseif(${BINTOOLS_OBJCOPY_STRIP_DEBUG})
set(obj_copy_strip "-g")
endif()
# Handle gap filling
set(obj_copy_gap_fill "")
if(DEFINED BINTOOLS_OBJCOPY_GAP_FILL)
set(obj_copy_gap_fill "--gap-fill;${BINTOOLS_OBJCOPY_GAP_FILL}")
endif()
# Handle srec len, but only if target output is srec
set(obj_copy_srec_len "")
if(DEFINED BINTOOLS_OBJCOPY_SREC_LEN)
if(NOT ${BINTOOLS_OBJCOPY_TARGET_OUTPUT} STREQUAL "srec")
message(WARNING "Ignoring srec len, for non srec target: ${BINTOOLS_OBJCOPY_TARGET_OUTPUT}")
else()
set(obj_copy_srec_len "--srec-len;${BINTOOLS_OBJCOPY_SREC_LEN}")
endif()
endif()
# Handle Input and Output target types
set(obj_copy_target_input "")
if(DEFINED BINTOOLS_OBJCOPY_TARGET_INPUT)
set(obj_copy_target_input "--input-target=${BINTOOLS_OBJCOPY_TARGET_INPUT}")
endif()
set(obj_copy_target_output "")
if(DEFINED BINTOOLS_OBJCOPY_TARGET_OUTPUT)
set(obj_copy_target_output "--output-target=${BINTOOLS_OBJCOPY_TARGET_OUTPUT}")
endif()
# Handle sections, if any
# 1. Section only selection(s)
set(obj_copy_sections_only "")
if(DEFINED BINTOOLS_OBJCOPY_SECTION_ONLY)
foreach(section_only ${BINTOOLS_OBJCOPY_SECTION_ONLY})
list(APPEND obj_copy_sections_only "--only-section=${section_only}")
endforeach()
endif()
# 2. Section rename selection(s)
set(obj_copy_sections_rename "")
if(DEFINED BINTOOLS_OBJCOPY_SECTION_RENAME)
foreach(section_rename ${BINTOOLS_OBJCOPY_SECTION_RENAME})
if(NOT ${section_rename} MATCHES "^.*=.*$")
message(FATAL_ERROR "Malformed section renaming. Must be from=to, have ${section_rename}")
else()
list(APPEND obj_copy_sections_rename "--rename-section;${section_rename}")
endif()
endforeach()
endif()
# 3. Section remove selection(s)
set(obj_copy_sections_remove "")
if(DEFINED BINTOOLS_OBJCOPY_SECTION_REMOVE)
foreach(section_remove ${BINTOOLS_OBJCOPY_SECTION_REMOVE})
list(APPEND obj_copy_sections_remove "--remove-section=${section_remove}")
endforeach()
endif()
# Construct the command
set(obj_copy_cmd
# Base command
COMMAND ${CMAKE_OBJCOPY} ${obj_copy_strip} ${obj_copy_gap_fill} ${obj_copy_srec_len}
# Input and Output target types
${obj_copy_target_input} ${obj_copy_target_output}
# Sections
${obj_copy_sections_only} ${obj_copy_sections_rename} ${obj_copy_sections_remove}
# Input and output files
${BINTOOLS_OBJCOPY_FILE_INPUT} ${BINTOOLS_OBJCOPY_FILE_OUTPUT}
)
# Place command in the parent provided variable
set(${BINTOOLS_OBJCOPY_RESULT_CMD_LIST} ${obj_copy_cmd} PARENT_SCOPE)
endfunction(bintools_objcopy)

View file

@ -1,66 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Construct a commandline suitable for calling the toolchain binary tools
# version of objdump.
#
# Usage:
# bintools_objdump(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# DISASSEMBLE <Display the assembler mnemonics for the machine instructions from input>
# DISASSEMBLE_SOURCE < Display source code intermixed with disassembly, if possible>
# DISASSEMBLE_ALL <Display disassembly of all sections not just the instruction sections>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_objdump)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_OBJDUMP
# List of argument names without values, hence boolean
"DISASSEMBLE;DISASSEMBLE_SOURCE;DISASSEMBLE_ALL"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
""
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_OBJDUMP_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_OBJDUMP_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_OBJDUMP_FILE_INPUT)
message(FATAL_ERROR "FILE_INPUT is required.")
endif()
# Handle disassembly
set(obj_dump_disassemble "")
if(${BINTOOLS_OBJDUMP_DISASSEMBLE_SOURCE})
set(obj_dump_disassemble "-S") # --source
elseif(${BINTOOLS_OBJDUMP_DISASSEMBLE})
set(obj_dump_disassemble "-d") # --disassemble
elseif(${BINTOOLS_OBJDUMP_DISASSEMBLE_ALL})
set(obj_dump_disassemble "-SDz") # --source --disassemble-all --disassemble-zeroes
endif()
# Handle output
set(obj_dump_output "")
if(DEFINED BINTOOLS_OBJDUMP_FILE_OUTPUT)
set(obj_dump_output > ${BINTOOLS_OBJDUMP_FILE_OUTPUT})
endif()
# Construct the command
set(obj_dump_cmd
# Base command
COMMAND ${CMAKE_OBJDUMP} ${obj_dump_disassemble}
# Input and Output
${BINTOOLS_OBJDUMP_FILE_INPUT} ${obj_dump_output}
)
# Place command in the parent provided variable
set(${BINTOOLS_OBJDUMP_RESULT_CMD_LIST} ${obj_dump_cmd} PARENT_SCOPE)
endfunction(bintools_objdump)

View file

@ -1,60 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Construct a commandline suitable for calling the toolchain binary tools
# version of readelf.
#
# Usage:
# bintools_readelf(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# HEADERS <Display all the headers in the input file>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_readelf)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_READELF
# List of argument names without values, hence boolean
"HEADERS"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
""
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_READELF_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_READELF_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_READELF_FILE_INPUT)
message(FATAL_ERROR "FILE_INPUT is required.")
endif()
# Handle headers
set(readelf_headers "")
if(${BINTOOLS_READELF_HEADERS})
set(readelf_headers "-e") # --headers
endif()
# Handle output
set(readelf_output "")
if(DEFINED BINTOOLS_READELF_FILE_OUTPUT)
set(readelf_output > ${BINTOOLS_READELF_FILE_OUTPUT})
endif()
# Construct the command
set(readelf_cmd
# Base command
COMMAND ${CMAKE_READELF} ${readelf_headers}
# Input and Output
${BINTOOLS_READELF_FILE_INPUT} ${readelf_output}
)
# Place command in the parent provided variable
set(${BINTOOLS_READELF_RESULT_CMD_LIST} ${readelf_cmd} PARENT_SCOPE)
endfunction(bintools_readelf)

View file

@ -1,62 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Construct a commandline suitable for calling the toolchain binary tools
# version of strip.
#
# Usage:
# bintools_strip(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# STRIP_ALL <When present, remove relocation and symbol info>
# STRIP_DEBUG <When present, remove debugging symbols and sections>
# STRIP_DWO <When present, remove DWARF .dwo sections>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_strip)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_STRIP
# List of argument names without values, hence boolean
"STRIP_ALL;STRIP_DEBUG;STRIP_DWO"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
""
# Parser input
${ARGN}
)
if(NOT DEFINED BINTOOLS_STRIP_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_STRIP_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_STRIP_FILE_INPUT OR NOT DEFINED BINTOOLS_STRIP_FILE_OUTPUT)
message(FATAL_ERROR "Both FILE_INPUT and FILE_OUTPUT are required.")
endif()
# Handle stripping
set(strip_what "")
if(${BINTOOLS_STRIP_STRIP_ALL})
set(strip_what "--strip-all")
elseif(${BINTOOLS_STRIP_STRIP_DEBUG})
set(strip_what "--strip-debug")
elseif(${BINTOOLS_STRIP_STRIP_DWO})
set(strip_what "--strip-dwo")
endif()
# Handle output
set(strip_output -o ${BINTOOLS_STRIP_FILE_OUTPUT})
# Construct the command
set(strip_cmd
# Base command
COMMAND ${CMAKE_STRIP} ${strip_what}
# Input and Output
${BINTOOLS_STRIP_FILE_INPUT} ${strip_output}
)
# Place command in the parent provided variable
set(${BINTOOLS_STRIP_RESULT_CMD_LIST} ${strip_cmd} PARENT_SCOPE)
endfunction(bintools_strip)

View file

@ -10,9 +10,5 @@ find_program(CMAKE_READELF readelf)
find_program(CMAKE_GDB gdb )
# Use the gnu binutil abstraction macros
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_memusage.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objcopy.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objdump.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_readelf.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_strip.cmake)
# Include bin tool properties
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_bintools.cmake)