Skip to content

[flang][runtime] Make sure to link libexecinfo if it exists #125344

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

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

brad0
Copy link
Contributor

@brad0 brad0 commented Feb 1, 2025

Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly and musl
libc with libexecinfo.

Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly
and musl libc with libexecinfo.
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Feb 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 1, 2025

@llvm/pr-subscribers-flang-runtime

Author: Brad Smith (brad0)

Changes

Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly and musl
libc with libexecinfo.


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

1 Files Affected:

  • (modified) flang/runtime/CMakeLists.txt (+7-2)
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index fbfaae9a880648..bf27a121e4d174 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -59,10 +59,15 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     )
 endif()
 
+set(linked_libraries FortranDecimal)
+
 # function checks
 find_package(Backtrace)
 set(HAVE_BACKTRACE ${Backtrace_FOUND})
 set(BACKTRACE_HEADER ${Backtrace_HEADER})
+if(HAVE_BACKTRACE)
+  list(APPEND linked_libraries ${Backtrace_LIBRARY})
+endif()
 
 include(CheckCXXSymbolExists)
 include(CheckCXXSourceCompiles)
@@ -271,7 +276,7 @@ if (NOT DEFINED MSVC)
   add_flang_library(FortranRuntime
     ${sources}
     LINK_LIBS
-    FortranDecimal
+    ${linked_libraries}
 
     INSTALL_WITH_TOOLCHAIN
   )
@@ -279,7 +284,7 @@ else()
   add_flang_library(FortranRuntime
     ${sources}
     LINK_LIBS
-    FortranDecimal
+    ${linked_libraries}
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
   add_flang_library(FortranRuntime.static ${sources}

@brad0
Copy link
Contributor Author

brad0 commented Feb 1, 2025

@tblah @dty2 @luporl @klausler

@brad0 brad0 added this to the LLVM 20.X Release milestone Feb 2, 2025
Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@brad0 brad0 merged commit cb2598d into llvm:main Feb 3, 2025
11 checks passed
@brad0 brad0 deleted the flang_runtime_backtrace branch February 3, 2025 15:04
@Meinersbur
Copy link
Member

If CMake knows to link to libexecinfo, doesn't mean that the flang driver does. This will influence how unittests are linked, but what ensures that an executable created by flang is linked correctly?

@tblah
Copy link
Contributor

tblah commented Feb 4, 2025

I'm definitely not an expert in this area but wouldn't this be a dependency of the runtime library so when the runtime library is loaded this would be too? Then flang just needs to know to link the runtime library

@Meinersbur
Copy link
Member

I'm definitely not an expert in this area but wouldn't this be a dependency of the runtime library so when the runtime library is loaded this would be too? Then flang just needs to know to link the runtime library

If it is a static library, then no. There is no mechanism for transitive dependencies in ld.

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 5, 2025
)

Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly and musl
libc with libexecinfo.

(cherry picked from commit cb2598d)
@Meinersbur
Copy link
Member

If CMake knows to link to libexecinfo, doesn't mean that the flang driver does. This will influence how unittests are linked, but what ensures that an executable created by flang is linked correctly?

#125998 does

Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
)

Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly and musl
libc with libexecinfo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

4 participants