-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[flang][AArch64] Always link compiler-rt to flang after libgcc #144710
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
base: main
Are you sure you want to change the base?
Conversation
This patch fixes an issue where the __trampoline_setup symbol is missing with some programs compiled with flang. This symbol is present only in compiler-rt and not in libgcc. This patch adds compiler-rt to the link line after libgcc if libgcc is being used, so that only this symbol will be picked from compiler-rt.
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-clang-driver Author: David Truby (DavidTruby) ChangesThis patch fixes an issue where the __trampoline_setup symbol is missing Full diff: https://github.com/llvm/llvm-project/pull/144710.diff 3 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index d5b2c5c1e199e..672b73432847d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2252,6 +2252,13 @@ static void AddLibgcc(const ToolChain &TC, const Driver &D,
if (LGT == LibGccType::SharedLibGcc ||
(LGT == LibGccType::UnspecifiedLibGcc && D.CCCIsCXX()))
CmdArgs.push_back("-lgcc");
+ // compiler-rt is needed after libgcc for flang on AArch64 for the
+ // __trampoline_setup symbol
+ if (D.IsFlangMode() && TC.getArch() == llvm::Triple::aarch64) {
+ CmdArgs.push_back("--as-needed");
+ CmdArgs.push_back(TC.getCompilerRTArgString(Args, "builtins"));
+ CmdArgs.push_back("--no-as-needed");
+ }
}
void tools::AddRunTimeLibs(const ToolChain &TC, const Driver &D,
diff --git a/flang/test/Driver/flang-ld-aarch64.f90 b/flang/test/Driver/flang-ld-aarch64.f90
new file mode 100644
index 0000000000000..61cd46cea5cd1
--- /dev/null
+++ b/flang/test/Driver/flang-ld-aarch64.f90
@@ -0,0 +1,9 @@
+! Check linker flags for AArch64 linux, since it needs both libgcc and
+! compiler-rt, with compiler-rt second when -rtlib=libgcc.
+
+! RUN: %flang -### -rtlib=libgcc --target=aarch64-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s
+
+! CHECK-LABEL: "{{.*}}ld{{(\.exe)?}}"
+! CHECK-SAME: "-lflang_rt.runtime" "-lm"
+! CHECK-SAME: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+! CHECK-SAME: "--as-needed" "{{.*}}{{\\|/}}libclang_rt.builtins.a" "--no-as-needed"
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 0849bec26d56a..1b91e45c202e3 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -653,6 +653,13 @@ if(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD STREQUAL "all")
set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${LLVM_ALL_EXPERIMENTAL_TARGETS})
endif()
+if("flang" IN_LIST LLVM_ENABLE_PROJECTS AND
+ "AArch64" IN_LIST LLVM_TARGETS_TO_BUILD AND
+ NOT "compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+ message(STATUS "Enabling Flang-RT as a dependency of Flang")
+ list(APPEND LLVM_ENABLE_RUNTIMES "compiler-rt")
+endif()
+
set(LLVM_TARGETS_TO_BUILD
${LLVM_TARGETS_TO_BUILD}
${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
|
Can you add a fixes tag for #141147 ? |
Looks like the pre-commit CI has compiler-rt in LLVM_ENABLE_PROJECTS. I thought that wasn't supported anymore? Anyways I guess I have to add a check that it's not in ENABLE_PROJECTS as well as ENABLE_RUNTIMES |
Looks good to me modulo the CI issues. |
This patch fixes an issue where the __trampoline_setup symbol is missing
with some programs compiled with flang. This symbol is present only in
compiler-rt and not in libgcc. This patch adds compiler-rt to the link
line after libgcc if libgcc is being used, so that only this symbol will
be picked from compiler-rt.
Fixes #141147