Skip to content

Commit 15f65af

Browse files
authored
[clang] Add option for -nolibc in Driver/ToolChains/Baremetal.cpp (#145700)
Some tests in LLVM-libc require this flag (#145349), which requires compiler-rt to be linked in, but not the C library. With this change, the `-nolibc` flag will not be ignored.
1 parent 6752415 commit 15f65af

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
671671
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
672672
CmdArgs.push_back("--start-group");
673673
AddRunTimeLibs(TC, D, CmdArgs, Args);
674-
CmdArgs.push_back("-lc");
674+
if (!Args.hasArg(options::OPT_nolibc))
675+
CmdArgs.push_back("-lc");
675676
if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D))
676677
CmdArgs.push_back("-lgloss");
677678
CmdArgs.push_back("--end-group");

clang/test/Driver/baremetal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@
163163
// RUN: | FileCheck %s --check-prefix=CHECK-RTLIB-GCC
164164
// CHECK-RTLIB-GCC: -lgcc
165165

166+
// RUN: %clang -### --target=arm-none-eabi -nolibc -rtlib=compiler-rt %s 2>&1 \
167+
// RUN: | FileCheck %s --check-prefix=CHECK-NOLIBC
168+
// CHECK-NOLIBC-NOT: "-lc"
169+
// CHECK-NOLIBC: "{{[^"]*}}libclang_rt.builtins.a"
170+
171+
// RUN: %clang -### --target=arm-none-eabi -nostdlib -rtlib=compiler-rt %s 2>&1 \
172+
// RUN: | FileCheck %s --check-prefix=CHECK-NOSTDLIB
173+
// CHECK-NOSTDLIB-NOT: "-lc"
174+
// CHECK-NOSTDLIB-NOT: "{{[^"]*}}libclang_rt.builtins.a"
175+
166176
// RUN: %clang -### --target=arm-none-eabi -v %s 2>&1 \
167177
// RUN: | FileCheck %s --check-prefix=CHECK-SYSROOT-INC
168178
// CHECK-SYSROOT-INC-NOT: "-internal-isystem" "include"

0 commit comments

Comments
 (0)