Skip to content

Commit

Permalink
cmake: Add objcopy --redefine-syms step to add_ia2_compartment
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrtonm committed Dec 20, 2023
1 parent beecd77 commit 0d07c0f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cmake/ia2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} $<JOIN:$<TARGET_OBJECTS:${target}>, \\\; && ${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})
Expand Down Expand Up @@ -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}
Expand All @@ -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)
Expand Down

0 comments on commit 0d07c0f

Please sign in to comment.