From b1b57aae05ca6cedb7cb650c6d6244be3514ee1a Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 12 Feb 2020 18:14:58 -0800 Subject: [PATCH 1/5] Port ld arguments from Makefile --- bindings/c/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index b30a78bd84..e8becba257 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -38,6 +38,7 @@ else() endif() add_dependencies(fdb_c fdb_c_generated fdb_c_options) target_link_libraries(fdb_c PUBLIC $) +target_link_options(fdb_c PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map -Wl,-z,nodelete) target_include_directories(fdb_c PUBLIC $ $ From f1357fd48257364b26fcda2622d8f40750587c6a Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 12 Feb 2020 19:35:12 -0800 Subject: [PATCH 2/5] Control exported symbols on osx for cmake --- bindings/c/CMakeLists.txt | 16 +++++++++++++++- bindings/c/symbolify.py | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 bindings/c/symbolify.py diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index e8becba257..675a43c802 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -38,7 +38,21 @@ else() endif() add_dependencies(fdb_c fdb_c_generated fdb_c_options) target_link_libraries(fdb_c PUBLIC $) -target_link_options(fdb_c PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map -Wl,-z,nodelete) +if(APPLE) + set(symbols ${CMAKE_CURRENT_BINARY_DIR}/fdb_c.symbols) + add_custom_command(OUTPUT ${symbols} + COMMAND $ ${CMAKE_CURRENT_SOURCE_DIR}/symbolify.py + ${CMAKE_CURRENT_SOURCE_DIR}/foundationdb/fdb_c.h + ${symbols} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/symbolify.py ${CMAKE_CURRENT_SOURCE_DIR}/foundationdb/fdb_c.h + COMMENT "Generate exported_symbols_list") + add_custom_target(exported_symbols_list DEPENDS ${symbols}) + add_dependencies(fdb_c exported_symbols_list) + target_link_options(fdb_c PRIVATE -Xlinker -exported_symbols_list -Xlinker ${symbols}) +elseif(WIN32) +else() + target_link_options(fdb_c PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map -Wl,-z,nodelete) +endif() target_include_directories(fdb_c PUBLIC $ $ diff --git a/bindings/c/symbolify.py b/bindings/c/symbolify.py new file mode 100644 index 0000000000..255717353f --- /dev/null +++ b/bindings/c/symbolify.py @@ -0,0 +1,9 @@ +if __name__ == '__main__': + import re + import sys + r = re.compile('DLLEXPORT[^(]*(fdb_[^(]*)[(]') + (fdb_c_h, symbols_file) = sys.argv[1:] + with open(fdb_c_h, 'r') as f: + symbols = sorted(set('_' + m.group(1) for m in r.finditer(f.read()))) + with open(symbols_file, 'w') as f: + print('\n'.join(symbols), file=f) From aeba8f5cafbe7532a88797157ef9bfe161fa02de Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 12 Feb 2020 21:56:01 -0800 Subject: [PATCH 3/5] Fix symbolify.py --- bindings/c/symbolify.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/c/symbolify.py b/bindings/c/symbolify.py index 255717353f..55d8dc81fd 100644 --- a/bindings/c/symbolify.py +++ b/bindings/c/symbolify.py @@ -6,4 +6,5 @@ if __name__ == '__main__': with open(fdb_c_h, 'r') as f: symbols = sorted(set('_' + m.group(1) for m in r.finditer(f.read()))) with open(symbols_file, 'w') as f: - print('\n'.join(symbols), file=f) + f.write('\n'.join(symbols)) + f.write('\n') From e1f279ac98f77614067687db3a3251831bb5b3e0 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 13 Feb 2020 11:03:42 -0800 Subject: [PATCH 4/5] Use the cmake LINKER feature Described here: https://cmake.org/cmake/help/latest/command/add_link_options.html --- bindings/c/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 675a43c802..990eed91d0 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -48,10 +48,10 @@ if(APPLE) COMMENT "Generate exported_symbols_list") add_custom_target(exported_symbols_list DEPENDS ${symbols}) add_dependencies(fdb_c exported_symbols_list) - target_link_options(fdb_c PRIVATE -Xlinker -exported_symbols_list -Xlinker ${symbols}) + target_link_options(fdb_c PRIVATE "LINKER:-exported_symbols_list,${symbols}") elseif(WIN32) else() - target_link_options(fdb_c PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map -Wl,-z,nodelete) + target_link_options(fdb_c PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map,-z,nodelete") endif() target_include_directories(fdb_c PUBLIC $ From 40c9e2f3d8a1acf43bfe5769d7fd5d88222f5e2d Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Tue, 18 Feb 2020 10:49:43 -0800 Subject: [PATCH 5/5] Add -no_weak_exports --- bindings/c/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 990eed91d0..75b0a4e323 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -48,7 +48,7 @@ if(APPLE) COMMENT "Generate exported_symbols_list") add_custom_target(exported_symbols_list DEPENDS ${symbols}) add_dependencies(fdb_c exported_symbols_list) - target_link_options(fdb_c PRIVATE "LINKER:-exported_symbols_list,${symbols}") + target_link_options(fdb_c PRIVATE "LINKER:-no_weak_exports,-exported_symbols_list,${symbols}") elseif(WIN32) else() target_link_options(fdb_c PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map,-z,nodelete")