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-STATIC: "-static"
     15 // CHECK-NO-STATIC-NOT: "-static"
     16 //
     17 // CHECK-PIE1: "-mrelocation-model" "pic"
     18 // CHECK-PIE1: "-pic-level" "1"
     19 // CHECK-PIE1: "-pie-level" "1"
     20 //
     21 // CHECK-PIE2: "-mrelocation-model" "pic"
     22 // CHECK-PIE2: "-pic-level" "2"
     23 // CHECK-PIE2: "-pie-level" "2"
     24 //
     25 // CHECK-PIE-LD: "{{.*}}ld{{(.exe)?}}"
     26 // CHECK-PIE-LD: "-pie"
     27 // CHECK-PIE-LD: "Scrt1.o" "crti.o" "crtbeginS.o"
     28 // CHECK-PIE-LD: "crtendS.o" "crtn.o"
     29 //
     30 // CHECK-NOPIE-LD: "-nopie"
     31 //
     32 // CHECK-DYNAMIC-NO-PIC-32: "-mrelocation-model" "dynamic-no-pic"
     33 // CHECK-DYNAMIC-NO-PIC-32-NOT: "-pic-level"
     34 // CHECK-DYNAMIC-NO-PIC-32-NOT: "-pie-level"
     35 //
     36 // CHECK-DYNAMIC-NO-PIC-64: "-mrelocation-model" "dynamic-no-pic"
     37 // CHECK-DYNAMIC-NO-PIC-64: "-pic-level" "2"
     38 // CHECK-DYNAMIC-NO-PIC-64-NOT: "-pie-level"
     39 //
     40 // CHECK-NON-DARWIN-DYNAMIC-NO-PIC: error: unsupported option '-mdynamic-no-pic' for target 'i386-unknown-unknown'
     41 //
     42 // CHECK-NO-PIE-NOT: "-pie"
     43 //
     44 // CHECK-NO-UNUSED-ARG-NOT: argument unused during compilation
     45 //
     46 // RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \
     47 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     48 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \
     49 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
     50 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -### 2>&1 \
     51 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
     52 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -### 2>&1 \
     53 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
     54 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -### 2>&1 \
     55 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
     56 //
     57 // Check that PIC and PIE flags obey last-match-wins. If the last flag is
     58 // a no-* variant, regardless of which variant or which flags precede it, we
     59 // get no PIC.
     60 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-pic -### 2>&1 \
     61 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     62 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-pic -### 2>&1 \
     63 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     64 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-pic -### 2>&1 \
     65 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     66 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-pic -### 2>&1 \
     67 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     68 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-PIC -### 2>&1 \
     69 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     70 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-PIC -### 2>&1 \
     71 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     72 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-PIC -### 2>&1 \
     73 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     74 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-PIC -### 2>&1 \
     75 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     76 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-pie -### 2>&1 \
     77 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     78 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-pie -### 2>&1 \
     79 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     80 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-pie -### 2>&1 \
     81 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     82 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-pie -### 2>&1 \
     83 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     84 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fno-PIE -### 2>&1 \
     85 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     86 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fno-PIE -### 2>&1 \
     87 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     88 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fno-PIE -### 2>&1 \
     89 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     90 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fno-PIE -### 2>&1 \
     91 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
     92 //
     93 // Last-match-wins where both pic and pie are specified.
     94 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fpic -### 2>&1 \
     95 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
     96 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fpic -### 2>&1 \
     97 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
     98 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fPIC -### 2>&1 \
     99 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    100 // RUN: %clang -c %s -target i386-unknown-unknown -fPIE -fPIC -### 2>&1 \
    101 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    102 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fpie -### 2>&1 \
    103 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    104 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fpie -### 2>&1 \
    105 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    106 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fPIE -### 2>&1 \
    107 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    108 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fPIE -### 2>&1 \
    109 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    110 //
    111 // Last-match-wins when selecting level 1 vs. level 2.
    112 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fPIC -### 2>&1 \
    113 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    114 // RUN: %clang -c %s -target i386-unknown-unknown -fPIC -fpic -### 2>&1 \
    115 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
    116 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -fPIE -fpie -### 2>&1 \
    117 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    118 // RUN: %clang -c %s -target i386-unknown-unknown -fpie -fPIC -fPIE -### 2>&1 \
    119 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    120 //
    121 // Make sure -pie is passed to along to ld and that the right *crt* files
    122 // are linked in.
    123 // RUN: %clang %s -target i386-unknown-freebsd -fPIE -pie -### \
    124 // RUN: --gcc-toolchain="" \
    125 // RUN: --sysroot=%S/Inputs/basic_freebsd_tree 2>&1 \
    126 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE-LD
    127 // RUN: %clang %s -target i386-linux-gnu -fPIE -pie -### \
    128 // RUN: --gcc-toolchain="" \
    129 // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
    130 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE-LD
    131 // RUN: %clang %s -target i386-linux-gnu -fPIC -pie -### \
    132 // RUN: --gcc-toolchain="" \
    133 // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
    134 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE-LD
    135 //
    136 // Disregard any of the PIC-specific flags if we have a trump-card flag.
    137 // RUN: %clang -c %s -target i386-unknown-unknown -mkernel -fPIC -### 2>&1 \
    138 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    139 
    140 // The -static argument *doesn't* override PIC: -static only affects
    141 // linking, and -fPIC only affects code generation.
    142 // RUN: %clang -c %s -target i386-unknown-unknown -static -fPIC -### 2>&1 \
    143 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    144 // RUN: %clang %s -target i386-linux-gnu -static -fPIC -### \
    145 // RUN: --gcc-toolchain="" \
    146 // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \
    147 // RUN:   | FileCheck %s --check-prefix=CHECK-STATIC
    148 //
    149 // On Linux, disregard -pie if we have -shared.
    150 // RUN: %clang %s -target i386-unknown-linux -shared -pie -### 2>&1 \
    151 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIE
    152 //
    153 // Darwin is a beautiful and unique snowflake when it comes to these flags.
    154 // When targeting a 32-bit darwin system, the -fno-* flag variants work and
    155 // disable PIC, but any other flag enables PIC (*not* PIE) even if the flag
    156 // specifies PIE. On 64-bit targets, there is simply nothing you can do, there
    157 // is no PIE, there is only PIC when it comes to compilation.
    158 // RUN: %clang -c %s -target i386-apple-darwin -### 2>&1 \
    159 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    160 // RUN: %clang -c %s -target i386-apple-darwin -fpic -### 2>&1 \
    161 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    162 // RUN: %clang -c %s -target i386-apple-darwin -fPIC -### 2>&1 \
    163 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    164 // RUN: %clang -c %s -target i386-apple-darwin -fpie -### 2>&1 \
    165 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    166 // RUN: %clang -c %s -target i386-apple-darwin -fPIE -### 2>&1 \
    167 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    168 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -### 2>&1 \
    169 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    170 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIE -### 2>&1 \
    171 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    172 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -fpic -### 2>&1 \
    173 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    174 // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -fPIE -### 2>&1 \
    175 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    176 // RUN: %clang -c %s -target x86_64-apple-darwin -fno-PIC -### 2>&1 \
    177 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    178 // RUN: %clang -c %s -target x86_64-apple-darwin -fno-PIE -### 2>&1 \
    179 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    180 // RUN: %clang -c %s -target x86_64-apple-darwin -fpic -### 2>&1 \
    181 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    182 // RUN: %clang -c %s -target x86_64-apple-darwin -fPIE -### 2>&1 \
    183 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    184 // RUN: %clang -c %s -target x86_64-apple-darwin -fPIC -### 2>&1 \
    185 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-UNUSED-ARG
    186 //
    187 // Darwin gets even more special with '-mdynamic-no-pic'. This flag is only
    188 // valid on Darwin, and it's behavior is very strange but needs to remain
    189 // consistent for compatibility.
    190 // RUN: %clang -c %s -target i386-unknown-unknown -mdynamic-no-pic -### 2>&1 \
    191 // RUN:   | FileCheck %s --check-prefix=CHECK-NON-DARWIN-DYNAMIC-NO-PIC
    192 // RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -### 2>&1 \
    193 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-32
    194 // RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -fno-pic -### 2>&1 \
    195 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-32
    196 // RUN: %clang -c %s -target i386-apple-darwin -mdynamic-no-pic -fpie -### 2>&1 \
    197 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-32
    198 // RUN: %clang -c %s -target x86_64-apple-darwin -mdynamic-no-pic -### 2>&1 \
    199 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-64
    200 // RUN: %clang -c %s -target x86_64-apple-darwin -mdynamic-no-pic -fno-pic -### 2>&1 \
    201 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-64
    202 // RUN: %clang -c %s -target x86_64-apple-darwin -mdynamic-no-pic -fpie -### 2>&1 \
    203 // RUN:   | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC-64
    204 //
    205 // Checks for ARM+Apple+IOS including -fapple-kext, -mkernel, and iphoneos
    206 // version boundaries.
    207 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -### 2>&1 \
    208 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    209 // RUN: %clang -c %s -target armv7-apple-ios -mkernel -miphoneos-version-min=6.0.0 -### 2>&1 \
    210 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    211 // RUN: %clang -c %s -target arm64-apple-ios -mkernel -miphoneos-version-min=7.0.0 -### 2>&1 \
    212 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    213 // RUN: %clang -x assembler -c %s -target arm64-apple-ios -mkernel -miphoneos-version-min=7.0.0 -no-integrated-as -### 2>&1 \
    214 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-STATIC
    215 // RUN: %clang -c %s -target armv7k-apple-watchos -fapple-kext -mwatchos-version-min=1.0.0 -### 2>&1 \
    216 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    217 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=5.0.0 -### 2>&1 \
    218 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    219 // RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -static -### 2>&1 \
    220 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    221 //
    222 // On OpenBSD, PIE is enabled by default, but can be disabled.
    223 // RUN: %clang -c %s -target amd64-pc-openbsd -### 2>&1 \
    224 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    225 // RUN: %clang -c %s -target i386-pc-openbsd -### 2>&1 \
    226 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    227 // RUN: %clang -c %s -target mips64-unknown-openbsd -### 2>&1 \
    228 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    229 // RUN: %clang -c %s -target mips64el-unknown-openbsd -### 2>&1 \
    230 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE1
    231 // RUN: %clang -c %s -target powerpc-unknown-openbsd -### 2>&1 \
    232 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    233 // RUN: %clang -c %s -target sparc-unknown-openbsd -### 2>&1 \
    234 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    235 // RUN: %clang -c %s -target sparc64-unknown-openbsd -### 2>&1 \
    236 // RUN:   | FileCheck %s --check-prefix=CHECK-PIE2
    237 // RUN: %clang -c %s -target i386-pc-openbsd -fno-pie -### 2>&1 \
    238 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
    239 //
    240 // On OpenBSD, -nopie needs to be passed through to the linker.
    241 // RUN: %clang %s -target i386-pc-openbsd -nopie -### 2>&1 \
    242 // RUN:   | FileCheck %s --check-prefix=CHECK-NOPIE-LD
    243 //
    244 // On Android PIC is enabled by default
    245 // RUN: %clang -c %s -target i686-linux-android -### 2>&1 \
    246 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    247 // RUN: %clang -c %s -target arm-linux-androideabi -### 2>&1 \
    248 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
    249 // RUN: %clang -c %s -target mipsel-linux-android -### 2>&1 \
    250 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
    251 // RUN: %clang -c %s -target aarch64-linux-android -### 2>&1 \
    252 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
    253 // RUN: %clang -c %s -target arm64-linux-android -### 2>&1 \
    254 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
    255 //
    256 // On Windows-X64 PIC is enabled by default
    257 // RUN: %clang -c %s -target x86_64-pc-windows-msvc18.0.0 -### 2>&1 \
    258 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    259 // RUN: %clang -c %s -target x86_64-pc-windows-gnu -### 2>&1 \
    260 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
    261