Skip to content

[libunwind] Don't override LINKER_LANGUAGE #143533

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FlyGoat
Copy link

@FlyGoat FlyGoat commented Jun 10, 2025

libunwind's GCC build fails because it tested -nostdlib++ flag against C++ linker but then use C linker to perform final linking, while gcc doesn't support this flag but g++ does.

The rationale for setting LINKER_LANGUAGE to C is to avoid pulling in C++ standard libraries. However this is already guaranteed by the combination of -nostdlib++ and empty CMAKE_CXX_IMPLICIT_LINK_LIBRARIES, thus we can safely remove this override.

However, in case -nostdlib++ is unsupported, we need to use -nodefaultlibs and link against rtlib & libc manually.

Closes #98440

libunwind's GCC build fails because it tested `-nostdlib++` flag against
C++ linker but then use C linker to perform final linking, while gcc doesn't
support this flag but g++ does.

The rationale for setting LINKER_LANGUAGE to C is to avoid pulling in
C++ standard libraries. However this is already guaranteed by the
combination of `-nostdlib++` and `empty CMAKE_CXX_IMPLICIT_LINK_LIBRARIES`,
thus we can safely remove this override.

However, in case `-nostdlib++` is unsupported, we need to use `-nodefaultlibs`
and link against rtlib & libc manually.
@FlyGoat FlyGoat requested a review from a team as a code owner June 10, 2025 13:30
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2025

@llvm/pr-subscribers-libunwind

Author: Jiaxun Yang (FlyGoat)

Changes

libunwind's GCC build fails because it tested -nostdlib++ flag against C++ linker but then use C linker to perform final linking, while gcc doesn't support this flag but g++ does.

The rationale for setting LINKER_LANGUAGE to C is to avoid pulling in C++ standard libraries. However this is already guaranteed by the combination of -nostdlib++ and empty CMAKE_CXX_IMPLICIT_LINK_LIBRARIES, thus we can safely remove this override.

However, in case -nostdlib++ is unsupported, we need to use -nodefaultlibs and link against rtlib & libc manually.


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

1 Files Affected:

  • (modified) libunwind/src/CMakeLists.txt (+3-2)
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 70bd3a017cda7..e83d11363f7e4 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -74,6 +74,9 @@ set(LIBUNWIND_SOURCES
 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
+  if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
+    add_link_flags_if_supported(-nodefaultlibs)
+  endif()
   if (LIBUNWIND_USE_COMPILER_RT)
     add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
   else()
@@ -164,7 +167,6 @@ set_target_properties(unwind_shared
   PROPERTIES
     EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_SHARED}>,FALSE,TRUE>"
     LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
-    LINKER_LANGUAGE C
     OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
     VERSION     "${LIBUNWIND_LIBRARY_VERSION}"
     SOVERSION   "1"
@@ -211,7 +213,6 @@ set_target_properties(unwind_static
   PROPERTIES
     EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_STATIC}>,FALSE,TRUE>"
     LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
-    LINKER_LANGUAGE C
     OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
 )
 

@FlyGoat FlyGoat changed the title [libunwind] Don't override LINKER_LANGUAGE (#98440) [libunwind] Don't override LINKER_LANGUAGE Jun 10, 2025
@FlyGoat
Copy link
Author

FlyGoat commented Jun 10, 2025

@MaskRay Do you mind to help me merge once I get necessary approval? I’m not a commiter yet.

@MaskRay
Copy link
Member

MaskRay commented Jun 12, 2025

This branch has conflicts that must be resolved

Please rebase :)

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

I don't think this is required, or even works after #143162.

@FlyGoat
Copy link
Author

FlyGoat commented Jun 12, 2025

@philnik777 Sorry I wasn’t aware of that. However #143162 breaks my use case of bootstrapping libunwind with compiler-rt builtins from same runtime build. I’ll try to come up with a more comprehensive solution.

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.

build libunwind with gcc error: gcc: error: unrecognized command-line option ‘-nostdlib++’
4 participants