]> granicus.if.org Git - clang/commitdiff
PIC should not be enabled by default on Darwin with -static.
authorBob Wilson <bob.wilson@apple.com>
Fri, 18 Dec 2015 20:37:54 +0000 (20:37 +0000)
committerBob Wilson <bob.wilson@apple.com>
Fri, 18 Dec 2015 20:37:54 +0000 (20:37 +0000)
r245667 changed -static so that it doesn't override an explicit -fPIC
option, but -static should still change the default for Darwin for -fno-PIC.
This matches longstanding GCC and Clang behavior on Darwin and changing it
would be disruptive, with no significant benefit.
http://reviews.llvm.org/D15455
rdar://problem/23811045

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

lib/Driver/Tools.cpp
test/Driver/pic.c

index c35aa1c754dd6f10799bbf2a2f96332b8ddd4a08..a86308d9c3a00a3acde0c30faa762a876fff963a 100644 (file)
@@ -3226,6 +3226,9 @@ ParsePICArgs(const ToolChain &ToolChain, const llvm::Triple &Triple,
   // ToolChain.getTriple() and Triple?
   bool PIE = ToolChain.isPIEDefault();
   bool PIC = PIE || ToolChain.isPICDefault();
+  // The Darwin default to use PIC does not apply when using -static.
+  if (ToolChain.getTriple().isOSDarwin() && Args.hasArg(options::OPT_static))
+    PIE = PIC = false;
   bool IsPICLevelTwo = PIC;
 
   bool KernelOrKext =
index ca4b892e0470dc6d2b9a658aba35eedad488ac89..06b4204e60da1591a6682a649dc6b16e504afd42 100644 (file)
 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=5.0.0 -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -static -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
 //
 // On OpenBSD, PIE is enabled by default, but can be disabled.
 // RUN: %clang -c %s -target amd64-pc-openbsd -### 2>&1 \