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.

llvm-svn: 172753
This commit is contained in:
Peter Collingbourne 2013-01-17 20:17:16 +00:00
parent 5724ee9765
commit 24c67c6a63
2 changed files with 7 additions and 1 deletions

View File

@ -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))

View File

@ -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