Skip to content

Commit

Permalink
[Driver][FreeBSD] -r: imply -nostdlib like GCC
Browse files Browse the repository at this point in the history
Similar to D116843 for Gnu.cpp

Reviewed By: dim

Differential Revision: https://reviews.llvm.org/D117388
  • Loading branch information
MaskRay committed Jan 17, 2022
1 parent 09949c4 commit 427d3b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions clang/lib/Driver/ToolChains/FreeBSD.cpp
Expand Up @@ -247,7 +247,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
assert(Output.isNothing() && "Invalid output.");
}

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
const char *crt1 = nullptr;
if (!Args.hasArg(options::OPT_shared)) {
if (Args.hasArg(options::OPT_pg))
Expand Down Expand Up @@ -295,7 +296,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,

unsigned Major = ToolChain.getTriple().getOSMajorVersion();
bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
// Use the static OpenMP runtime with -static-openmp
bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
!Args.hasArg(options::OPT_static);
Expand Down Expand Up @@ -358,7 +360,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
if (Args.hasArg(options::OPT_shared) || IsPIE)
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
else
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/freebsd.c
Expand Up @@ -205,3 +205,10 @@
// RUN: %clang -target ppc64-unknown-freebsd13.0 -### -S %s 2>&1 | \
// RUN: FileCheck -check-prefix=PPC64-MUNWIND %s
// PPC64-MUNWIND: "-funwind-tables=2"

/// -r suppresses default -l and crt*.o like -nostdlib.
// RUN: %clang -### %s --target=aarch64-pc-freebsd11 -r \
// RUN: --sysroot=%S/Inputs/basic_freebsd64_tree 2>&1 | FileCheck %s --check-prefix=RELOCATABLE
// RELOCATABLE: "-r"
// RELOCATABLE-NOT: "-l
// RELOCATABLE-NOT: crt{{[^.]+}}.o

0 comments on commit 427d3b9

Please sign in to comment.