Home | History | Annotate | Download | only in AArch64
      1 ; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs -relocation-model=pic %s -o - | FileCheck %s
      2 ; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs -relocation-model=pic -filetype=obj %s -o -| llvm-objdump -r - | FileCheck --check-prefix=CHECK-ELF %s
      3 
      4 @var = global i32 0
      5 
      6 ; CHECK-ELF: RELOCATION RECORDS FOR [.rela.text]
      7 
      8 define i32 @get_globalvar() {
      9 ; CHECK-LABEL: get_globalvar:
     10 
     11   %val = load i32* @var
     12 ; CHECK: adrp x[[GOTHI:[0-9]+]], :got:var
     13 ; CHECK: ldr x[[GOTLOC:[0-9]+]], [x[[GOTHI]], #:got_lo12:var]
     14 ; CHECK: ldr w0, [x[[GOTLOC]]]
     15 
     16 ; CHECK-ELF: R_AARCH64_ADR_GOT_PAGE var
     17 ; CHECK-ELF: R_AARCH64_LD64_GOT_LO12_NC var
     18   ret i32 %val
     19 }
     20 
     21 define i32* @get_globalvaraddr() {
     22 ; CHECK-LABEL: get_globalvaraddr:
     23 
     24   %val = load i32* @var
     25 ; CHECK: adrp x[[GOTHI:[0-9]+]], :got:var
     26 ; CHECK: ldr x0, [x[[GOTHI]], #:got_lo12:var]
     27 
     28 ; CHECK-ELF: R_AARCH64_ADR_GOT_PAGE var
     29 ; CHECK-ELF: R_AARCH64_LD64_GOT_LO12_NC var
     30   ret i32* @var
     31 }
     32 
     33 @hiddenvar = hidden global i32 0
     34 
     35 define i32 @get_hiddenvar() {
     36 ; CHECK-LABEL: get_hiddenvar:
     37 
     38   %val = load i32* @hiddenvar
     39 ; CHECK: adrp x[[HI:[0-9]+]], hiddenvar
     40 ; CHECK: ldr w0, [x[[HI]], #:lo12:hiddenvar]
     41 
     42 ; CHECK-ELF: R_AARCH64_ADR_PREL_PG_HI21 hiddenvar
     43 ; CHECK-ELF: R_AARCH64_LDST32_ABS_LO12_NC hiddenvar
     44   ret i32 %val
     45 }
     46 
     47 define i32* @get_hiddenvaraddr() {
     48 ; CHECK-LABEL: get_hiddenvaraddr:
     49 
     50   %val = load i32* @hiddenvar
     51 ; CHECK: adrp [[HI:x[0-9]+]], hiddenvar
     52 ; CHECK: add x0, [[HI]], #:lo12:hiddenvar
     53 
     54 ; CHECK-ELF: R_AARCH64_ADR_PREL_PG_HI21 hiddenvar
     55 ; CHECK-ELF: R_AARCH64_ADD_ABS_LO12_NC hiddenvar
     56   ret i32* @hiddenvar
     57 }
     58 
     59 define void()* @get_func() {
     60 ; CHECK-LABEL: get_func:
     61 
     62   ret void()* bitcast(void()*()* @get_func to void()*)
     63 ; CHECK: adrp x[[GOTHI:[0-9]+]], :got:get_func
     64 ; CHECK: ldr x0, [x[[GOTHI]], #:got_lo12:get_func]
     65 
     66   ; Particularly important that the ADRP gets a relocation, LLVM tends to think
     67   ; it can relax it because it knows where get_func is. It can't!
     68 ; CHECK-ELF: R_AARCH64_ADR_GOT_PAGE get_func
     69 ; CHECK-ELF: R_AARCH64_LD64_GOT_LO12_NC get_func
     70 }
     71