[llvm-branch-commits] [clang] 9827a18 - [Driver][Ananas] -r: imply -nostdlib like GCC

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 18 20:11:55 PDT 2022


Author: Brad Smith
Date: 2022-05-18T19:56:45-07:00
New Revision: 9827a185b611b33b7735458e024eab7a0646bc40

URL: https://github.com/llvm/llvm-project/commit/9827a185b611b33b7735458e024eab7a0646bc40
DIFF: https://github.com/llvm/llvm-project/commit/9827a185b611b33b7735458e024eab7a0646bc40.diff

LOG: [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 a132e527f25164268e08ebc63b043bbce8a043ed)

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Ananas.cpp
    clang/test/Driver/ananas.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Ananas.cpp b/clang/lib/Driver/ToolChains/Ananas.cpp
index be1476a7636c6..40f9e56b38e94 100644
--- a/clang/lib/Driver/ToolChains/Ananas.cpp
+++ b/clang/lib/Driver/ToolChains/Ananas.cpp
@@ -85,7 +85,8 @@ void ananas::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)) {
     if (!Args.hasArg(options::OPT_shared)) {
       CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
     }
@@ -111,12 +112,15 @@ void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
-  if (ToolChain.ShouldLinkCXXStdlib(Args))
-    ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+                   options::OPT_r)) {
+    if (ToolChain.ShouldLinkCXXStdlib(Args))
+      ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
     CmdArgs.push_back("-lc");
+  }
 
-  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) || Args.hasArg(options::OPT_pie))
       CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
     else

diff  --git a/clang/test/Driver/ananas.c b/clang/test/Driver/ananas.c
index 4edc2a10941c7..bd36fae6f424a 100644
--- a/clang/test/Driver/ananas.c
+++ b/clang/test/Driver/ananas.c
@@ -15,3 +15,10 @@
 // CHECK-SHARED: crtbeginS.o
 // CHECK-SHARED: crtendS.o
 // CHECK-SHARED: crtn.o
+
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang %s -### -o %t.o --target=x86_64-unknown-ananas -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE:     "-r"
+// CHECK-RELOCATABLE-NOT: "-l
+// CHECK-RELOCATABLE-NOT: {{.*}}crt{{[^.]+}}.o


        


More information about the llvm-branch-commits mailing list