mcarrasco created this revision. mcarrasco added reviewers: jroelofs, clang. mcarrasco added a project: clang-modules. Herald added subscribers: cfe-commits, abidh, kristof.beyls. Herald added a project: clang. mcarrasco requested review of this revision.
The Baremetal toolchain currently has a fixed behavior regardless of the -rtlib option's value. It is always linking against compiler-rt unless -nodefaultlibs is enabled. This proposal slightly changes the code in such a way that enabling -rtlib=libgcc implies linking against -libgcc. Something that I'm unsure about this patch is that we are not enforcing the existence of such libgcc. By reading other toolchains, I understood that is not always enforced. Do you think this policy is acceptable? If it is not, how would you think it should be addressed? Context: So far I manually set an -L path to a valid libgcc on my system when clang is invoked. In this particular case, I use arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -print-libgcc-file-name which retrieves the path I want. Assume the user forwards a gcc-toolchain installation through --gcc-toolchain. Would be a good idea to programmatically query arm-none-eabi-gcc for the libgcc as described above? If that is the case, how would be the most "llvm way" to do it? I'm not very related to all abstractions and concepts from the framework. This is my very first contribution to LLVM so I'd really appreciate any feedback in order to improve this proposal :) Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D87164 Files: clang/lib/Driver/ToolChains/BareMetal.cpp clang/test/Driver/baremetal.cpp Index: clang/test/Driver/baremetal.cpp =================================================================== --- clang/test/Driver/baremetal.cpp +++ 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 Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -156,8 +156,16 @@ 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())); + break; + case ToolChain::RLT_Libgcc: + CmdArgs.push_back("-lgcc"); + break; + } } void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Index: clang/test/Driver/baremetal.cpp =================================================================== --- clang/test/Driver/baremetal.cpp +++ 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 Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -156,8 +156,16 @@ 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())); + break; + case ToolChain::RLT_Libgcc: + CmdArgs.push_back("-lgcc"); + break; + } } void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits