Home | History | Annotate | Download | only in X86
      1 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -pie-copy-relocations \
      2 ; RUN:   | FileCheck -check-prefix=X64 %s
      3 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
      4 ; RUN:   | FileCheck -check-prefix=X32 %s
      5 
      6 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -pie-copy-relocations \
      7 ; RUN:   | FileCheck -check-prefix=X64 %s
      8 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic -pie-copy-relocations \
      9 ; RUN:   | FileCheck -check-prefix=X32 %s
     10 
     11 ; External Linkage
     12 @a = global i32 0, align 4
     13 
     14 define i32 @my_access_global_a() #0 {
     15 ; X32-LABEL: my_access_global_a:
     16 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
     17 ; X32-NEXT:  movl a@GOTOFF(%eax), %eax
     18 ; X64-LABEL: my_access_global_a:
     19 ; X64:       movl a(%rip), %eax
     20 
     21 entry:
     22   %0 = load i32, i32* @a, align 4
     23   ret i32 %0
     24 }
     25 
     26 ; WeakAny Linkage
     27 @b = weak global i32 0, align 4
     28 
     29 define i32 @my_access_global_b() #0 {
     30 ; X32-LABEL: my_access_global_b:
     31 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
     32 ; X32-NEXT:  movl b@GOTOFF(%eax), %eax
     33 ; X64-LABEL: my_access_global_b:
     34 ; X64:       movl b(%rip), %eax
     35 
     36 entry:
     37   %0 = load i32, i32* @b, align 4
     38   ret i32 %0
     39 }
     40 
     41 ; Internal Linkage
     42 @c = internal global i32 0, align 4
     43 
     44 define i32 @my_access_global_c() #0 {
     45 ; X32-LABEL: my_access_global_c:
     46 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
     47 ; X32-NEXT:  movl c@GOTOFF(%eax), %eax
     48 ; X64-LABEL: my_access_global_c:
     49 ; X64:       movl c(%rip), %eax
     50 
     51 entry:
     52   %0 = load i32, i32* @c, align 4
     53   ret i32 %0
     54 }
     55 
     56 ; External Linkage, only declaration.
     57 @d = external global i32, align 4
     58 
     59 define i32 @my_access_global_load_d() #0 {
     60 ; X32-LABEL: my_access_global_load_d:
     61 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
     62 ; X32-NEXT:  movl d@GOTOFF(%eax), %eax
     63 ; X64-LABEL: my_access_global_load_d:
     64 ; X64:       movl d(%rip), %eax
     65 
     66 entry:
     67   %0 = load i32, i32* @d, align 4
     68   ret i32 %0
     69 }
     70 
     71 ; ExternalWeak Linkage
     72 @e = extern_weak global i32, align 4
     73 
     74 define i32* @my_access_global_d() #0 {
     75 ; X32-LABEL: my_access_global_d:
     76 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
     77 ; X32:       movl e@GOT(%eax), %eax
     78 ; X64-LABEL: my_access_global_d:
     79 ; X64:       movq e@GOTPCREL(%rip), %rax
     80 
     81 entry:
     82   ret i32* @e
     83 }
     84 
     85 ; ExternalWeak hidden Linkage
     86 @he = extern_weak hidden global i32, align 4
     87 
     88 define i32* @my_access_global_he() #0 {
     89 ; X32-LABEL: my_access_global_he:
     90 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
     91 ; X32:       movl he@GOT(%eax), %eax
     92 ; X64-LABEL: my_access_global_he:
     93 ; X64:       movq he@GOTPCREL(%rip), %rax
     94   ret i32* @he
     95 }
     96 
     97 
     98 ; External Linkage, only declaration, store a value.
     99 
    100 define i32 @my_access_global_store_d() #0 {
    101 ; X32-LABEL: my_access_global_store_d:
    102 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
    103 ; X32-NEXT:  movl $2, d@GOTOFF(%eax)
    104 ; X64-LABEL: my_access_global_store_d:
    105 ; X64:  movl $2, d(%rip)
    106 
    107 entry:
    108   store i32 2, i32* @d, align 4
    109   ret i32 0
    110 }
    111 
    112 ; External Linkage, function pointer access.
    113 declare i32 @access_fp(i32 ()*)
    114 declare i32 @foo()
    115 
    116 define i32 @my_access_fp_foo() #0 {
    117 ; X32-LABEL: my_access_fp_foo:
    118 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
    119 ; X32-NEXT:  movl	foo@GOT(%ebx), %eax
    120 ; X64-LABEL: my_access_fp_foo:
    121 ; X64:       movq foo@GOTPCREL(%rip), %rdi
    122 
    123 entry:
    124   %call = call i32 @access_fp(i32 ()* @foo)
    125   ret i32 %call
    126 }
    127 
    128 ; LinkOnceODR Linkage, function pointer access.
    129 
    130 $bar = comdat any
    131 
    132 define linkonce_odr i32 @bar() comdat {
    133 entry:
    134   ret i32 0
    135 }
    136 
    137 define i32 @my_access_fp_bar() #0 {
    138 ; X32-LABEL: my_access_fp_bar:
    139 ; X32:       addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
    140 ; X32-NEXT:  leal	bar@GOTOFF(%ebx), %eax
    141 ; X64-LABEL: my_access_fp_bar:
    142 ; X64:       leaq bar(%rip), %rdi
    143 
    144 entry:
    145   %call = call i32 @access_fp(i32 ()* @bar)
    146   ret i32 %call
    147 }
    148 
    149 !llvm.module.flags = !{!0, !1}
    150 !0 = !{i32 1, !"PIC Level", i32 1}
    151 !1 = !{i32 1, !"PIE Level", i32 1}
    152