[PATCH] D58326: [Driver][Gnu] Support -nolibc flag
Petr Hosek via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 16 17:20:12 PST 2019
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58326.187151.patch
Type: text/x-patch
Size: 1325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190217/c212566a/attachment.bin>
More information about the cfe-commits
mailing list