phosek created this revision.
phosek added reviewers: echristo, mcgrathr.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This can be used to disable libc linking. This flag is supported by
GCC since version 9 as well as some Clang target toolchains.


Repository:
  rC Clang

https://reviews.llvm.org/D58326

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/nodefaultlib.c
  clang/test/Driver/nolibc.c


Index: clang/test/Driver/nolibc.c
===================================================================
--- /dev/null
+++ clang/test/Driver/nolibc.c
@@ -0,0 +1,5 @@
+// RUN: %clang -target i686-pc-linux-gnu -### -rtlib=libgcc -nolibc %s 2>&1 | 
FileCheck %s
+// CHECK: crtbegin
+// CHECK: "-lgcc"
+// CHECK-NOT: "-lc"
+// CHECK: crtend
Index: clang/test/Driver/nodefaultlib.c
===================================================================
--- clang/test/Driver/nodefaultlib.c
+++ clang/test/Driver/nodefaultlib.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target i686-pc-linux-gnu -### -nodefaultlibs %s 2>&1 | 
FileCheck -check-prefix=TEST1 %s
+// RUN: %clang -target i686-pc-linux-gnu -### -rtlib=libgcc -nodefaultlibs %s 
2>&1 | FileCheck -check-prefix=TEST1 %s
 // TEST1-NOT: start-group
 // TEST1-NOT: "-lgcc"
 // TEST1-NOT: "-lc"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -518,7 +518,8 @@
       if (Args.hasArg(options::OPT_fsplit_stack))
         CmdArgs.push_back("--wrap=pthread_create");
 
-      CmdArgs.push_back("-lc");
+      if (!Args.hasArg(options::OPT_nolibc))
+        CmdArgs.push_back("-lc");
 
       // Add IAMCU specific libs, if needed.
       if (IsIAMCU)


Index: clang/test/Driver/nolibc.c
===================================================================
--- /dev/null
+++ clang/test/Driver/nolibc.c
@@ -0,0 +1,5 @@
+// RUN: %clang -target i686-pc-linux-gnu -### -rtlib=libgcc -nolibc %s 2>&1 | FileCheck %s
+// CHECK: crtbegin
+// CHECK: "-lgcc"
+// CHECK-NOT: "-lc"
+// CHECK: crtend
Index: clang/test/Driver/nodefaultlib.c
===================================================================
--- clang/test/Driver/nodefaultlib.c
+++ clang/test/Driver/nodefaultlib.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target i686-pc-linux-gnu -### -nodefaultlibs %s 2>&1 | FileCheck -check-prefix=TEST1 %s
+// RUN: %clang -target i686-pc-linux-gnu -### -rtlib=libgcc -nodefaultlibs %s 2>&1 | FileCheck -check-prefix=TEST1 %s
 // TEST1-NOT: start-group
 // TEST1-NOT: "-lgcc"
 // TEST1-NOT: "-lc"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -518,7 +518,8 @@
       if (Args.hasArg(options::OPT_fsplit_stack))
         CmdArgs.push_back("--wrap=pthread_create");
 
-      CmdArgs.push_back("-lc");
+      if (!Args.hasArg(options::OPT_nolibc))
+        CmdArgs.push_back("-lc");
 
       // Add IAMCU specific libs, if needed.
       if (IsIAMCU)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to