blob: ce4d648d48d9a1138f44726ee0bd83a69dca05c0 [file] [log] [blame]
Fangrui Songf01fa402019-07-01 17:12:181# REQUIRES: riscv
2# RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=riscv32 - -o %t1.o
Fangrui Song523f9992019-08-28 12:06:063# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so
Fangrui Songf01fa402019-07-01 17:12:184
5# RUN: llvm-mc -filetype=obj -triple=riscv32 -position-independent %s -o %t.o
6# RUN: ld.lld %t.o %t1.so -o %t
Fangrui Song523f9992019-08-28 12:06:067# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC32 %s
Fangrui Songf01fa402019-07-01 17:12:188# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC32 %s
Fangrui Song523f9992019-08-28 12:06:069# RUN: llvm-nm %t | FileCheck --check-prefix=NM32 %s
Fangrui Songf01fa402019-07-01 17:12:1810# RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX32 %s
11# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS32 %s
12
13# RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=riscv64 - -o %t1.o
Fangrui Song523f9992019-08-28 12:06:0614# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so
Fangrui Songf01fa402019-07-01 17:12:1815
16# RUN: llvm-mc -filetype=obj -triple=riscv64 -position-independent %s -o %t.o
17# RUN: ld.lld %t.o %t1.so -o %t
Fangrui Song523f9992019-08-28 12:06:0618# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC64 %s
Fangrui Songf01fa402019-07-01 17:12:1819# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC64 %s
Fangrui Song523f9992019-08-28 12:06:0620# RUN: llvm-nm %t | FileCheck --check-prefix=NM64 %s
Fangrui Songf01fa402019-07-01 17:12:1821# RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX64 %s
22# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS64 %s
23
Fangrui Song523f9992019-08-28 12:06:0624# SEC32: .got PROGBITS 0001220c 00020c 00000c
25# SEC64: .got PROGBITS 0000000000012358 000358 000018
Fangrui Songf01fa402019-07-01 17:12:1826
27# RELOC32: .rela.dyn {
Fangrui Song523f9992019-08-28 12:06:0628# RELOC32-NEXT: 0x12214 R_RISCV_32 b 0x0
Fangrui Songf01fa402019-07-01 17:12:1829# RELOC32-NEXT: }
30
31# RELOC64: .rela.dyn {
Fangrui Song523f9992019-08-28 12:06:0632# RELOC64-NEXT: 0x12368 R_RISCV_64 b 0x0
Fangrui Songf01fa402019-07-01 17:12:1833# RELOC64-NEXT: }
34
Fangrui Song523f9992019-08-28 12:06:0635# NM32: 00013218 d a
36# NM64: 0000000000013370 d a
Fangrui Songf01fa402019-07-01 17:12:1837
38## .got[0] = _DYNAMIC
39## .got[1] = a (filled at link time)
40## .got[2] = 0 (relocated by R_RISCV_64 at runtime)
41# HEX32: section '.got':
Fangrui Song523f9992019-08-28 12:06:0642# HEX32: 0x0001220c ac210100 18320100 00000000
Fangrui Songf01fa402019-07-01 17:12:1843
44# HEX64: section '.got':
Fangrui Song523f9992019-08-28 12:06:0645# HEX64: 0x00012358 98220100 00000000 70330100 00000000
46# HEX64: 0x00012368 00000000 00000000
Fangrui Songf01fa402019-07-01 17:12:1847
Fangrui Song523f9992019-08-28 12:06:0648## &.got[1]-. = 0x12210-0x1119c = 4096*1+116
49# DIS32: 1119c: auipc a0, 1
50# DIS32-NEXT: lw a0, 116(a0)
51## &.got[2]-. = 0x12214-0x111a4 = 4096*1+112
52# DIS32: 111a4: auipc a0, 1
53# DIS32-NEXT: lw a0, 112(a0)
Fangrui Songf01fa402019-07-01 17:12:1854
Fangrui Song523f9992019-08-28 12:06:0655## &.got[1]-. = 0x12360-0x11288 = 4096*1+216
56# DIS64: 11288: auipc a0, 1
57# DIS64-NEXT: ld a0, 216(a0)
58## &.got[2]-. = 0x12368-0x11290 = 4096*1+216
59# DIS64: 11290: auipc a0, 1
60# DIS64-NEXT: ld a0, 216(a0)
Fangrui Songf01fa402019-07-01 17:12:1861
62la a0,a
63la a0,b
64
65.data
66a:
67## An undefined reference of _GLOBAL_OFFSET_TABLE_ causes .got[0] to be
68## allocated to store _DYNAMIC.
69.long _GLOBAL_OFFSET_TABLE_ - .