diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -156,8 +156,17 @@ void BareMetal::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs) const { - CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" + - getTriple().getArchName())); + ToolChain::RuntimeLibType RLT = GetRuntimeLibType(Args); + switch (RLT) { + case ToolChain::RLT_CompilerRT: + CmdArgs.push_back( + Args.MakeArgString("-lclang_rt.builtins-" + getTriple().getArchName())); + return; + case ToolChain::RLT_Libgcc: + CmdArgs.push_back("-lgcc"); + return; + } + llvm_unreachable("Unhandled RuntimeLibType."); } void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp --- a/clang/test/Driver/baremetal.cpp +++ b/clang/test/Driver/baremetal.cpp @@ -83,3 +83,7 @@ // RUN: %clangxx -target arm-none-eabi -mthread-model posix -v 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-THREAD-MODEL-POSIX // CHECK-THREAD-MODEL-POSIX: Thread model: posix + +// RUN: %clang -### -target arm-none-eabi -rtlib=libgcc -v %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-RTLIB-GCC +// CHECK-RTLIB-GCC: -lgcc