Skip to content

Commit e003eab

Browse files
committed
[Object][AMDGPU] Support REL relocations
1 parent df7db44 commit e003eab

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

llvm/docs/AMDGPUUsage.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,8 @@ The following relocation types are supported:
27092709
the ``mesa3d`` OS, which does not support ``R_AMDGPU_ABS64``.
27102710

27112711
There is no current OS loader support for 32-bit programs and so
2712-
``R_AMDGPU_ABS32`` is not used.
2712+
``R_AMDGPU_ABS32`` is only generated for static relocations, for example to
2713+
implement some DWARF32 forms.
27132714

27142715
.. _amdgpu-loaded-code-object-path-uniform-resource-identifier:
27152716

llvm/lib/Object/RelocationResolver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ static bool supportsAmdgpu(uint64_t Type) {
274274
}
275275

276276
static uint64_t resolveAmdgpu(uint64_t Type, uint64_t Offset, uint64_t S,
277-
uint64_t /*LocData*/, int64_t Addend) {
277+
uint64_t LocData, int64_t Addend) {
278+
assert((LocData == 0 || Addend == 0) &&
279+
"one of LocData and Addend must be 0");
278280
switch (Type) {
279281
case ELF::R_AMDGPU_ABS32:
280282
case ELF::R_AMDGPU_ABS64:
281-
return S + Addend;
283+
return S + LocData + Addend;
282284
default:
283285
llvm_unreachable("Invalid relocation type");
284286
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: llvm-dwarfdump -i %t | FileCheck %s
3+
4+
# Test REL relocation handling for AMDGPU
5+
6+
# CHECK: DW_TAG_compile_unit
7+
# CHECK: DW_AT_producer ("dxc")
8+
# CHECK: DW_AT_name (".\\example.hlsl")
9+
# CHECK: DW_AT_str_offsets_base (0x00000008)
10+
11+
--- !ELF
12+
FileHeader:
13+
Class: ELFCLASS64
14+
Data: ELFDATA2LSB
15+
OSABI: ELFOSABI_AMDGPU_PAL
16+
Type: ET_REL
17+
Machine: EM_AMDGPU
18+
Flags: [ EF_AMDGPU_MACH_AMDGCN_GFX1201 ]
19+
SectionHeaderStringTable: .strtab
20+
Sections:
21+
- Name: .debug_abbrev
22+
Type: SHT_PROGBITS
23+
AddressAlign: 0x1
24+
Content: 01110125251305032572171017110B120673178C0117000000
25+
- Name: .debug_info
26+
Type: SHT_PROGBITS
27+
AddressAlign: 0x1
28+
Content: 23000000050001080000000001000400010800000000000000005C000000080000000C00000000
29+
- Name: .debug_str_offsets
30+
Type: SHT_PROGBITS
31+
AddressAlign: 0x1
32+
Content: 0C000000050000000000000004000000
33+
- Name: .rel.debug_info
34+
Type: SHT_REL
35+
Flags: [ SHF_INFO_LINK ]
36+
Link: .symtab
37+
AddressAlign: 0x8
38+
Info: .debug_info
39+
Relocations:
40+
- Offset: 0x8
41+
Symbol: .debug_abbrev
42+
Type: R_AMDGPU_ABS32
43+
- Offset: 0x11
44+
Symbol: .debug_str_offsets
45+
Type: R_AMDGPU_ABS32
46+
- Name: .rel.debug_str_offsets
47+
Type: SHT_REL
48+
Flags: [ SHF_INFO_LINK ]
49+
Link: .symtab
50+
AddressAlign: 0x8
51+
Info: .debug_str_offsets
52+
Relocations:
53+
- Offset: 0x8
54+
Symbol: .debug_str
55+
Type: R_AMDGPU_ABS32
56+
- Offset: 0xC
57+
Symbol: .debug_str
58+
Type: R_AMDGPU_ABS32
59+
- Type: SectionHeaderTable
60+
Sections:
61+
- Name: .strtab
62+
- Name: .debug_abbrev
63+
- Name: .debug_info
64+
- Name: .rel.debug_info
65+
- Name: .debug_str_offsets
66+
- Name: .rel.debug_str_offsets
67+
- Name: .debug_str
68+
- Name: .symtab
69+
Symbols:
70+
- Name: .debug_abbrev
71+
Type: STT_SECTION
72+
Section: .debug_abbrev
73+
- Name: .debug_info
74+
Type: STT_SECTION
75+
Section: .debug_info
76+
- Name: .debug_str_offsets
77+
Type: STT_SECTION
78+
Section: .debug_str_offsets
79+
- Name: .debug_str
80+
Type: STT_SECTION
81+
Section: .debug_str
82+
DWARF:
83+
debug_str:
84+
- 'dxc'
85+
- '.\example.hlsl'
86+
...

0 commit comments

Comments
 (0)