Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 468f0aa

Browse files
committed
Add partial linking + objcopy
There seems to be no easier way to hide symbols in archives.
1 parent 228696a commit 468f0aa

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

CMakeLists.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,24 @@ endif()
9595
set_property(TARGET syscall_intercept_base_c
9696
APPEND PROPERTY COMPILE_FLAGS ${capstone_CFLAGS})
9797

98-
99-
add_library(syscall_intercept_shared SHARED
100-
$<TARGET_OBJECTS:syscall_intercept_base_c>
101-
$<TARGET_OBJECTS:syscall_intercept_base_asm>
102-
$<TARGET_OBJECTS:syscall_intercept_base_clf>)
103-
add_library(syscall_intercept_static STATIC
98+
add_library(syscall_intercept_unscoped STATIC
10499
$<TARGET_OBJECTS:syscall_intercept_base_c>
105100
$<TARGET_OBJECTS:syscall_intercept_base_asm>
106101
$<TARGET_OBJECTS:syscall_intercept_base_clf>)
107102

103+
set(syscall_intercept_unscoped_a $<TARGET_FILE:syscall_intercept_unscoped>)
104+
105+
add_custom_command(
106+
OUTPUT syscall_intercept_scoped.o
107+
COMMAND ${CMAKE_LINKER}
108+
-r --whole-archive ${syscall_intercept_unscoped_a}
109+
-o syscall_intercept_scoped.o
110+
COMMAND ${CMAKE_OBJCOPY} --localize-hidden syscall_intercept_scoped.o
111+
COMMENT "Hiding symbols")
112+
113+
add_library(syscall_intercept_shared SHARED syscall_intercept_scoped.o)
114+
add_library(syscall_intercept_static STATIC syscall_intercept_scoped.o)
115+
108116
set_target_properties(syscall_intercept_base_c
109117
PROPERTIES C_VISIBILITY_PRESET hidden)
110118

@@ -122,6 +130,7 @@ add_executable(cpp_test src/cpp_compile_test.cc src/cpp_compile_mock.c)
122130

123131
set_target_properties(syscall_intercept_shared syscall_intercept_static
124132
PROPERTIES
133+
LINKER_LANGUAGE C
125134
PUBLIC_HEADER "include/libsyscall_intercept_hook_point.h"
126135
OUTPUT_NAME syscall_intercept)
127136

0 commit comments

Comments
 (0)