From: Bob Wilson Date: Fri, 18 Dec 2015 20:37:54 +0000 (+0000) Subject: PIC should not be enabled by default on Darwin with -static. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b94b1a2175d90bec0b32a7660fd676ef3a4e0179;p=clang PIC should not be enabled by default on Darwin with -static. 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 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index c35aa1c754..a86308d9c3 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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 = diff --git a/test/Driver/pic.c b/test/Driver/pic.c index ca4b892e04..06b4204e60 100644 --- a/test/Driver/pic.c +++ b/test/Driver/pic.c @@ -217,7 +217,7 @@ // 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 \