r245667 - Stop treating -static as overriding -fPIC: they are distinct.

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 20 21:14:56 PDT 2015


Author: jyknight
Date: Thu Aug 20 23:14:55 2015
New Revision: 245667

URL: http://llvm.org/viewvc/llvm-project?rev=245667&view=rev
Log:
Stop treating -static as overriding -fPIC: they are distinct.

For some reason, clang had been treating a command like:
 clang -static -fPIC foo.c
as if it should be compiled without the PIC relocation model.

This was incorrect: -static should be affecting only the linking
model, and -fPIC only the compilation.

This new behavior also matches GCC.

This is a follow-up from a review comment on r245447.

Differential Revision: http://reviews.llvm.org/D12208

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/pic.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=245667&r1=245666&r2=245667&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Aug 20 23:14:55 2015
@@ -3021,12 +3021,10 @@ ParsePICArgs(const ToolChain &ToolChain,
   if (PIC && ToolChain.getTriple().isOSDarwin())
     IsPICLevelTwo |= ToolChain.isPICDefault();
 
-  // Note that these flags are trump-cards. Regardless of the order w.r.t. the
-  // PIC or PIE options above, if these show up, PIC is disabled.
+  // This kernel flags are a trump-card: they will disable PIC/PIE
+  // generation, independent of the argument order.
   if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)))
     PIC = PIE = false;
-  if (Args.hasArg(options::OPT_static))
-    PIC = PIE = false;
 
   if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
     // This is a very special mode. It trumps the other modes, almost no one

Modified: cfe/trunk/test/Driver/pic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pic.c?rev=245667&r1=245666&r2=245667&view=diff
==============================================================================
--- cfe/trunk/test/Driver/pic.c (original)
+++ cfe/trunk/test/Driver/pic.c Thu Aug 20 23:14:55 2015
@@ -11,6 +11,7 @@
 // CHECK-PIC2: "-mrelocation-model" "pic"
 // CHECK-PIC2: "-pic-level" "2"
 //
+// CHECK-STATIC: "-static"
 // CHECK-NO-STATIC-NOT: "-static"
 //
 // CHECK-PIE1: "-mrelocation-model" "pic"
@@ -135,8 +136,15 @@
 // Disregard any of the PIC-specific flags if we have a trump-card flag.
 // RUN: %clang -c %s -target i386-unknown-unknown -mkernel -fPIC -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+
+// The -static argument *doesn't* override PIC: -static only affects
+// linking, and -fPIC only affects code generation.
 // RUN: %clang -c %s -target i386-unknown-unknown -static -fPIC -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+// RUN: %clang %s -target i386-linux-gnu -static -fPIC -### \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-STATIC
 //
 // On Linux, disregard -pie if we have -shared.
 // RUN: %clang %s -target i386-unknown-linux -shared -pie -### 2>&1 \
@@ -207,7 +215,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-NO-PIC
+// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 //
 // On OpenBSD, PIE is enabled by default, but can be disabled.
 // RUN: %clang -c %s -target amd64-pc-openbsd -### 2>&1 \




More information about the cfe-commits mailing list