Skip to content

Commit 21f87ad

Browse files
brad0tstellar
authored andcommitted
[Driver][NetBSD] -r: imply -nostdlib like GCC
Similar to D116843 for Gnu.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D119655 (cherry picked from commit d241ce0)
1 parent 779871c commit 21f87ad

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clang/lib/Driver/ToolChains/NetBSD.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
236236
assert(Output.isNothing() && "Invalid output.");
237237
}
238238

239-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
239+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
240+
options::OPT_r)) {
240241
if (!Args.hasArg(options::OPT_shared)) {
241242
CmdArgs.push_back(
242243
Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
@@ -294,7 +295,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
294295
}
295296
}
296297

297-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
298+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
299+
options::OPT_r)) {
298300
// Use the static OpenMP runtime with -static-openmp
299301
bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
300302
!Args.hasArg(options::OPT_static);
@@ -330,7 +332,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
330332
}
331333
}
332334

333-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
335+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
336+
options::OPT_r)) {
334337
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
335338
CmdArgs.push_back(
336339
Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));

clang/test/Driver/netbsd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,11 @@
467467
// RUN: %clang -target powerpc-unknown-netbsd -### -c %s 2>&1 \
468468
// RUN: | FileCheck -check-prefix=POWERPC-SECUREPLT %s
469469
// POWERPC-SECUREPLT: "-target-feature" "+secure-plt"
470+
471+
// -r suppresses default -l and crt*.o like -nostdlib.
472+
// RUN: %clang -no-canonical-prefixes -target x86_64-unknown-netbsd -r \
473+
// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \
474+
// RUN: | FileCheck -check-prefix=RELOCATABLE %s
475+
// RELOCATABLE: "-r"
476+
// RELOCATABLE-NOT: "-l
477+
// RELOCATABLE-NOT: crt{{[^.]+}}.o

0 commit comments

Comments
 (0)