Home | History | Annotate | Download | only in Driver
      1 // Test the driver's control over the PIC behavior. These consist of tests of
      2 // the relocation model flags and the pic level flags passed to CC1.
      3 //
      4 // CHECK-NO-PIC: "-mrelocation-model" "static"
      5 // CHECK-NO-PIC-NOT: "-pic-level"
      6 // CHECK-NO-PIC-NOT: "-pie-level"
      7 //
      8 // CHECK-PIC1: "-mrelocation-model" "pic"
      9 // CHECK-PIC1: "-pic-level" "1"
     10 //
     11 // CHECK-PIC2: "-mrelocation-model" "pic"
     12 // CHECK-PIC2: "-pic-level" "2"
     13 //
     14 // CHECK-PIE1: "-mrelocation-model" "pic"
     15 // CHECK-PIE1: "-pic-level" "1"
     16 // CHECK-PIE1: "-pie-level" "1"
     17 //
     18 // CHECK-PIE2: "-mrelocation-model" "pic"
     19 // CHECK-PIE2: "-pic-level" "2"
     20 // CHECK-PIE2: "-pie-level" "2"
     21 //
     22 // CHECK-PIE-LD: "{{.*}}ld{{(.exe)?}}"
     23 // CHECK-PIE-LD: "-pie"
     24 // CHECK-PIE-LD: "Scrt1.o" "crti.o" "crtbeginS.o"
     25 // CHECK-PIE-LD: "crtendS.o" "crtn.o"
     26 //
     27 // CHECK-DYNAMIC-NO-PIC-32: "-mrelocation-model" "dynamic-no-pic"
     28 // CHECK-DYNAMIC-NO-PIC-32-NOT: "-pic-level"
     29 // CHECK-DYNAMIC-NO-PIC-32-NOT: "-pie-level"
     30 //
     31 // CHECK-DYNAMIC-NO-PIC-64: "-mrelocation-model" "dynamic-no-pic"
     32 // CHECK-DYNAMIC-NO-PIC-64: "-pic-level" "2"
     33 // CHECK-DYNAMIC-NO-PIC-64-NOT: "-pie-level"
     34 //
     35 // CHECK-NON-DARWIN-DYNAMIC-NO-PIC: error: unsupported option '-mdynamic-no-pic' for target 'i386-unknown-unknown'
     36 //
     37 // CHECK-NO-PIE-NOT: "-pie"
     38 //
     39 // RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \
     40 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     41 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \
     42 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
     43 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -### 2>&1 \
     44 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
     45 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -### 2>&1 \
     46 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
     47 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -### 2>&1 \
     48 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
     49 //
     50 // Check that PIC and PIE flags obey last-match-wins. If the last flag is
     51 // a no-* variant, regardless of which variant or which flags precede it, we
     52 // get no PIC.
     53 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-pic -### 2>&1 \
     54 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     55 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-pic -### 2>&1 \
     56 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     57 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-pic -### 2>&1 \
     58 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     59 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-pic -### 2>&1 \
     60 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     61 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-PIC -### 2>&1 \
     62 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     63 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-PIC -### 2>&1 \
     64 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     65 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-PIC -### 2>&1 \
     66 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     67 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-PIC -### 2>&1 \
     68 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     69 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-pie -### 2>&1 \
     70 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     71 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-pie -### 2>&1 \
     72 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     73 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-pie -### 2>&1 \
     74 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     75 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-pie -### 2>&1 \
     76 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     77 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-PIE -### 2>&1 \
     78 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     79 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-PIE -### 2>&1 \
     80 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     81 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-PIE -### 2>&1 \
     82 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     83 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-PIE -### 2>&1 \
     84 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     85 //
     86 // Last-match-wins where both pic and pie are specified.
     87 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fpic -### 2>&1 \
     88 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
     89 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fpic -### 2>&1 \
     90 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
     91 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fPIC -### 2>&1 \
     92 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
     93 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fPIC -### 2>&1 \
     94 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
     95 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fpie -### 2>&1 \
     96 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
     97 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fpie -### 2>&1 \
     98 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
     99 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fPIE -### 2>&1 \
    100 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    101 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fPIE -### 2>&1 \
    102 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    103 //
    104 // Last-match-wins when selecting level 1 vs. level 2.
    105 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fPIC -### 2>&1 \
    106 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    107 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fpic -### 2>&1 \
    108 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
    109 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fPIE -fpie -### 2>&1 \
    110 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    111 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fPIC -fPIE -### 2>&1 \
    112 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    113 //
    114 // Make sure -pie is passed to along to ld and that the right *crt* files
    115 // are linked in.
    116 // RUN: %clang %s -target i386-unknown-freebsd -fPIE -pie -### \
    117 // RUN: --sysroot=%S/Inputs/basic_freebsd_tree 2>&1 \
    118 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE-LD
    119 // RUN: %clang %s -target i386-linux-gnu -fPIE -pie -### \
    120 // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
    121 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE-LD
    122 // RUN: %clang %s -target i386-linux-gnu -fPIC -pie -### \
    123 // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
    124 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE-LD
    125 //
    126 // Disregard any of the PIC-specific flags if we have a trump-card flag.
    127 // RUN: %clang -c %s -target i386-unknown-unknown -mkernel -fPIC -### 2>&1 \
    128 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    129 // RUN: %clang -c %s -target i386-unknown-unknown -static -fPIC -### 2>&1 \
    130 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    131 //
    132 // On Linux, disregard -pie if we have -shared.
    133 // RUN: %clang %s -target i386-unknown-linux -shared -pie -### 2>&1 \
    134 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIE
    135 //
    136 // Darwin is a beautiful and unique snowflake when it comes to these flags.
    137 // When targetting a 32-bit darwin system, the -fno-* flag variants work and
    138 // disable PIC, but any other flag enables PIC (*not* PIE) even if the flag
    139 // specifies PIE. On 64-bit targets, there is simply nothing you can do, there
    140 // is no PIE, there is only PIC when it comes to compilation.
    141 // RUN: %clang -c %s -target i386-apple-darwin -### 2>&1 \
    142 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    143 // RUN: %clang -c %s -target i386-apple-darwin -fpic -### 2>&1 \
    144 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    145 // RUN: %clang -c %s -target i386-apple-darwin -fPIC -### 2>&1 \
    146 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    147 // RUN: %clang -c %s -target i386-apple-darwin -fpie -### 2>&1 \
    148 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    149 // RUN: %clang -c %s -target i386-apple-darwin -fPIE -### 2>&1 \
    150 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    151 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -### 2>&1 \
    152 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    153 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIE -### 2>&1 \
    154 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    155 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -fpic -### 2>&1 \
    156 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    157 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -fPIE -### 2>&1 \
    158 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    159 // RUN: %clang -c %s -target x86_64-apple-darwin -fno-PIC -### 2>&1 \
    160 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    161 // RUN: %clang -c %s -target x86_64-apple-darwin -fno-PIE -### 2>&1 \
    162 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    163 // RUN: %clang -c %s -target x86_64-apple-darwin -fpic -### 2>&1 \
    164 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    165 // RUN: %clang -c %s -target x86_64-apple-darwin -fPIE -### 2>&1 \
    166 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    167 //
    168 // Darwin gets even more special with '-mdynamic-no-pic'. This flag is only
    169 // valid on Darwin, and it's behavior is very strange but needs to remain
    170 // consistent for compatibility.
    171 // RUN: %clang -c %s -target i386-unknown-unknown -mdynamic-no-pic -### 2>&1 \
    172 // RUN:   | FileCheck %s --check-prefix=CHECK-NON-DARWIN-DYNAMIC-NO-PIC
    173 // RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -### 2>&1 \
    174 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-32
    175 // RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -fno-pic -### 2>&1 \
    176 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-32
    177 // RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -fpie -### 2>&1 \
    178 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-32
    179 // RUN: %clang -c %s -target x86_64-apple-darwin -mdynamic-no-pic -### 2>&1 \
    180 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-64
    181 // RUN: %clang -c %s -target x86_64-apple-darwin -mdynamic-no-pic -fno-pic -### 2>&1 \
    182 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-64
    183 // RUN: %clang -c %s -target x86_64-apple-darwin -mdynamic-no-pic -fpie -### 2>&1 \
    184 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-64
    185 //
    186 // Checks for ARM+Apple+IOS including -fapple-kext, -mkernel, and iphoneos
    187 // version boundaries.
    188 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -### 2>&1 \
    189 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    190 // RUN: %clang -c %s -target armv7-apple-ios -mkernel -miphoneos-version-min=6.0.0 -### 2>&1 \
    191 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    192 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=5.0.0 -### 2>&1 \
    193 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    194 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -static -### 2>&1 \
    195 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    196