| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| ; RUN: llc -mtriple=armv7-linux-gnueabi -relocation-model=static < %s \ |
| ; RUN: | FileCheck %s --check-prefix=STATIC |
| ; RUN: llc -mtriple=armv7-linux-gnueabi -relocation-model=pic < %s \ |
| ; RUN: | FileCheck %s --check-prefix=PIC |
| |
| @preemptable_var = dso_preemptable global i32 42 |
| define ptr @get_preemptable_var() nounwind { |
| ; STATIC-LABEL: get_preemptable_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:preemptable_var |
| ; STATIC-NEXT: movt r0, :upper16:preemptable_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_preemptable_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI0_0 |
| ; PIC-NEXT: .LPC0_0: |
| ; PIC-NEXT: ldr r0, [pc, r0] |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI0_0: |
| ; PIC-NEXT: .Ltmp0: |
| ; PIC-NEXT: .long preemptable_var(GOT_PREL)-(.LPC0_0+8-.Ltmp0) |
| ret ptr @preemptable_var |
| } |
| |
| @dsolocal_var = dso_local global i32 42 |
| define ptr @get_dsolocal_var() nounwind { |
| ; STATIC-LABEL: get_dsolocal_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:dsolocal_var |
| ; STATIC-NEXT: movt r0, :upper16:dsolocal_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_dsolocal_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI1_0 |
| ; PIC-NEXT: .LPC1_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI1_0: |
| ; PIC-NEXT: .long .Ldsolocal_var$local-(.LPC1_0+8) |
| ret ptr @dsolocal_var |
| } |
| |
| @weak_dsolocal_var = weak dso_local global i32 42 |
| define ptr @get_weak_dsolocal_var() nounwind { |
| ; STATIC-LABEL: get_weak_dsolocal_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:weak_dsolocal_var |
| ; STATIC-NEXT: movt r0, :upper16:weak_dsolocal_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_weak_dsolocal_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI2_0 |
| ; PIC-NEXT: .LPC2_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI2_0: |
| ; PIC-NEXT: .Ltmp1: |
| ; PIC-NEXT: .long .Ltmp1-(.LPC2_0+8) |
| ; PIC-NEXT: .reloc .Ltmp1, R_ARM_REL32, weak_dsolocal_var |
| ret ptr @weak_dsolocal_var |
| } |
| |
| @hidden_var = hidden global i32 42 |
| define ptr @get_hidden_var() nounwind { |
| ; STATIC-LABEL: get_hidden_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:hidden_var |
| ; STATIC-NEXT: movt r0, :upper16:hidden_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_hidden_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI3_0 |
| ; PIC-NEXT: .LPC3_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI3_0: |
| ; PIC-NEXT: .long hidden_var-(.LPC3_0+8) |
| ret ptr @hidden_var |
| } |
| |
| @protected_var = protected global i32 42 |
| define ptr @get_protected_var() nounwind { |
| ; STATIC-LABEL: get_protected_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:protected_var |
| ; STATIC-NEXT: movt r0, :upper16:protected_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_protected_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI4_0 |
| ; PIC-NEXT: .LPC4_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI4_0: |
| ; PIC-NEXT: .long protected_var-(.LPC4_0+8) |
| ret ptr @protected_var |
| } |
| |
| define dso_preemptable ptr @preemptable_func() nounwind { |
| ; STATIC-LABEL: preemptable_func: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:preemptable_func |
| ; STATIC-NEXT: movt r0, :upper16:preemptable_func |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: preemptable_func: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI5_0 |
| ; PIC-NEXT: .LPC5_0: |
| ; PIC-NEXT: ldr r0, [pc, r0] |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI5_0: |
| ; PIC-NEXT: .Ltmp2: |
| ; PIC-NEXT: .long preemptable_func(GOT_PREL)-(.LPC5_0+8-.Ltmp2) |
| ret ptr @preemptable_func |
| } |
| |
| define dso_local ptr @dsolocal_func() nounwind { |
| ; STATIC-LABEL: dsolocal_func: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:dsolocal_func |
| ; STATIC-NEXT: movt r0, :upper16:dsolocal_func |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: dsolocal_func: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI6_0 |
| ; PIC-NEXT: .LPC6_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI6_0: |
| ; PIC-NEXT: .long .Ldsolocal_func$local-(.LPC6_0+8) |
| ret ptr @dsolocal_func |
| } |
| |
| define weak dso_local ptr @weak_dsolocal_func() nounwind { |
| ; STATIC-LABEL: weak_dsolocal_func: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:weak_dsolocal_func |
| ; STATIC-NEXT: movt r0, :upper16:weak_dsolocal_func |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: weak_dsolocal_func: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI7_0 |
| ; PIC-NEXT: .LPC7_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI7_0: |
| ; PIC-NEXT: .Ltmp3: |
| ; PIC-NEXT: .long .Ltmp3-(.LPC7_0+8) |
| ; PIC-NEXT: .reloc .Ltmp3, R_ARM_REL32, weak_dsolocal_func |
| ret ptr @weak_dsolocal_func |
| } |
| |
| ;; call .Ldsolocal_func$local either resolves to a constant at assembly time |
| ;; or produces a relocation referencing a non-preemptible local symbol. |
| define dso_local void @call_dsolocal_func() nounwind { |
| ; STATIC-LABEL: call_dsolocal_func: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: .save {r11, lr} |
| ; STATIC-NEXT: push {r11, lr} |
| ; STATIC-NEXT: bl dsolocal_func |
| ; STATIC-NEXT: pop {r11, pc} |
| ; |
| ; PIC-LABEL: call_dsolocal_func: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: .save {r11, lr} |
| ; PIC-NEXT: push {r11, lr} |
| ; PIC-NEXT: bl .Ldsolocal_func$local |
| ; PIC-NEXT: pop {r11, pc} |
| call ptr @dsolocal_func() |
| ret void |
| } |
| |
| ;; extern_weak (undefined) symbols are external/preemptible and must go through |
| ;; the GOT in PIC mode. R_ARM_REL32 against an external or undefined symbol |
| ;; cannot be used when making a shared object, so the .reloc path must not |
| ;; apply to them. |
| @extern_weak_var = extern_weak global i32 |
| define ptr @get_extern_weak_var() nounwind { |
| ; STATIC-LABEL: get_extern_weak_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:extern_weak_var |
| ; STATIC-NEXT: movt r0, :upper16:extern_weak_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_extern_weak_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI9_0 |
| ; PIC-NEXT: .LPC9_0: |
| ; PIC-NEXT: ldr r0, [pc, r0] |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI9_0: |
| ; PIC-NEXT: .Ltmp4: |
| ; PIC-NEXT: .long extern_weak_var(GOT_PREL)-(.LPC9_0+8-.Ltmp4) |
| ret ptr @extern_weak_var |
| } |
| |
| declare extern_weak ptr @extern_weak_func() |
| define ptr @get_extern_weak_func() nounwind { |
| ; STATIC-LABEL: get_extern_weak_func: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:extern_weak_func |
| ; STATIC-NEXT: movt r0, :upper16:extern_weak_func |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_extern_weak_func: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI10_0 |
| ; PIC-NEXT: .LPC10_0: |
| ; PIC-NEXT: ldr r0, [pc, r0] |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI10_0: |
| ; PIC-NEXT: .Ltmp5: |
| ; PIC-NEXT: .long extern_weak_func(GOT_PREL)-(.LPC10_0+8-.Ltmp5) |
| ret ptr @extern_weak_func |
| } |
| |
| ;; An undefined weak reference with hidden visibility (e.g. from |
| ;; `[[gnu::weak, gnu::visibility("hidden")]] extern int foo;`) is still not |
| ;; dso_local, so it must go through the GOT: the compiler cannot know whether |
| ;; it will be defined or undefined at link time, and an undefined weak has to |
| ;; materialize as 0, which only the GOT can produce (R_ARM_REL32 cannot). |
| @extern_weak_hidden_var = extern_weak hidden global i32 |
| define ptr @get_extern_weak_hidden_var() nounwind { |
| ; STATIC-LABEL: get_extern_weak_hidden_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:extern_weak_hidden_var |
| ; STATIC-NEXT: movt r0, :upper16:extern_weak_hidden_var |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_extern_weak_hidden_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI11_0 |
| ; PIC-NEXT: .LPC11_0: |
| ; PIC-NEXT: ldr r0, [pc, r0] |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI11_0: |
| ; PIC-NEXT: .Ltmp6: |
| ; PIC-NEXT: .long extern_weak_hidden_var(GOT_PREL)-(.LPC11_0+8-.Ltmp6) |
| ret ptr @extern_weak_hidden_var |
| } |
| |
| declare extern_weak hidden ptr @extern_weak_hidden_func() |
| define ptr @get_extern_weak_hidden_func() nounwind { |
| ; STATIC-LABEL: get_extern_weak_hidden_func: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: movw r0, :lower16:extern_weak_hidden_func |
| ; STATIC-NEXT: movt r0, :upper16:extern_weak_hidden_func |
| ; STATIC-NEXT: bx lr |
| ; |
| ; PIC-LABEL: get_extern_weak_hidden_func: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: ldr r0, .LCPI12_0 |
| ; PIC-NEXT: .LPC12_0: |
| ; PIC-NEXT: ldr r0, [pc, r0] |
| ; PIC-NEXT: bx lr |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI12_0: |
| ; PIC-NEXT: .Ltmp7: |
| ; PIC-NEXT: .long extern_weak_hidden_func(GOT_PREL)-(.LPC12_0+8-.Ltmp7) |
| ret ptr @extern_weak_hidden_func |
| } |
| |
| ;; TLS weak symbols must not use the .reloc/R_ARM_REL32 path; they require |
| ;; TLS-specific relocations (R_ARM_TLS_GD32 etc.), not R_ARM_REL32. Using |
| ;; R_ARM_REL32 for a TLS symbol produces a wrong address and crashes at runtime. |
| @tls_weak_var = weak dso_local thread_local global i32 42 |
| define ptr @get_tls_weak_var() nounwind { |
| ; STATIC-LABEL: get_tls_weak_var: |
| ; STATIC: @ %bb.0: |
| ; STATIC-NEXT: .save {r11, lr} |
| ; STATIC-NEXT: push {r11, lr} |
| ; STATIC-NEXT: ldr r1, .LCPI13_0 |
| ; STATIC-NEXT: bl __aeabi_read_tp |
| ; STATIC-NEXT: add r0, r0, r1 |
| ; STATIC-NEXT: pop {r11, pc} |
| ; STATIC-NEXT: .p2align 2 |
| ; STATIC-NEXT: @ %bb.1: |
| ; STATIC-NEXT: .LCPI13_0: |
| ; STATIC-NEXT: .long tls_weak_var(TPOFF) |
| ; |
| ; PIC-LABEL: get_tls_weak_var: |
| ; PIC: @ %bb.0: |
| ; PIC-NEXT: .save {r11, lr} |
| ; PIC-NEXT: push {r11, lr} |
| ; PIC-NEXT: ldr r0, .LCPI13_0 |
| ; PIC-NEXT: .LPC13_0: |
| ; PIC-NEXT: add r0, pc, r0 |
| ; PIC-NEXT: bl __tls_get_addr |
| ; PIC-NEXT: pop {r11, pc} |
| ; PIC-NEXT: .p2align 2 |
| ; PIC-NEXT: @ %bb.1: |
| ; PIC-NEXT: .LCPI13_0: |
| ; PIC-NEXT: .Ltmp8: |
| ; PIC-NEXT: .long tls_weak_var(TLSGD)-(.LPC13_0+8-.Ltmp8) |
| ret ptr @tls_weak_var |
| } |