[PATCH] D124729: [Driver][Ananas] -r: imply -nostdlib like GCC

Brad Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 30 23:13:50 PDT 2022


brad created this revision.
brad added reviewers: MaskRay, zhmu.
brad added a project: clang.
Herald added a subscriber: StephenFan.
Herald added a project: All.
brad requested review of this revision.

Similar to D116843 <https://reviews.llvm.org/D116843> for Gnu.cpp


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124729

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


Index: clang/test/Driver/ananas.c
===================================================================
--- clang/test/Driver/ananas.c
+++ clang/test/Driver/ananas.c
@@ -15,3 +15,11 @@
 // CHECK-SHARED: crtbeginS.o
 // CHECK-SHARED: crtendS.o
 // CHECK-SHARED: crtn.o
+
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o \
+// RUN:     --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
Index: clang/lib/Driver/ToolChains/Ananas.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Ananas.cpp
+++ clang/lib/Driver/ToolChains/Ananas.cpp
@@ -85,7 +85,8 @@
     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 @@
 
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124729.426267.patch
Type: text/x-patch
Size: 2046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220501/6f6a2636/attachment.bin>


More information about the cfe-commits mailing list