Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Driver/flang-ld-aarch64.f90
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this say "Enabling compiler-rt" instead of Flang_RT if the next line enables compiler-rt?

list(APPEND LLVM_ENABLE_RUNTIMES "compiler-rt")
endif()

set(LLVM_TARGETS_TO_BUILD
${LLVM_TARGETS_TO_BUILD}
${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
Expand Down
Loading