Skip to content

Commit

Permalink
i#58 MacOS: rpath on Mac
Browse files Browse the repository at this point in the history
Use the rpath equivalent on MacOS: -install_name @rpath/.. in each library,
and then -rpath @loader_path in the app.

SVN-Revision: 2396
  • Loading branch information
derekbruening committed Nov 25, 2013
1 parent 1df2d2f commit 02fdd65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
17 changes: 14 additions & 3 deletions core/CMakeLists.txt
Expand Up @@ -405,18 +405,25 @@ if (UNIX)
set_target_properties(${PRELOAD_NAME} PROPERTIES
LINK_FLAGS "-nostartfiles")

set(dynamorio_link_flags "")

# Do non-lazy runtime binding
if (APPLE)
set(dynamorio_link_flags "-Xlinker -bind_at_load")
set(dynamorio_link_flags "${dynamorio_link_flags} -Xlinker -bind_at_load")
else (APPLE)
set(dynamorio_link_flags "-Xlinker -z -Xlinker now")
set(dynamorio_link_flags "${dynamorio_link_flags} -Xlinker -z -Xlinker now")
endif (APPLE)

if (APPLE)
set(dynamorio_link_flags
"${dynamorio_link_flags} -install_name @rpath/libdynamorio.dylib")
endif (APPLE)

# Bind global symbols internally to avoid interposing
if (APPLE)
# Looks like -interposable is off by default
else (APPLE)
set(dynamorio_link_flags "-Xlinker -Bsymbolic")
set(dynamorio_link_flags "${dynamorio_link_flags} -Xlinker -Bsymbolic")
endif (APPLE)

set(dynamorio_link_flags "${dynamorio_link_flags} -nostdlib")
Expand Down Expand Up @@ -782,6 +789,10 @@ if (WIN32)
ARGS -E copy "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/drinjectlib.dll"
"${EXECUTABLE_OUTPUT_DIRECTORY}/" VERBATIM)
endif (WIN32)
if (APPLE)
set_target_properties(drinjectlib PROPERTIES
LINK_FLAGS "-install_name @rpath/libdrinjectlib.dylib")
endif (APPLE)

if (BUILD_TESTS)
add_executable(unit_tests unit_tests.c
Expand Down
4 changes: 4 additions & 0 deletions libutil/CMakeLists.txt
Expand Up @@ -112,6 +112,10 @@ set_target_properties(drconfiglib PROPERTIES
COMPILE_FLAGS "${libutil_cflags} -DRC_IS_DRCONFIGLIB"
# put dll in lib dir
RUNTIME_OUTPUT_DIRECTORY${location_suffix} "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
if (APPLE)
set_target_properties(drconfiglib PROPERTIES
LINK_FLAGS "-install_name @rpath/libdrconfiglib.dylib")
endif (APPLE)
add_gen_events_deps(drconfiglib)

if (WIN32)
Expand Down
6 changes: 5 additions & 1 deletion make/utils.cmake
Expand Up @@ -74,7 +74,11 @@ function (add_rel_rpaths target)
file(RELATIVE_PATH relpath "${tgt_path}" "${lib_path}")

# Append the new rpath element if it isn't there already.
set(new_lflag "-Wl,-rpath='$ORIGIN/${relpath}'")
if (APPLE)
set(new_lflag "-Wl,-rpath,'@loader_path/${relpath}'")
else (APPLE)
set(new_lflag "-Wl,-rpath='$ORIGIN/${relpath}'")
endif ()
get_target_property(lflags ${target} LINK_FLAGS)
if (NOT lflags MATCHES "\\$ORIGIN/${relpath}")
append_property_string(TARGET ${target} LINK_FLAGS "${new_lflag}")
Expand Down

0 comments on commit 02fdd65

Please sign in to comment.