1# REQUIRES: riscv
2# RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=riscv32 - -o %t1.o
3# RUN: ld.lld -shared %t1.o -o %t1.so
4
5# RUN: llvm-mc -filetype=obj -triple=riscv32 -position-independent %s -o %t.o
6# RUN: ld.lld %t.o %t1.so -o %t
7# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC32 %s
8# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s
9# RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX32 %s
10# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS32 %s
11
12# RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=riscv64 - -o %t1.o
13# RUN: ld.lld -shared %t1.o -o %t1.so
14
15# RUN: llvm-mc -filetype=obj -triple=riscv64 -position-independent %s -o %t.o
16# RUN: ld.lld %t.o %t1.so -o %t
17# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC64 %s
18# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s
19# RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX64 %s
20# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS64 %s
21
22# SEC: .got PROGBITS 00012060 020060 00000c
23
24# RELOC32:      .rela.dyn {
25# RELOC32-NEXT:   0x12068 R_RISCV_32 b 0x0
26# RELOC32-NEXT: }
27
28# RELOC64:      .rela.dyn {
29# RELOC64-NEXT:   0x120D0 R_RISCV_64 b 0x0
30# RELOC64-NEXT: }
31
32# NM: 00013000 d a
33
34## .got[0] = _DYNAMIC
35## .got[1] = a (filled at link time)
36## .got[2] = 0 (relocated by R_RISCV_64 at runtime)
37# HEX32: section '.got':
38# HEX32: 0x00012060 00200100 00300100 00000000
39
40# HEX64: section '.got':
41# HEX64: 0x000120c0 00200100 00000000 00300100 00000000
42# HEX64: 0x000120d0 00000000 00000000
43
44## &.got[1]-. = 0x12060-0x11000 = 4096*1+100
45# DIS32:      11000: auipc a0, 1
46# DIS32-NEXT:        lw a0, 100(a0)
47## &.got[2]-. = 0x12064-0x11008 = 4096*1+96
48# DIS32:      11008: auipc a0, 1
49# DIS32-NEXT:        lw a0, 96(a0)
50
51## &.got[1]-. = 0x120c8-0x11000 = 4096*1+100
52# DIS64:      11000: auipc a0, 1
53# DIS64-NEXT:        ld a0, 200(a0)
54## &.got[2]-. = 0x120d0-0x11008 = 4096*1+200
55# DIS64:      11008: auipc a0, 1
56# DIS64-NEXT:        ld a0, 200(a0)
57
58la a0,a
59la a0,b
60
61.data
62a:
63## An undefined reference of _GLOBAL_OFFSET_TABLE_ causes .got[0] to be
64## allocated to store _DYNAMIC.
65.long _GLOBAL_OFFSET_TABLE_ - .
66