]> granicus.if.org Git - clang/commitdiff
Respect ToolChain::isPIEDefault() in constructing link job on Linux and FreeBSD.
authorAlexey Samsonov <samsonov@google.com>
Tue, 25 Feb 2014 13:26:03 +0000 (13:26 +0000)
committerAlexey Samsonov <samsonov@google.com>
Tue, 25 Feb 2014 13:26:03 +0000 (13:26 +0000)
Partially based on http://llvm-reviews.chandlerc.com/D2644 by Viktor Kutuzov.

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

lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h
lib/Driver/Tools.cpp
test/Driver/sanitizer-ld.c

index fb98e1236b304f8d9c49b86d92451ffef922a92d..5f62601e9dafa682765511b7c3e9f8b0deb62f1e 100644 (file)
@@ -2446,6 +2446,14 @@ bool FreeBSD::UseSjLjExceptions() const {
   }
 }
 
+bool FreeBSD::HasNativeLLVMSupport() const {
+  return true;
+}
+
+bool FreeBSD::isPIEDefault() const {
+  return getSanitizerArgs().hasZeroBaseShadow();
+}
+
 /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
 
 NetBSD::NetBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args)
@@ -2996,10 +3004,6 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   addPathIfExists(SysRoot + "/usr/lib", Paths);
 }
 
-bool FreeBSD::HasNativeLLVMSupport() const {
-  return true;
-}
-
 bool Linux::HasNativeLLVMSupport() const {
   return true;
 }
index 6c3b084bf726645d62d92e48f6c450d6c7f231c9..e4e25e632d30d8c296da3495feaedc244d221668 100644 (file)
@@ -590,6 +590,7 @@ public:
   }
 
   virtual bool UseSjLjExceptions() const;
+  virtual bool isPIEDefault() const;
 protected:
   virtual Tool *buildAssembler() const;
   virtual Tool *buildLinker() const;
index 371df4b62fefe84bd476e15cd8922351d2afda35..7934105bfc95b6c08f37be443c80f6046c63eece 100644 (file)
@@ -5992,6 +5992,9 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
   const toolchains::FreeBSD& ToolChain = 
     static_cast<const toolchains::FreeBSD&>(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const bool IsPIE =
+    !Args.hasArg(options::OPT_shared) &&
+    (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault());
   ArgStringList CmdArgs;
 
   // Silence warning for "clang -g foo.o -o foo"
@@ -6005,7 +6008,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
   if (!D.SysRoot.empty())
     CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  if (IsPIE)
     CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_static)) {
@@ -6055,7 +6058,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
     if (!Args.hasArg(options::OPT_shared)) {
       if (Args.hasArg(options::OPT_pg))
         crt1 = "gcrt1.o";
-      else if (Args.hasArg(options::OPT_pie))
+      else if (IsPIE)
         crt1 = "Scrt1.o";
       else
         crt1 = "crt1.o";
@@ -6068,7 +6071,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
     const char *crtbegin = NULL;
     if (Args.hasArg(options::OPT_static))
       crtbegin = "crtbeginT.o";
-    else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
+    else if (Args.hasArg(options::OPT_shared) || IsPIE)
       crtbegin = "crtbeginS.o";
     else
       crtbegin = "crtbegin.o";
@@ -6149,7 +6152,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
 
   if (!Args.hasArg(options::OPT_nostdlib) &&
       !Args.hasArg(options::OPT_nostartfiles)) {
-    if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
+    if (Args.hasArg(options::OPT_shared) || IsPIE)
       CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
     else
       CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
@@ -6640,10 +6643,9 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
   const Driver &D = ToolChain.getDriver();
   const bool isAndroid =
     ToolChain.getTriple().getEnvironment() == llvm::Triple::Android;
-  const SanitizerArgs &Sanitize = ToolChain.getSanitizerArgs();
   const bool IsPIE =
     !Args.hasArg(options::OPT_shared) &&
-    (Args.hasArg(options::OPT_pie) || Sanitize.hasZeroBaseShadow());
+    (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault());
 
   ArgStringList CmdArgs;
 
index f1c36446e91c81f4dd7e09d8e384f93d5e7477bd..57f33d8737a2d654fa1cfdbd6f9273e08c525535 100644 (file)
@@ -69,6 +69,8 @@
 // CHECK-ASAN-ANDROID-NOT: "-lc"
 // CHECK-ASAN-ANDROID: libclang_rt.asan-arm-android.so"
 // CHECK-ASAN-ANDROID-NOT: "-lpthread"
+// CHECK-ASAN-ANDROID: "-pie"
+// CHECK-ASAN-ANDROID-NOT: "-lpthread"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     -target arm-linux-androideabi -fsanitize=address \