| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | . $(dirnamescip-shell system . . dirname. $0)/common.inc |
| 3 | |
| 4 | catscip-shell system . . cat. <<EOF | $CC -o $t/a.o -c -xassembler - |
| 5 | .globl get_sym1, get_sym2, get_sym3, get_sym4, get_sym5 |
| 6 | .option norvc |
| 7 | get_sym1: |
| 8 | .reloc ., R_RISCV_GOT_HI20, sym1 |
| 9 | .reloc ., R_RISCV_RELAX |
| 10 | auipc a0, 0 |
| 11 | .reloc ., R_RISCV_PCREL_LO12_I, get_sym1 |
| 12 | .reloc ., R_RISCV_RELAX |
| 13 | ld a0, 0(a0) |
| 14 | ret |
| 15 | get_sym2: |
| 16 | .reloc ., R_RISCV_GOT_HI20, sym2 |
| 17 | .reloc ., R_RISCV_RELAX |
| 18 | auipc a0, 0 |
| 19 | .reloc ., R_RISCV_PCREL_LO12_I, get_sym2 |
| 20 | .reloc ., R_RISCV_RELAX |
| 21 | ld a0, 0(a0) |
| 22 | ret |
| 23 | get_sym3: |
| 24 | .reloc ., R_RISCV_GOT_HI20, sym3 |
| 25 | .reloc ., R_RISCV_RELAX |
| 26 | auipc a0, 0 |
| 27 | .reloc ., R_RISCV_PCREL_LO12_I, get_sym3 |
| 28 | .reloc ., R_RISCV_RELAX |
| 29 | ld a0, 0(a0) |
| 30 | ret |
| 31 | get_sym4: |
| 32 | .reloc ., R_RISCV_GOT_HI20, sym4 |
| 33 | .reloc ., R_RISCV_RELAX |
| 34 | auipc a0, 0 |
| 35 | .reloc ., R_RISCV_PCREL_LO12_I, get_sym4 |
| 36 | .reloc ., R_RISCV_RELAX |
| 37 | ld a0, 0(a0) |
| 38 | ret |
| 39 | get_sym5: |
| 40 | .reloc ., R_RISCV_GOT_HI20, sym5 |
| 41 | .reloc ., R_RISCV_RELAX |
| 42 | auipc a0, 0 |
| 43 | .reloc ., R_RISCV_PCREL_LO12_I, get_sym5 |
| 44 | .reloc ., R_RISCV_RELAX |
| 45 | ld a0, 0(a0) |
| 46 | ret |
| 47 | EOF |
| 48 | |
| 49 | catscip-shell system . . cat. <<EOF | $CC -o $t/b.o -c -xassembler - |
| 50 | .globl sym1, sym2, sym3, sym4, sym5 |
| 51 | sym1 = 0x0 |
| 52 | sym2 = 0xba |
| 53 | sym3 = 0xbeef |
| 54 | sym4 = 0x11beef |
| 55 | sym5 = 0xdeadbeef |
| 56 | EOF |
| 57 | |
| 58 | catscip-shell system . . cat. <<EOF | $CC -o $t/c.o -c -xc - |
| 59 | #include <stdio.h> |
| 60 | |
| 61 | int get_sym1(); |
| 62 | int get_sym2(); |
| 63 | int get_sym3(); |
| 64 | int get_sym4(); |
| 65 | int get_sym5(); |
| 66 | |
| 67 | int main() { |
| 68 | printf("%x %x %x %x %x\n", |
| 69 | get_sym1(), get_sym2(), get_sym3(), get_sym4(), get_sym5()); |
| 70 | } |
| 71 | EOF |
| 72 | |
| 73 | $CC -B. -o $t/exe1 $t/a.o $t/b.o $t/c.o -Wl,--no-relax |
| 74 | $QEMU $t/exe1 | grepscip-shell system . . grep. -E '^0 ba beef 11beef deadbeef$' |
| 75 | |
| 76 | $CC -B. -o $t/exe2 $t/a.o $t/b.o $t/c.o |
| 77 | $QEMU $t/exe2 | grepscip-shell system . . grep. -E '^0 ba beef 11beef deadbeef$' |
| 78 | |
| 79 | $OBJDUMP -d $t/exe2 | grepscip-shell system . . grep. -A2 '<get_sym2>:' | grepscip-shell system . . grep. -E $'li[ \t]+a0,186$' |