Index: clang/lib/Driver/ToolChains/BareMetal.h =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.h +++ clang/lib/Driver/ToolChains/BareMetal.h @@ -57,8 +57,10 @@ llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; - void AddLinkRuntimeLib(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const; + + std::string getCompilerRT(const llvm::opt::ArgList &Args, + StringRef Component, + FileType Type = ToolChain::FT_Static) const override; }; } // namespace toolchains Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -154,10 +154,31 @@ CmdArgs.push_back("-lunwind"); } -void BareMetal::AddLinkRuntimeLib(const ArgList &Args, - ArgStringList &CmdArgs) const { - CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" + - getTriple().getArchName() + ".a")); +std::string BareMetal::getCompilerRT(const llvm::opt::ArgList &Args, + StringRef Component, + FileType Type) const { + SmallString<128> Path(getDriver().ResourceDir); + const char *Suffix; + switch (Type) { + case ToolChain::FT_Object: + Suffix = ".o"; + break; + case ToolChain::FT_Static: + Suffix = ".a"; + break; + case ToolChain::FT_Shared: + Suffix = ".so"; + break; + } + + // Builds of compiler-rt on bare-metal targets are specialized by specific + // architecture rather than architecture classes. We grab the triple's + // architecture explicitly so we don't just link the generic thumb-mode + // versions of these libraries. + auto Arch = getTriple().getArchName(); + llvm::sys::path::append( + Path, "lib", Twine("libclang_rt." + Component + "-" + Arch + Suffix)); + return Path.str(); } void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -185,7 +206,8 @@ CmdArgs.push_back("-lc"); CmdArgs.push_back("-lm"); - TC.AddLinkRuntimeLib(Args, CmdArgs); + CmdArgs.push_back(Args.MakeArgString( + TC.getCompilerRT(Args, "builtins"))); } CmdArgs.push_back("-o"); Index: clang/test/Driver/baremetal.cpp =================================================================== --- clang/test/Driver/baremetal.cpp +++ clang/test/Driver/baremetal.cpp @@ -13,7 +13,8 @@ // CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal" // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for" -// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" +// CHECK-V6M-C-SAME: "-lc" "-lm" +// CHECK-V6M-C-SAME: "{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}libclang_rt.builtins-armv6m.a" // CHECK-V6M-C-SAME: "-o" "{{.*}}.o" // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ @@ -35,7 +36,8 @@ // CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind" -// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" +// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" +// CHECK-V6M-DEFAULTCXX-SAME: "{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}libclang_rt.builtins-armv6m.a" // CHECK-V6M-DEFAULTCXX-SAME: "-o" "{{.*}}.o" // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ @@ -48,7 +50,8 @@ // CHECK-V6M-LIBCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind" -// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" +// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" +// CHECK-V6M-LIBCXX-SAME: "{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}libclang_rt.builtins-armv6m.a" // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o" // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ @@ -61,7 +64,8 @@ // CHECK-V6M-LIBSTDCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind" -// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" +// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" +// CHECK-V6M-LIBSTDCXX-SAME: "{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}libclang_rt.builtins-armv6m.a" // CHECK-V6M-LIBSTDCXX-SAME: "-o" "{{.*}}.o" // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \