Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libunwind] Pass -Wl,--export-dynamic on all supported platforms #67205

Merged
merged 1 commit into from Sep 25, 2023

Conversation

arichardson
Copy link
Member

@arichardson arichardson commented Sep 22, 2023

I was trying to run the tests on FreeBSD and noticed that we weren't printing symbol names. It turns out this is because of the missing -Wl,--export-dynamic flag. Instead of hardcoding the name of the flag and only passing it for Linux hosts, use a pre-existing CMake variable instead. I was not aware of this flag, but it appears to have been supported for the past 16 years (with support for more platforms added later): https://gitlab.kitware.com/cmake/cmake/-/commit/66d1930f5674f08e09f455b3f0777f2de3e0717e

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 22, 2023

@llvm/pr-subscribers-libunwind

Changes

I was trying to run the tests on FreeBSD and noticed that we weren't printing symbol names. It turns out this is because of the missing -Wl,--export dynamic flag. Instead of hardcoding the name of the flag and only passing it for Linux hosts, use a pre-existing CMake variable instead. I was not aware of this flag, but it appears to have been supported for the past 16 years (with support for more platforms added later): https://gitlab.kitware.com/cmake/cmake/-/commit/66d1930f5674f08e09f455b3f0777f2de3e0717e


Full diff: https://github.com/llvm/llvm-project/pull/67205.diff

3 Files Affected:

  • (modified) libunwind/test/configs/llvm-libunwind-merged.cfg.in (+4-2)
  • (modified) libunwind/test/configs/llvm-libunwind-shared.cfg.in (+4-2)
  • (modified) libunwind/test/configs/llvm-libunwind-static.cfg.in (+4-2)
diff --git a/libunwind/test/configs/llvm-libunwind-merged.cfg.in b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
index 10650f7edf66a2f..e6fafd1edd9756f 100644
--- a/libunwind/test/configs/llvm-libunwind-merged.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
@@ -11,8 +11,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
     compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-    link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+    link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
     link_flags.append('-l@CMAKE_DL_LIBS@')
diff --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index 97185e57234ff7f..f2e98c7a388dd32 100644
--- a/libunwind/test/configs/llvm-libunwind-shared.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
@@ -10,8 +10,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
     compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-    link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+    link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
     link_flags.append('-l@CMAKE_DL_LIBS@')
diff --git a/libunwind/test/configs/llvm-libunwind-static.cfg.in b/libunwind/test/configs/llvm-libunwind-static.cfg.in
index fc6a18d057f3884..1fbdec249855d4a 100644
--- a/libunwind/test/configs/llvm-libunwind-static.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-static.cfg.in
@@ -13,8 +13,10 @@ if @LIBUNWIND_ENABLE_THREADS@:
 if @LIBUNWIND_ENABLE_CET@:
     compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-    link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+    link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
     link_flags.append('-l@CMAKE_DL_LIBS@')

@brad0 brad0 requested a review from MaskRay September 23, 2023 01:22
@MaskRay
Copy link
Member

MaskRay commented Sep 23, 2023

the missing -Wl,--export dynamic flag

typo: missing -

if '@CMAKE_SYSTEM_NAME@' == 'Linux':
link_flags.append('-Wl,--export-dynamic')
# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
# be empty for Apple platforms).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for non-ELF platforms.

AIX linker doesn't have this option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the idea of the comment in the round brackets. I think it would be better to just say something like.. On ELF platforms, add -Wl,--export-dynamic if supported by the linker.

I was trying to run the tests on FreeBSD and noticed that we weren't
printing symbol names. It turns out this is because of the missing
-Wl,--export-dynamic flag. Instead of hardcoding the name of the flag
and only passing it for Linux hosts, use a pre-existing CMake variable
instead. I was not aware of this flag, but it appears to have been
supported for the past 16 years (with support for more platforms added
later): https://gitlab.kitware.com/cmake/cmake/-/commit/66d1930f5674f08e09f455b3f0777f2de3e0717e
@arichardson arichardson merged commit dae7e2d into llvm:main Sep 25, 2023
2 of 3 checks passed
@arichardson arichardson deleted the libunwind-export-dynamic branch September 25, 2023 15:42
@jsonn
Copy link
Contributor

jsonn commented Sep 25, 2023

Is this really desirable? It can actually break applications as it changes ELF semantics.

@arichardson
Copy link
Member Author

Is this really desirable? It can actually break applications as it changes ELF semantics.

I agree that it's not generally desirable, but this is only for the libunwind tests (which expect these semantics).

@jsonn
Copy link
Contributor

jsonn commented Sep 25, 2023

Can you as a small follow-up just update the comment to include that part? E.g.

# On ELF platforms, link tests with -Wl,--export-dynamic if supported by the linker.

Side note: the much older way for doing this is actually -rdynamic.

@arichardson
Copy link
Member Author

Can you as a small follow-up just update the comment to include that part? E.g.

Will do.

# On ELF platforms, link tests with -Wl,--export-dynamic if supported by the linker.

Side note: the much older way for doing this is actually -rdynamic.

It appears CMake actually still does this in one case:

Modules/Platform/Linux-TinyCC-C.cmake:set(CMAKE_EXE_EXPORTS_C_FLAG "-rdynamic ")

arichardson added a commit that referenced this pull request Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants