From 0d07c0f02b22f04117d066f0d26c62a0ae53de20 Mon Sep 17 00:00:00 2001 From: Ayrton Munoz Date: Tue, 19 Dec 2023 19:08:05 -0500 Subject: [PATCH] cmake: Add objcopy --redefine-syms step to add_ia2_compartment --- cmake/ia2.cmake | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmake/ia2.cmake b/cmake/ia2.cmake index e4d5b5b8f..9bc3f8e0a 100644 --- a/cmake/ia2.cmake +++ b/cmake/ia2.cmake @@ -214,6 +214,16 @@ function(add_ia2_call_gates NAME) target_link_options(${target} PRIVATE "-Wl,@${target_ld_args_file}") list(APPEND LD_ARGS_FILES "${target_ld_args_file}") + set(target_objcopy_args_file "${REWRITER_OUTPUT_PREFIX}_${target_pkey}.objcopy") + set(OBJCOPY_GLUE ${CMAKE_OBJCOPY} "--redefine-syms=${target_objcopy_args_file}") + set(OBJCOPY_CMD ${OBJCOPY_GLUE} $, \\\; && ${OBJCOPY_GLUE} >) + add_custom_command(TARGET ${target} PRE_LINK + COMMAND "${OBJCOPY_CMD}" + DEPENDS ${target_objcopy_args_file} + VERBATIM + COMMAND_EXPAND_LISTS) + list(APPEND OBJCOPY_ARGS_FILES "${target_objcopy_args_file}") + get_target_property(target_srcs ${target} ORIGINAL_SOURCES) relative_to_absolute(target_original_srcs ${target_source_dir} ${target_srcs}) list(APPEND SOURCES ${target_original_srcs}) @@ -243,7 +253,8 @@ function(add_ia2_call_gates NAME) endforeach() add_custom_command( - OUTPUT ${CALL_GATE_SRC} ${CALL_GATE_HDR} ${LD_ARGS_FILES} ${REWRITTEN_SOURCES} + OUTPUT ${CALL_GATE_SRC} ${CALL_GATE_HDR} + ${LD_ARGS_FILES} ${OBJCOPY_ARGS_FILES} ${REWRITTEN_SOURCES} COMMAND ia2-rewriter --output-prefix=${REWRITER_OUTPUT_PREFIX} --root-directory=${CMAKE_CURRENT_SOURCE_DIR} @@ -260,7 +271,8 @@ function(add_ia2_call_gates NAME) ) add_custom_target(${NAME}-rewrite - DEPENDS ${CALL_GATE_SRC} ${CALL_GATE_HDR} ${LD_ARGS_FILES} ${REWRITTEN_SOURCES}) + DEPENDS ${CALL_GATE_SRC} ${CALL_GATE_HDR} + ${LD_ARGS_FILES} ${OBJCOPY_ARGS_FILES} ${REWRITTEN_SOURCES}) add_library(${CALL_GATE_TARGET} SHARED ${CALL_GATE_SRC}) add_dependencies(${CALL_GATE_TARGET} ${NAME}-rewrite)