Skip to content

Commit 9827a18

Browse files
brad0tstellar
authored andcommitted
[Driver][Ananas] -r: imply -nostdlib like GCC
Similar to D116843 for Gnu.cpp Reviewed By: zhmu, MaskRay Differential Revision: https://reviews.llvm.org/D124729 (cherry picked from commit a132e52)
1 parent 087082a commit 9827a18

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

clang/lib/Driver/ToolChains/Ananas.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA,
8585
assert(Output.isNothing() && "Invalid output.");
8686
}
8787

88-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
88+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
89+
options::OPT_r)) {
8990
if (!Args.hasArg(options::OPT_shared)) {
9091
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
9192
}
@@ -111,12 +112,15 @@ void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA,
111112

112113
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
113114

114-
if (ToolChain.ShouldLinkCXXStdlib(Args))
115-
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
116-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
115+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
116+
options::OPT_r)) {
117+
if (ToolChain.ShouldLinkCXXStdlib(Args))
118+
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
117119
CmdArgs.push_back("-lc");
120+
}
118121

119-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
122+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
123+
options::OPT_r)) {
120124
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
121125
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
122126
else

clang/test/Driver/ananas.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@
1515
// CHECK-SHARED: crtbeginS.o
1616
// CHECK-SHARED: crtendS.o
1717
// CHECK-SHARED: crtn.o
18+
19+
// -r suppresses default -l and crt*.o like -nostdlib.
20+
// RUN: %clang %s -### -o %t.o --target=x86_64-unknown-ananas -r 2>&1 \
21+
// RUN: | FileCheck %s --check-prefix=CHECK-RELOCATABLE
22+
// CHECK-RELOCATABLE: "-r"
23+
// CHECK-RELOCATABLE-NOT: "-l
24+
// CHECK-RELOCATABLE-NOT: {{.*}}crt{{[^.]+}}.o

0 commit comments

Comments
 (0)