1# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+relax < %s \ 2# RUN: | llvm-readobj -r - | FileCheck -check-prefix=RELAX-RELOC %s 3# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax < %s \ 4# RUN: | llvm-readobj -r - | FileCheck -check-prefix=NORELAX-RELOC %s 5# RUN: llvm-mc -triple riscv32 -mattr=+relax < %s -show-encoding \ 6# RUN: | FileCheck -check-prefix=RELAX-FIXUP %s 7# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+relax < %s \ 8# RUN: | llvm-readobj -r - | FileCheck -check-prefix=RELAX-RELOC %s 9# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=-relax < %s \ 10# RUN: | llvm-readobj -r - | FileCheck -check-prefix=NORELAX-RELOC %s 11# RUN: llvm-mc -triple riscv64 -mattr=+relax < %s -show-encoding \ 12# RUN: | FileCheck -check-prefix=RELAX-FIXUP %s 13 14.long foo 15 16call foo 17# NORELAX-RELOC: R_RISCV_CALL_PLT foo 0x0 18# NORELAX-RELOC-NOT: R_RISCV_RELAX 19# RELAX-RELOC: R_RISCV_CALL_PLT foo 0x0 20# RELAX-RELOC: R_RISCV_RELAX - 0x0 21# RELAX-FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_call 22# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 23 24lui t1, %hi(foo) 25# NORELAX-RELOC: R_RISCV_HI20 foo 0x0 26# NORELAX-RELOC-NOT: R_RISCV_RELAX 27# RELAX-RELOC: R_RISCV_HI20 foo 0x0 28# RELAX-RELOC: R_RISCV_RELAX - 0x0 29# RELAX-FIXUP: fixup A - offset: 0, value: %hi(foo), kind: fixup_riscv_hi20 30# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 31 32addi t1, t1, %lo(foo) 33# NORELAX-RELOC: R_RISCV_LO12_I foo 0x0 34# NORELAX-RELOC-NOT: R_RISCV_RELAX 35# RELAX-RELOC: R_RISCV_LO12_I foo 0x0 36# RELAX-RELOC: R_RISCV_RELAX - 0x0 37# RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_i 38# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 39 40sb t1, %lo(foo)(a2) 41# NORELAX-RELOC: R_RISCV_LO12_S foo 0x0 42# NORELAX-RELOC-NOT: R_RISCV_RELAX 43# RELAX-RELOC: R_RISCV_LO12_S foo 0x0 44# RELAX-RELOC: R_RISCV_RELAX - 0x0 45# RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_s 46# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 47 481: 49auipc t1, %pcrel_hi(foo) 50# NORELAX-RELOC: R_RISCV_PCREL_HI20 foo 0x0 51# NORELAX-RELOC-NOT: R_RISCV_RELAX 52# RELAX-RELOC: R_RISCV_PCREL_HI20 foo 0x0 53# RELAX-RELOC: R_RISCV_RELAX - 0x0 54# RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo), kind: fixup_riscv_pcrel_hi20 55# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 56 57addi t1, t1, %pcrel_lo(1b) 58# NORELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0 59# NORELAX-RELOC-NOT: R_RISCV_RELAX 60# RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0 61# RELAX-RELOC: R_RISCV_RELAX - 0x0 62# RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_i 63# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 64 65sb t1, %pcrel_lo(1b)(a2) 66# NORELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0 67# NORELAX-RELOC-NOT: R_RISCV_RELAX 68# RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0 69# RELAX-RELOC: R_RISCV_RELAX - 0x0 70# RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_s 71# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 72 73 74# Check behaviour when a locally defined symbol is referenced. 75bar: 76 77beq s1, s1, bar 78# NORELAX-RELOC-NOT: R_RISCV_BRANCH 79# RELAX-RELOC: R_RISCV_BRANCH bar 0x0 80# RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_branch 81# RELAX-FIXUP-NOT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 82 83call bar 84# NORELAX-RELOC-NOT: R_RISCV_CALL 85# NORELAX-RELOC-NOT: R_RISCV_RELAX 86# RELAX-RELOC: R_RISCV_CALL_PLT bar 0x0 87# RELAX-RELOC: R_RISCV_RELAX - 0x0 88# RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_call 89# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 90 91lui t1, %hi(bar) 92# NORELAX-RELOC: R_RISCV_HI20 bar 0x0 93# NORELAX-RELOC-NOT: R_RISCV_RELAX 94# RELAX-RELOC: R_RISCV_HI20 bar 0x0 95# RELAX-RELOC: R_RISCV_RELAX - 0x0 96# RELAX-FIXUP: fixup A - offset: 0, value: %hi(bar), kind: fixup_riscv_hi20 97# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 98 99addi t1, t1, %lo(bar) 100# NORELAX-RELOC: R_RISCV_LO12_I bar 0x0 101# NORELAX-RELOC-NOT: R_RISCV_RELAX 102# RELAX-RELOC: R_RISCV_LO12_I bar 0x0 103# RELAX-RELOC: R_RISCV_RELAX - 0x0 104# RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_i 105# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 106 107sb t1, %lo(bar)(a2) 108# NORELAX-RELOC: R_RISCV_LO12_S bar 0x0 109# NORELAX-RELOC-NOT: R_RISCV_RELAX 110# RELAX-RELOC: R_RISCV_LO12_S bar 0x0 111# RELAX-RELOC: R_RISCV_RELAX - 0x0 112# RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_s 113# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 114 1152: 116auipc t1, %pcrel_hi(bar) 117# NORELAX-RELOC-NOT: R_RISCV_PCREL_HI20 118# NORELAX-RELOC-NOT: R_RISCV_RELAX 119# RELAX-RELOC: R_RISCV_PCREL_HI20 bar 0x0 120# RELAX-RELOC: R_RISCV_RELAX - 0x0 121# RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(bar), kind: fixup_riscv_pcrel_hi20 122# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 123 124addi t1, t1, %pcrel_lo(2b) 125# NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_I 126# NORELAX-RELOC-NOT: R_RISCV_RELAX 127# RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp1 0x0 128# RELAX-RELOC: R_RISCV_RELAX - 0x0 129# RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_i 130# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 131 132sb t1, %pcrel_lo(2b)(a2) 133# NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_S 134# NORELAX-RELOC-NOT: R_RISCV_RELAX 135# RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp1 0x0 136# RELAX-RELOC: R_RISCV_RELAX - 0x0 137# RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_s 138# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax 139 140# Check that a relocation is not emitted for a symbol difference which has 141# been folded to a fixup with an absolute value. This can happen when a 142# difference expression refers to two symbols, at least one of which is 143# not defined at the point it is referenced. Then during *assembler* 144# relaxation when both symbols have become defined the difference may be folded 145# down to a fixup simply containing the absolute value. We want to ensure that 146# we don't force a relocation to be emitted for this absolute value even 147# when linker relaxation is enabled. The reason for this is that one instance 148# where this pattern appears in in the .eh_frame section (the CIE 'length' 149# field), and the .eh_frame section cannot be parsed by the linker unless the 150# fixup has been resolved to a concrete value instead of a relocation. 151 .data 152lo: 153 .word hi-lo 154 .quad hi-lo 155# NORELAX-RELOC-NOT: R_RISCV_32 156# NORELAX-RELOC-NOT: R_RISCV_64 157# RELAX-RELOC-NOT: R_RISCV_32 158# RELAX-RELOC-NOT: R_RISCV_64 159hi: 160