aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-01-17 20:17:16 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-01-17 20:17:16 +0000
commit17d481fb97b304a58e45a136e3f3e2a2a22b76c8 (patch)
tree0f138b328c63725164909dfa65a529db882993b7
parent205ecf01939d6e9c903f0e1d51455b2d882d076b (diff)
Do not pass -pie flag to linker if -shared specified. This matches
the gcc driver and makes it possible to add -pie to $CC or similar and have it apply in the right places. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172753 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Driver/Tools.cpp2
-rw-r--r--test/Driver/pic.c6
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 199bb719de..372af79404 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -5506,7 +5506,7 @@ void linuxtools::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 (Args.hasArg(options::OPT_pie) && !Args.hasArg(options::OPT_shared))
CmdArgs.push_back("-pie");
if (Args.hasArg(options::OPT_rdynamic))
diff --git a/test/Driver/pic.c b/test/Driver/pic.c
index 54e5982c08..8ba931954b 100644
--- a/test/Driver/pic.c
+++ b/test/Driver/pic.c
@@ -34,6 +34,8 @@
//
// CHECK-NON-DARWIN-DYNAMIC-NO-PIC: error: unsupported option '-mdynamic-no-pic' for target 'i386-unknown-unknown'
//
+// CHECK-NO-PIE-NOT: "-pie"
+//
// RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC
// RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \
@@ -127,6 +129,10 @@
// RUN: %clang -c %s -target i386-unknown-unknown -static -fPIC -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC
//
+// On Linux, disregard -pie if we have -shared.
+// RUN: %clang %s -target i386-unknown-linux -shared -pie -### 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIE
+//
// Darwin is a beautiful and unique snowflake when it comes to these flags.
// When targetting a 32-bit darwin system, the -fno-* flag variants work and
// disable PIC, but any other flag enables PIC (*not* PIE) even if the flag