]> granicus.if.org Git - clang/commitdiff
[Driver] Use -push-/-pop-state and -as-needed for libc++ on Fuchsia
authorPetr Hosek <phosek@chromium.org>
Sat, 3 Nov 2018 01:43:25 +0000 (01:43 +0000)
committerPetr Hosek <phosek@chromium.org>
Sat, 3 Nov 2018 01:43:25 +0000 (01:43 +0000)
This avoids introducing unnecessary DT_NEEDED entries when using
C++ driver for linking C code or C++ code that doesn't use C++
standard library.

Differential Revision: https://reviews.llvm.org/D53854

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346064 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Fuchsia.cpp
test/Driver/fuchsia.cpp

index 94441fce7cd42d1ee3e818a0e4b9dbffe6ba1db1..f788f91d5d83b81d57988f194b22ee4b5e0e3669 100644 (file)
@@ -122,13 +122,14 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
       if (ToolChain.ShouldLinkCXXStdlib(Args)) {
         bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
                                    !Args.hasArg(options::OPT_static);
+        CmdArgs.push_back("--push-state");
+        CmdArgs.push_back("--as-needed");
         if (OnlyLibstdcxxStatic)
-          CmdArgs.push_back("-Bstatic");
+          CmdArgs.push_back("-static");
         ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-        if (OnlyLibstdcxxStatic)
-          CmdArgs.push_back("-Bdynamic");
+        CmdArgs.push_back("-lm");
+        CmdArgs.push_back("--pop-state");
       }
-      CmdArgs.push_back("-lm");
     }
 
     AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
index dad16e412e3e139f1d47c27f2370eb1e8960950b..ba9e9b49f72aae6733664557751025cd150da0b9 100644 (file)
 // CHECK-NOT: crti.o
 // CHECK-NOT: crtbegin.o
 // CHECK: "-L[[SYSROOT]]{{/|\\\\}}lib"
-// CHECK: "-lc++" "-lm"
+// CHECK: "--push-state"
+// CHECK: "--as-needed"
+// CHECK: "-lc++"
+// CHECK: "-lm"
+// CHECK: "--pop-state"
 // CHECK: "{{.*[/\\]}}libclang_rt.builtins-x86_64.a"
 // CHECK: "-lc"
 // CHECK-NOT: crtend.o
 // RUN: %clangxx %s -### --target=x86_64-unknown-fuchsia -static-libstdc++ \
 // RUN:     -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck %s -check-prefix=CHECK-STATIC
-// CHECK-STATIC: "-Bstatic"
+// CHECK-STATIC: "--push-state"
+// CHECK-STATIC: "--as-needed"
+// CHECK-STATIC: "-static"
 // CHECK-STATIC: "-lc++"
-// CHECK-STATIC: "-Bdynamic"
 // CHECK-STATIC: "-lm"
+// CHECK-STATIC: "--pop-state"
 // CHECK-STATIC: "-lc"