[PATCH] D58320: [Darwin] Introduce a new flag, -flink-builtins-rt that forces linking of the builtins library.

2019-02-20 Thread Amara Emerson via Phabricator via cfe-commits
aemerson abandoned this revision.
aemerson added a comment.

After discussion on the thread, we can implement this requirement with -nolibc 
-nostdlib++ -nostartfiles


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58320/new/

https://reviews.llvm.org/D58320



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58320: [Darwin] Introduce a new flag, -flink-builtins-rt that forces linking of the builtins library.

2019-02-19 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

In D58320#1402254 , @peter.smith wrote:

> The implementation changes in the Darwin toolchain look fine to me, although 
> with respect to the command line option I think Petr Hosek's message on 
> cfe-dev is interesting:
>
> > GCC implements -nolibc which could be used to achieve the same effect when 
> > combined with -nostartfiles (and -nostdlib++ when compiling C++). I'd 
> > prefer that approach not only because it improves compatibility with with 
> > GCC, but also because it matches existing flag scheme which is subtractive 
> > rather than additive (i.e. -nodefaultlibs, -nostdlib, -nostdlib++, 
> > -nostartfiles). Clang already defines this flag but the only toolchain that 
> > currently supports it is DragonFly.
>
> Looking at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (quoted here 
> for convenience)
>
> > -nostartfiles
> >  Do not use the standard system startup files when linking. The standard 
> > system libraries are used normally, unless -nostdlib, -nolibc, or 
> > -nodefaultlibs is used.
> > -nolibc
> >  Do not use the C library or system libraries tightly coupled with it when 
> > linking. Still link with the startup files, libgcc or toolchain provided 
> > language support libraries such as libgnat, libgfortran or libstdc++ unless 
> > options preventing their inclusion are used as well. This typically removes 
> > -lc from the link command line, as well as system libraries that normally 
> > go with it and become meaningless when absence of a C library is assumed, 
> > for example -lpthread or -lm in some configurations. This is intended for 
> > bare-board targets when there is indeed no C library available.
>
> It does seem like these options accomplish what -flink_builtins_rt do with 
> the added advantage of being more portable with gcc. If they don't work for 
> you it will be worth double checking with Petr.


Thanks for taking a look. I've replied on the thread for the problem that 
approach presents.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58320/new/

https://reviews.llvm.org/D58320



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58320: [Darwin] Introduce a new flag, -flink-builtins-rt that forces linking of the builtins library.

2019-02-19 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

The implementation changes in the Darwin toolchain look fine to me, although 
with respect to the command line option I think Petr Hosek's message on cfe-dev 
is interesting:

> GCC implements -nolibc which could be used to achieve the same effect when 
> combined with -nostartfiles (and -nostdlib++ when compiling C++). I'd prefer 
> that approach not only because it improves compatibility with with GCC, but 
> also because it matches existing flag scheme which is subtractive rather than 
> additive (i.e. -nodefaultlibs, -nostdlib, -nostdlib++, -nostartfiles). Clang 
> already defines this flag but the only toolchain that currently supports it 
> is DragonFly.

Looking at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (quoted here 
for convenience)

> -nostartfiles
>  Do not use the standard system startup files when linking. The standard 
> system libraries are used normally, unless -nostdlib, -nolibc, or 
> -nodefaultlibs is used.
> -nolibc
>  Do not use the C library or system libraries tightly coupled with it when 
> linking. Still link with the startup files, libgcc or toolchain provided 
> language support libraries such as libgnat, libgfortran or libstdc++ unless 
> options preventing their inclusion are used as well. This typically removes 
> -lc from the link command line, as well as system libraries that normally go 
> with it and become meaningless when absence of a C library is assumed, for 
> example -lpthread or -lm in some configurations. This is intended for 
> bare-board targets when there is indeed no C library available.

It does seem like these options accomplish what -flink_builtins_rt do with the 
added advantage of being more portable with gcc. If they don't work for you it 
will be worth double checking with Petr.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58320/new/

https://reviews.llvm.org/D58320



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58320: [Darwin] Introduce a new flag, -flink-builtins-rt that forces linking of the builtins library.

