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