Skip to content

Commit 707e970

Browse files
committed
[DWARF][RISCV] Test resolving of RISC-V relocations
Summary: This patch adds an object file (in yaml format) with a synthetic .debug_info section which we use to test that the supported RISC-V relocations are properly resolved. Reviewers: asb, lenary, MaskRay Reviewed By: MaskRay Tags: #llvm Differential Revision: https://reviews.llvm.org/D70541
1 parent f2ba939 commit 707e970

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not 'RISCV' in config.root.targets:
2+
config.unsupported = True
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Tests RISC-V relocations. We provide a .debug_info section with multiple
2+
# DW_AT_high_pc entries (that's one of the attributes for which relocations are
3+
# resolved by llvm-dwarfdump) and we add a relocation for each of them.
4+
#
5+
# RUN: yaml2obj %s | llvm-dwarfdump - | FileCheck %s
6+
7+
# To add more tests you need to modify the Content of the .debug_abbrev and
8+
# .debug_info sections. To do that create a test.s which matches the assembly
9+
# code below, run the command that follows and copy over the "Content" value of
10+
# the respective sections:
11+
#
12+
# ```
13+
# $ cat test.s
14+
# .section .debug_abbrev,"",@progbits
15+
# .byte 1 # Abbreviation Code
16+
# .byte 0x11 # DW_TAG_compile_unit
17+
# .byte 0 # DW_CHILDREN_no
18+
#
19+
# # Add a DW_AT_high_pc for each relocation we test.
20+
# .rept 14 # (UPDATE HERE)
21+
# .byte 0x12 # DW_AT_high_pc
22+
# .byte 0x01 # DW_FORM_addr
23+
# .endr
24+
#
25+
# .byte 0 # EOM(1)
26+
# .byte 0 # EOM(2)
27+
# .byte 0 # EOM(3)
28+
#
29+
# .section .debug_info,"",@progbits
30+
# .4byte 2+4+1+1+8*14 # Length of Unit (UPDATE HERE)
31+
# .2byte 4 # DWARF version number
32+
# .4byte .debug_abbrev # Offset Into Abbrev. Section
33+
# .byte 8 # Address Size (in bytes)
34+
# .byte 1 # Abbrev 1
35+
# .8byte 0x00000000000042 # Test 1
36+
# .8byte 0x00000000000042 # Test 2
37+
# .8byte 0x00000000000042 # Test 3
38+
# .8byte 0x00000000000042 # Test 4
39+
# .8byte 0x00000000000042 # Test 5
40+
# .8byte 0x00000000000042 # Test 6
41+
# .8byte 0x00000000000042 # Test 7
42+
# .8byte 0x00000000000042 # Test 8
43+
# .8byte 0x00000000004242 # Test 9
44+
# .8byte 0x00000000004242 # Test 10
45+
# .8byte 0x00000042424242 # Test 11
46+
# .8byte 0x00000042424242 # Test 12
47+
# .8byte 0x42424242424242 # Test 13
48+
# .8byte 0x42424242424242 # Test 14
49+
# $ llvm-mc test.s -filetype obj -triple riscv64 -o - | obj2yaml
50+
# ```
51+
52+
--- !ELF
53+
FileHeader:
54+
Class: ELFCLASS64
55+
Data: ELFDATA2LSB
56+
Type: ET_REL
57+
Machine: EM_RISCV
58+
Sections:
59+
- Name: .debug_abbrev
60+
Type: SHT_PROGBITS
61+
Content: 01110012011201120112011201120112011201120112011201120112011201000000
62+
- Name: .debug_info
63+
Type: SHT_PROGBITS
64+
Content: 78000000040000000000080142000000000000004200000000000000420000000000000042000000000000004200000000000000420000000000000042000000000000004200000000000000424200000000000042420000000000004242424200000000424242420000000042424242424242004242424242424200
65+
- Name: .rela.debug_info
66+
Type: SHT_RELA
67+
Flags: [ SHF_INFO_LINK ]
68+
Link: .symtab
69+
EntSize: 0x0000000000000018
70+
Info: .debug_info
71+
Relocations:
72+
73+
# Test 1
74+
# 0x42 with R_RISCV_NONE(0x1) = 0x42
75+
# CHECK: DW_AT_high_pc (0x0000000000000042)
76+
- Offset: 0x000000000000000C # 0xC + 8*0
77+
Symbol: v1
78+
Type: R_RISCV_NONE
79+
80+
# Test 2
81+
# 0x42 with R_RISCV_32(0xFFFFFFFFFFFFFFFF) = 0x00000000FFFFFFFF
82+
# CHECK-NEXT: DW_AT_high_pc (0x00000000ffffffff)
83+
- Offset: 0x0000000000000014 # 0xC + 8*1
84+
Symbol: vFFFFFFFFFFFFFFFF
85+
Type: R_RISCV_32
86+
87+
# Test 3
88+
# 0x42 with R_RISCV_32_PCREL(0x4) = 0x4-0x1C = 0x00000000FFFFFFE8
89+
# CHECK-NEXT: DW_AT_high_pc (0x00000000ffffffe8)
90+
- Offset: 0x000000000000001C # 0xC + 8*2
91+
Symbol: v4
92+
Type: R_RISCV_32_PCREL
93+
94+
# Test 4
95+
# 0x42 with R_RISCV_64(0xFFFFFFFFFFFFFFFF) = 0xFFFFFFFFFFFFFFFF
96+
# CHECK-NEXT: DW_AT_high_pc (0xffffffffffffffff)
97+
- Offset: 0x0000000000000024 # 0xC + 8*3
98+
Symbol: vFFFFFFFFFFFFFFFF
99+
Type: R_RISCV_64
100+
101+
# Test 5
102+
# 0x42 with R_RISCV_SET6(1) = 0x41
103+
# CHECK-NEXT: DW_AT_high_pc (0x0000000000000041)
104+
- Offset: 0x000000000000002C # 0xC + 8*4
105+
Symbol: v1
106+
Type: R_RISCV_SET6
107+
108+
# Test 6
109+
# 0x42 with R_RISCV_SUB6(0x4) = 0x7E
110+
# CHECK-NEXT: DW_AT_high_pc (0x000000000000007e)
111+
- Offset: 0x0000000000000034 # 0xC + 8*5
112+
Symbol: v4
113+
Type: R_RISCV_SUB6
114+
115+
# Test 7
116+
# 0x42 with R_RISCV_ADD8(0x04020103) = 0x45
117+
# CHECK-NEXT: DW_AT_high_pc (0x0000000000000045)
118+
- Offset: 0x000000000000003C # 0xC + 8*6
119+
Symbol: v04020103
120+
Type: R_RISCV_ADD8
121+
122+
# Test 8
123+
# 0x42 with R_RISCV_SUB8(0x04020103) = 0x3F
124+
# CHECK-NEXT: DW_AT_high_pc (0x000000000000003f)
125+
- Offset: 0x0000000000000044 # 0xC + 8*7
126+
Symbol: v04020103
127+
Type: R_RISCV_SUB8
128+
129+
# Test 9
130+
# 0x4242 with R_RISCV_ADD16(0x04020103) = 0x4345
131+
# CHECK-NEXT: DW_AT_high_pc (0x0000000000004345)
132+
- Offset: 0x000000000000004C # 0xC + 8*8
133+
Symbol: v04020103
134+
Type: R_RISCV_ADD16
135+
136+
# Test 10
137+
# 0x4242 with R_RISCV_SUB16(0x04020103) = 0x413F
138+
# CHECK-NEXT: DW_AT_high_pc (0x000000000000413f)
139+
- Offset: 0x0000000000000054 # 0xC + 8*9
140+
Symbol: v04020103
141+
Type: R_RISCV_SUB16
142+
143+
# Test 11
144+
# 0x42424242 with R_RISCV_ADD32(0x04020103) = 0x46444345
145+
# CHECK-NEXT: DW_AT_high_pc (0x0000000046444345)
146+
- Offset: 0x000000000000005C # 0xC + 8*10
147+
Symbol: v04020103
148+
Type: R_RISCV_ADD32
149+
150+
# Test 12
151+
# 0x42424242 with R_RISCV_SUB32(0x04020103) = 0x3E40413F
152+
# CHECK-NEXT: DW_AT_high_pc (0x000000003e40413f)
153+
- Offset: 0x0000000000000064 # 0xC + 8*11
154+
Symbol: v04020103
155+
Type: R_RISCV_SUB32
156+
157+
# Test 13
158+
# 0x0042424242424242 with R_RISCV_ADD64(0x0100000000000000) = 0x0142424242424242
159+
# CHECK-NEXT: DW_AT_high_pc (0x0142424242424242)
160+
- Offset: 0x000000000000006C # 0xC + 8*12
161+
Symbol: v0100000000000000
162+
Type: R_RISCV_ADD64
163+
164+
# Test 14
165+
# 0x0042424242424242 with R_RISCV_SUB64(0x0100000000000000) = 0xFF42424242424242
166+
# CHECK-NEXT: DW_AT_high_pc (0xff42424242424242)
167+
- Offset: 0x0000000000000074 # 0xC + 8*13
168+
Symbol: v0100000000000000
169+
Type: R_RISCV_SUB64
170+
171+
Symbols:
172+
- Name: v1
173+
Type: STT_SECTION
174+
Section: .debug_info
175+
Value: 0x0000000000000001
176+
- Name: v4
177+
Type: STT_SECTION
178+
Section: .debug_info
179+
Value: 0x0000000000000004
180+
- Name: v04020103
181+
Type: STT_SECTION
182+
Section: .debug_info
183+
Value: 0x0000000004020103
184+
- Name: vFFFFFFFFFFFFFFFF
185+
Type: STT_SECTION
186+
Section: .debug_info
187+
Value: 0xFFFFFFFFFFFFFFFF
188+
- Name: v0100000000000000
189+
Type: STT_SECTION
190+
Section: .debug_info
191+
Value: 0x0100000000000000
192+
...

0 commit comments

Comments
 (0)