2019-02-15 Thread Amara Emerson via Phabricator via cfe-commits
aemerson created this revision.
aemerson added reviewers: peter.smith, dexonsmith, ab.
aemerson added a project: clang.
Herald added subscribers: jdoerfert, jfb.

This driver flag is useful when users want to link against the compiler's 
builtins, but nothing else, and so use flags like -nostdlib.

Implemented only for Darwin at the moment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58320

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/test/Driver/darwin-flink-builtins-rt.c

Index: clang/test/Driver/darwin-flink-builtins-rt.c
===
--- /dev/null
+++ clang/test/Driver/darwin-flink-builtins-rt.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target arm64-apple-ios12.0 %s -nostdlib -flink-builtins-rt -### 2>&1 | FileCheck %s
+// RUN: %clang -target arm64-apple-ios12.0 %s -static -flink-builtins-rt -### 2>&1 | FileCheck %s
+// RUN: %clang -target arm64-apple-ios12.0 %s -flink-builtins-rt -### 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// CHECK-NOT: "-lSystem"
+// DEFAULT: "-lSystem"
+// CHECK: libclang_rt.ios.a
Index: clang/lib/Driver/ToolChains/Darwin.h
===
--- clang/lib/Driver/ToolChains/Darwin.h
+++ clang/lib/Driver/ToolChains/Darwin.h
@@ -157,7 +157,8 @@
   /// FIXME: This API is intended for use with embedded libraries only, and is
   /// misleadingly named.
   virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const;
+ llvm::opt::ArgStringList ,
+ bool ForceLinkBuiltinRT = false) const;
 
   virtual void addStartObjectFileArgs(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const {
@@ -495,7 +496,8 @@
   RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList ) const override;
 
   void AddLinkRuntimeLibArgs(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const override;
+ llvm::opt::ArgStringList ,
+ bool ForceLinkBuiltinRT = false) const override;
 
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList ,
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -568,15 +568,26 @@
 
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+
+  bool NoStdOrDefaultLibs =
+  Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs);
+  bool ForceLinkBuiltins = Args.hasArg(options::OPT_flink_builtins_rt);
+  if (!NoStdOrDefaultLibs || ForceLinkBuiltins) {
 // link_ssp spec is empty.
 
-// Let the tool chain choose which runtime library to link.
-getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs);
+// If we have both -nostdlib/nodefaultlibs and -flink-builtins-rt then
+// we just want to link the builtins, not the other libs like libSystem.
+if (NoStdOrDefaultLibs && ForceLinkBuiltins) {
+  getMachOToolChain().AddLinkRuntimeLib(Args, CmdArgs, "builtins");
+} else {
+  // Let the tool chain choose which runtime library to link.
+  getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs,
+ForceLinkBuiltins);
 
-// No need to do anything for pthreads. Claim argument to avoid warning.
-Args.ClaimAllArgs(options::OPT_pthread);
-Args.ClaimAllArgs(options::OPT_pthreads);
+  // No need to do anything for pthreads. Claim argument to avoid warning.
+  Args.ClaimAllArgs(options::OPT_pthread);
+  Args.ClaimAllArgs(options::OPT_pthreads);
+}
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
@@ -1074,7 +1085,8 @@
 }
 
 void DarwinClang::AddLinkRuntimeLibArgs(const ArgList ,
-ArgStringList ) const {
+ArgStringList ,
+bool ForceLinkBuiltinRT) const {
   // Call once to ensure diagnostic is printed if wrong value was specified
   GetRuntimeLibType(Args);
 
@@ -1082,8 +1094,11 @@
   // libraries with -static.
   if (Args.hasArg(options::OPT_static) ||
   Args.hasArg(options::OPT_fapple_kext) ||
-  Args.hasArg(options::OPT_mkernel))
+  Args.hasArg(options::OPT_mkernel)) {
+if (ForceLinkBuiltinRT)
+  AddLinkRuntimeLib(Args, CmdArgs, "builtins");
 return;
+  }
 
   // Reject -static-libgcc for now, we can deal with this when and if someone
   // cares. This is useful in situations where someone wants to statically link
@@ -2054,7 +2069,8 @@
 }