cmake: Toolchain abstraction: Abstraction of binary tool, objdump.

This abstracts the interface for generation of the objdump command
line, by naming the desired actions instead of directly setting the
command parameters, which then opens up for other binary tool sets
which may require different arguments to achieve the desired result.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
This commit is contained in:
Danny Oerndrup 2019-08-01 08:01:39 +02:00 committed by Alberto Escolar
commit 0760a53d2c
5 changed files with 77 additions and 2 deletions

View file

@ -1335,14 +1335,23 @@ if(CONFIG_BUILD_OUTPUT_S19)
endif() endif()
if(CONFIG_OUTPUT_DISASSEMBLY) if(CONFIG_OUTPUT_DISASSEMBLY)
set(out_disassembly_cmd "")
set(out_disassembly_byprod "")
bintools_objdump(
RESULT_CMD_LIST out_disassembly_cmd
RESULT_BYPROD_LIST out_disassembly_byprod
DISASSEMBLE_SOURCE
FILE_INPUT ${KERNEL_ELF_NAME}
FILE_OUTPUT ${KERNEL_LST_NAME}
)
list(APPEND list(APPEND
post_build_commands post_build_commands
COMMAND ${out_disassembly_cmd}
${CMAKE_OBJDUMP} -S ${KERNEL_ELF_NAME} > ${KERNEL_LST_NAME}
) )
list(APPEND list(APPEND
post_build_byproducts post_build_byproducts
${KERNEL_LST_NAME} ${KERNEL_LST_NAME}
${out_disassembly_byprod}
) )
endif() endif()

View file

@ -16,3 +16,4 @@ find_program(CMAKE_GDB gdb-multiarch PATH ${TOOLCHAIN_HOME}
# Include bin tool abstraction macros # Include bin tool abstraction macros
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_memusage.cmake) 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_objcopy.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objdump.cmake)

View file

@ -0,0 +1,63 @@
# 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>
#
# 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"
# 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
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

@ -13,3 +13,4 @@ find_program(CMAKE_GDB gdb )
# Use the gnu binutil abstraction macros # Use the gnu binutil abstraction macros
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_memusage.cmake) 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_objcopy.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objdump.cmake)

View file

@ -17,3 +17,4 @@ find_program(CMAKE_READELF readelf ${find_program_binutils_args})
# Use the gnu binutil abstraction macros # Use the gnu binutil abstraction macros
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_memusage.cmake) 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_objcopy.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objdump.cmake)