1; RUN: llc -mtriple x86_64-pc-linux -relocation-model=static < %s | \ 2; RUN: FileCheck --check-prefixes=COMMON,STATIC %s 3; RUN: llc -mtriple x86_64-pc-linux -relocation-model=pic < %s | \ 4; RUN: FileCheck --check-prefixes=COMMON,CHECK %s 5; RUN: llc -mtriple x86_64-pc-linux -relocation-model=dynamic-no-pic < %s | \ 6; RUN: FileCheck --check-prefixes=COMMON,CHECK %s 7 8; 32 bits 9 10; RUN: llc -mtriple i386-pc-linux \ 11; RUN: -relocation-model=pic < %s | FileCheck --check-prefix=CHECK32 %s 12 13; globals 14 15@strong_default_global = global i32 42 16define ptr @get_strong_default_global() { 17 ret ptr @strong_default_global 18} 19; CHECK: movq strong_default_global@GOTPCREL(%rip), %rax 20; STATIC: movq strong_default_global@GOTPCREL(%rip), %rax 21; CHECK32: movl strong_default_global@GOT(%eax), %eax 22 23@strong_hidden_global = hidden global i32 42 24define ptr @get_hidden_default_global() { 25 ret ptr @strong_hidden_global 26} 27; CHECK: leaq strong_hidden_global(%rip), %rax 28; STATIC: movl $strong_hidden_global, %eax 29; CHECK32: leal strong_hidden_global@GOTOFF(%eax), %eax 30 31@weak_default_global = weak global i32 42 32define ptr @get_weak_default_global() { 33 ret ptr @weak_default_global 34} 35; CHECK: movq weak_default_global@GOTPCREL(%rip), %rax 36; STATIC: movq weak_default_global@GOTPCREL(%rip), %rax 37; CHECK32: movl weak_default_global@GOT(%eax), %eax 38 39@external_default_global = external global i32 40define ptr @get_external_default_global() { 41 ret ptr @external_default_global 42} 43; CHECK: movq external_default_global@GOTPCREL(%rip), %rax 44; STATIC: movq external_default_global@GOTPCREL(%rip), %rax 45; CHECK32: movl external_default_global@GOT(%eax), %eax 46 47@strong_local_global = dso_local global i32 42 48define ptr @get_strong_local_global() { 49 ret ptr @strong_local_global 50} 51; CHECK: leaq .Lstrong_local_global$local(%rip), %rax 52; STATIC: movl $strong_local_global, %eax 53; CHECK32: leal .Lstrong_local_global$local@GOTOFF(%eax), %eax 54 55@weak_local_global = weak dso_local global i32 42 56define ptr @get_weak_local_global() { 57 ret ptr @weak_local_global 58} 59; CHECK: leaq weak_local_global(%rip), %rax 60; STATIC: movl $weak_local_global, %eax 61; CHECK32: leal weak_local_global@GOTOFF(%eax), %eax 62 63@external_local_global = external dso_local global i32 64define ptr @get_external_local_global() { 65 ret ptr @external_local_global 66} 67; CHECK: leaq external_local_global(%rip), %rax 68; STATIC: movl $external_local_global, %eax 69; CHECK32: leal external_local_global@GOTOFF(%eax), %eax 70 71 72@strong_preemptable_global = dso_preemptable global i32 42 73define ptr @get_strong_preemptable_global() { 74 ret ptr @strong_preemptable_global 75} 76; CHECK: movq strong_preemptable_global@GOTPCREL(%rip), %rax 77; STATIC: movq strong_preemptable_global@GOTPCREL(%rip), %rax 78; CHECK32: movl strong_preemptable_global@GOT(%eax), %eax 79 80@weak_preemptable_global = weak dso_preemptable global i32 42 81define ptr @get_weak_preemptable_global() { 82 ret ptr @weak_preemptable_global 83} 84; CHECK: movq weak_preemptable_global@GOTPCREL(%rip), %rax 85; STATIC: movq weak_preemptable_global@GOTPCREL(%rip), %rax 86; CHECK32: movl weak_preemptable_global@GOT(%eax), %eax 87 88@external_preemptable_global = external dso_preemptable global i32 89define ptr @get_external_preemptable_global() { 90 ret ptr @external_preemptable_global 91} 92; CHECK: movq external_preemptable_global@GOTPCREL(%rip), %rax 93; STATIC: movq external_preemptable_global@GOTPCREL(%rip), %rax 94; CHECK32: movl external_preemptable_global@GOT(%eax), %eax 95 96; aliases 97@aliasee = global i32 42 98 99@strong_default_alias = alias i32, ptr @aliasee 100define ptr @get_strong_default_alias() { 101 ret ptr @strong_default_alias 102} 103; CHECK: movq strong_default_alias@GOTPCREL(%rip), %rax 104; STATIC: movq strong_default_alias@GOTPCREL(%rip), %rax 105; CHECK32: movl strong_default_alias@GOT(%eax), %eax 106 107@strong_hidden_alias = hidden alias i32, ptr @aliasee 108define ptr @get_strong_hidden_alias() { 109 ret ptr @strong_hidden_alias 110} 111; CHECK: leaq strong_hidden_alias(%rip), %rax 112; STATIC: movl $strong_hidden_alias, %eax 113; CHECK32: leal strong_hidden_alias@GOTOFF(%eax), %eax 114 115@weak_default_alias = weak alias i32, ptr @aliasee 116define ptr @get_weak_default_alias() { 117 ret ptr @weak_default_alias 118} 119; CHECK: movq weak_default_alias@GOTPCREL(%rip), %rax 120; STATIC: movq weak_default_alias@GOTPCREL(%rip), %rax 121; CHECK32: movl weak_default_alias@GOT(%eax), %eax 122 123@strong_local_alias = dso_local alias i32, ptr @aliasee 124define ptr @get_strong_local_alias() { 125 ret ptr @strong_local_alias 126} 127; CHECK: leaq .Lstrong_local_alias$local(%rip), %rax 128; STATIC: movl $strong_local_alias, %eax 129; CHECK32: leal .Lstrong_local_alias$local@GOTOFF(%eax), %eax 130 131@weak_local_alias = weak dso_local alias i32, ptr @aliasee 132define ptr @get_weak_local_alias() { 133 ret ptr @weak_local_alias 134} 135; CHECK: leaq weak_local_alias(%rip), %rax 136; STATIC: movl $weak_local_alias, %eax 137; CHECK32: leal weak_local_alias@GOTOFF(%eax), %eax 138 139 140@strong_preemptable_alias = dso_preemptable alias i32, ptr @aliasee 141define ptr @get_strong_preemptable_alias() { 142 ret ptr @strong_preemptable_alias 143} 144; CHECK: movq strong_preemptable_alias@GOTPCREL(%rip), %rax 145; STATIC: movq strong_preemptable_alias@GOTPCREL(%rip), %rax 146; CHECK32: movl strong_preemptable_alias@GOT(%eax), %eax 147 148@weak_preemptable_alias = weak dso_preemptable alias i32, ptr @aliasee 149define ptr @get_weak_preemptable_alias() { 150 ret ptr @weak_preemptable_alias 151} 152; CHECK: movq weak_preemptable_alias@GOTPCREL(%rip), %rax 153; STATIC: movq weak_preemptable_alias@GOTPCREL(%rip), %rax 154; CHECK32: movl weak_preemptable_alias@GOT(%eax), %eax 155 156; functions 157 158define void @strong_default_function() { 159 ret void 160} 161define ptr @get_strong_default_function() { 162 ret ptr @strong_default_function 163} 164; CHECK: movq strong_default_function@GOTPCREL(%rip), %rax 165; STATIC: movq strong_default_function@GOTPCREL(%rip), %rax 166; CHECK32: movl strong_default_function@GOT(%eax), %eax 167 168define hidden void @strong_hidden_function() { 169 ret void 170} 171define ptr @get_strong_hidden_function() { 172 ret ptr @strong_hidden_function 173} 174; CHECK: leaq strong_hidden_function(%rip), %rax 175; STATIC: movl $strong_hidden_function, %eax 176; CHECK32: leal strong_hidden_function@GOTOFF(%eax), %eax 177 178define weak void @weak_default_function() { 179 ret void 180} 181define ptr @get_weak_default_function() { 182 ret ptr @weak_default_function 183} 184; CHECK: movq weak_default_function@GOTPCREL(%rip), %rax 185; STATIC: movq weak_default_function@GOTPCREL(%rip), %rax 186; CHECK32: movl weak_default_function@GOT(%eax), %eax 187 188declare void @external_default_function() 189define ptr @get_external_default_function() { 190 ret ptr @external_default_function 191} 192; CHECK: movq external_default_function@GOTPCREL(%rip), %rax 193; STATIC: movq external_default_function@GOTPCREL(%rip), %rax 194; CHECK32: movl external_default_function@GOT(%eax), %eax 195 196define dso_local void @strong_local_function() { 197 ret void 198} 199define ptr @get_strong_local_function() { 200 ret ptr @strong_local_function 201} 202; COMMON: {{^}}strong_local_function: 203; CHECK-NEXT: .Lstrong_local_function$local: 204; CHECK: leaq .Lstrong_local_function$local(%rip), %rax 205; STATIC: movl $strong_local_function, %eax 206; CHECK32: leal .Lstrong_local_function$local@GOTOFF(%eax), %eax 207 208define weak dso_local void @weak_local_function() { 209 ret void 210} 211define ptr @get_weak_local_function() { 212 ret ptr @weak_local_function 213} 214; CHECK: leaq weak_local_function(%rip), %rax 215; STATIC: movl $weak_local_function, %eax 216; CHECK32: leal weak_local_function@GOTOFF(%eax), %eax 217 218declare dso_local void @external_local_function() 219define ptr @get_external_local_function() { 220 ret ptr @external_local_function 221} 222; CHECK: leaq external_local_function(%rip), %rax 223; STATIC: movl $external_local_function, %eax 224; CHECK32: leal external_local_function@GOTOFF(%eax), %eax 225 226 227define dso_preemptable void @strong_preemptable_function() { 228 ret void 229} 230define ptr @get_strong_preemptable_function() { 231 ret ptr @strong_preemptable_function 232} 233; CHECK: movq strong_preemptable_function@GOTPCREL(%rip), %rax 234; STATIC: movq strong_preemptable_function@GOTPCREL(%rip), %rax 235; CHECK32: movl strong_preemptable_function@GOT(%eax), %eax 236 237define weak dso_preemptable void @weak_preemptable_function() { 238 ret void 239} 240define ptr @get_weak_preemptable_function() { 241 ret ptr @weak_preemptable_function 242} 243; CHECK: movq weak_preemptable_function@GOTPCREL(%rip), %rax 244; STATIC: movq weak_preemptable_function@GOTPCREL(%rip), %rax 245; CHECK32: movl weak_preemptable_function@GOT(%eax), %eax 246 247declare dso_preemptable void @external_preemptable_function() 248define ptr @get_external_preemptable_function() { 249 ret ptr @external_preemptable_function 250} 251; CHECK: movq external_preemptable_function@GOTPCREL(%rip), %rax 252; STATIC: movq external_preemptable_function@GOTPCREL(%rip), %rax 253; CHECK32: movl external_preemptable_function@GOT(%eax), %eax 254 255$comdat_nodeduplicate_local = comdat nodeduplicate 256$comdat_nodeduplicate_preemptable = comdat nodeduplicate 257$comdat_any_local = comdat any 258 259;; -fpic -fno-semantic-interposition may add dso_local. Some instrumentation 260;; may add comdat nodeduplicate. We should use local aliases to make the symbol 261;; non-preemptible in the linker. 262define dso_local ptr @comdat_nodeduplicate_local() comdat { 263 ret ptr @comdat_nodeduplicate_local 264} 265; CHECK: leaq .Lcomdat_nodeduplicate_local$local(%rip), %rax 266; STATIC: movl $comdat_nodeduplicate_local, %eax 267 268define dso_preemptable ptr @comdat_nodeduplicate_preemptable() comdat { 269 ret ptr @comdat_nodeduplicate_preemptable 270} 271; CHECK: movq comdat_nodeduplicate_preemptable@GOTPCREL(%rip), %rax 272; STATIC: movq comdat_nodeduplicate_preemptable@GOTPCREL(%rip), %rax 273 274;; Check the behavior for the invalid construct. 275define dso_local ptr @comdat_any_local() comdat { 276 ret ptr @comdat_any_local 277} 278; CHECK: leaq comdat_any_local(%rip), %rax 279; STATIC: movl $comdat_any_local, %eax 280 281!llvm.module.flags = !{!0} 282!0 = !{i32 7, !"PIC Level", i32 2} 283 284; COMMON: {{^}}strong_local_global: 285; CHECK-NEXT: .Lstrong_local_global$local: 286 287; COMMON: .globl strong_default_alias 288; COMMON-NEXT: .set strong_default_alias, aliasee 289; COMMON-NEXT: .globl strong_hidden_alias 290; COMMON-NEXT: .hidden strong_hidden_alias 291; COMMON-NEXT: .set strong_hidden_alias, aliasee 292; COMMON-NEXT: .weak weak_default_alias 293; COMMON-NEXT: .set weak_default_alias, aliasee 294; COMMON-NEXT: .globl strong_local_alias 295; COMMON-NEXT: .set strong_local_alias, aliasee 296; CHECK-NEXT: .set .Lstrong_local_alias$local, aliasee 297; COMMON-NEXT: .weak weak_local_alias 298; COMMON-NEXT: .set weak_local_alias, aliasee 299; COMMON-NEXT: .globl strong_preemptable_alias 300; COMMON-NEXT: .set strong_preemptable_alias, aliasee 301; COMMON-NEXT: .weak weak_preemptable_alias 302; COMMON-NEXT: .set weak_preemptable_alias, aliasee 303