2929# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3030# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
32- cmake_minimum_required (VERSION 2.8.7 )
32+ cmake_minimum_required (VERSION 3.3 )
3333project (syscall_intercept C CXX ASM)
3434
3535set (CMAKE_DISABLE_IN_SOURCE_BUILD ON )
@@ -60,7 +60,7 @@ include(GNUInstallDirs)
6060include (cmake/toolchain_features.cmake)
6161include (cmake/find_capstone.cmake)
6262
63- # main source files - intentionally excluding src/entry .c
63+ # main source files - intentionally excluding src/cmdline_filter .c
6464set (SOURCES_C
6565 src/disasm_wrapper.c
6666 src/intercept.c
@@ -83,8 +83,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
8383# can use the internal interface of the libraries (linking
8484# with syscall_intercept_base instead of the actual lib ), without
8585# the library trying to hotpatch libc every time.
86- add_library (syscall_intercept_base_c STATIC ${SOURCES_C} )
87- add_library (syscall_intercept_base_asm STATIC ${SOURCES_ASM} )
86+ add_library (syscall_intercept_base_c OBJECT ${SOURCES_C} )
87+ add_library (syscall_intercept_base_asm OBJECT ${SOURCES_ASM} )
88+ add_library (syscall_intercept_base_clf OBJECT src/cmdline_filter.c)
8889
8990if (HAS_NOUNUSEDARG)
9091 target_compile_options (syscall_intercept_base_asm BEFORE
@@ -94,36 +95,42 @@ endif()
9495set_property (TARGET syscall_intercept_base_c
9596 APPEND PROPERTY COMPILE_FLAGS ${capstone_CFLAGS} )
9697
97- target_link_libraries (syscall_intercept_base_c
98- ${CMAKE_DL_LIBS} ${capstone_LIBRARIES} )
98+ add_library (syscall_intercept_unscoped STATIC
99+ $<TARGET_OBJECTS:syscall_intercept_base_c>
100+ $<TARGET_OBJECTS:syscall_intercept_base_asm>
101+ $<TARGET_OBJECTS:syscall_intercept_base_clf>)
102+
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+
116+ set_target_properties (syscall_intercept_base_c
117+ PROPERTIES C_VISIBILITY_PRESET hidden)
99118
100- add_library (syscall_intercept_shared SHARED src/entry.c)
101119target_link_libraries (syscall_intercept_shared
102- syscall_intercept_base_c syscall_intercept_base_asm )
103- add_library (syscall_intercept_static STATIC src/entry.c)
120+ PRIVATE ${CMAKE_DL_LIBS} ${capstone_LIBRARIES} )
121+
104122target_link_libraries (syscall_intercept_static
105- syscall_intercept_base_c syscall_intercept_base_asm )
123+ INTERFACE ${CMAKE_DL_LIBS} ${capstone_LIBRARIES} )
106124
107125set_target_properties (syscall_intercept_shared
108126 PROPERTIES VERSION ${SYSCALL_INTERCEPT_VERSION}
109127 SOVERSION ${SYSCALL_INTERCEPT_VERSION_MAJOR} )
110128
111129add_executable (cpp_test src/cpp_compile_test.cc src/cpp_compile_mock.c)
112130
113- if (CMAKE_OBJCOPY)
114- foreach (target syscall_intercept_shared syscall_intercept_static)
115- add_custom_command (TARGET ${target}
116- POST_BUILD COMMAND ${CMAKE_OBJCOPY}
117- --localize-hidden
118- -G intercept_hook_point
119- -G syscall_no_intercept
120- -G libc_hook_in_process_allowed
121- $<TARGET_FILE:${target} >)
122- endforeach ()
123- endif ()
124-
125131set_target_properties (syscall_intercept_shared syscall_intercept_static
126132 PROPERTIES
133+ LINKER_LANGUAGE C
127134 PUBLIC_HEADER "include/libsyscall_intercept_hook_point.h"
128135 OUTPUT_NAME syscall_intercept)
129136
0 commit comments