Skip to content

Commit 82b4368

Browse files
committed
[llvm-readobj] Print <null> for relocation target with an empty name
For a relocation, we don't differentiate the two cases: * the symbol index is 0 * the symbol index is non zero, the type is not STT_SECTION, and the name is empty. Clang generates such local symbols for RISC-V linker relaxation. So we may print ``` Offset Info Type Symbol's Value Symbol's Name + Addend 000000000000001c 0000000100000039 R_RISCV_32_PCREL 0000000000000000 0 // llvm-readobj 0x1C R_RISCV_32_PCREL - 0x0 ``` while GNU readelf prints "<null>", which is clearer. Let's match the GNU behavior. Related to https://reviews.llvm.org/D81842 ``` 000000000000001c 0000000100000039 R_RISCV_32_PCREL 0000000000000000 <null> + 0 // llvm-readobj 0x1C R_RISCV_32_PCREL <null> 0x0 ``` Reviewed By: jhenderson, kito-cheng Differential Revision: https://reviews.llvm.org/D155353
1 parent 7cbcc59 commit 82b4368

File tree

11 files changed

+66
-61
lines changed

11 files changed

+66
-61
lines changed

lld/test/ELF/mips-eh_frame-pic.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
# RELOCS: .rel{{a?}}.eh_frame {
3737
# ABS32-RELOCS-NEXT: 0x1C R_MIPS_32 .text
3838
# ABS64-RELOCS-NEXT: 0x1C R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE .text
39-
# PIC64-RELOCS-NEXT: 0x1C R_MIPS_PC32/R_MIPS_NONE/R_MIPS_NONE -
40-
# PIC32-RELOCS-NEXT: 0x1C R_MIPS_PC32 -
39+
# PIC64-RELOCS-NEXT: 0x1C R_MIPS_PC32/R_MIPS_NONE/R_MIPS_NONE <null>
40+
# PIC32-RELOCS-NEXT: 0x1C R_MIPS_PC32 <null>
4141
# RELOCS-NEXT: }
4242

4343
# ABS64-EH-FRAME: Augmentation data: 0C

llvm/test/CodeGen/RISCV/fixups-diff.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ entry:
2323
}
2424

2525
; CHECK: Section {{.*}} .rela.debug_info {
26-
; CHECK: 0x22 R_RISCV_ADD32 - 0x0
27-
; CHECK-NEXT: 0x22 R_RISCV_SUB32 - 0x0
28-
; CHECK: 0x2B R_RISCV_ADD32 - 0x0
29-
; CHECK-NEXT: 0x2B R_RISCV_SUB32 - 0x0
26+
; CHECK: 0x22 R_RISCV_ADD32 <null> 0x0
27+
; CHECK-NEXT: 0x22 R_RISCV_SUB32 <null> 0x0
28+
; CHECK: 0x2B R_RISCV_ADD32 <null> 0x0
29+
; CHECK-NEXT: 0x2B R_RISCV_SUB32 <null> 0x0
3030
; CHECK: }
3131

3232
; CHECK: Section {{.*}} .rela.eh_frame {
33-
; CHECK: 0x1C R_RISCV_32_PCREL - 0x0
34-
; CHECK: 0x20 R_RISCV_ADD32 - 0x0
35-
; CHECK-NEXT: 0x20 R_RISCV_SUB32 - 0x0
33+
; CHECK: 0x1C R_RISCV_32_PCREL <null> 0x0
34+
; CHECK: 0x20 R_RISCV_ADD32 <null> 0x0
35+
; CHECK-NEXT: 0x20 R_RISCV_SUB32 <null> 0x0
3636
; CHECK: }
3737

3838
!llvm.dbg.cu = !{!0}

llvm/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
; Check that we actually have relocations, otherwise this is kind of pointless.
88
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_info {
9-
; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 - 0x0
10-
; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 - 0x0
9+
; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 <null> 0x0
10+
; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 <null> 0x0
1111
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_frame {
12-
; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 - 0x0
13-
; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 - 0x0
12+
; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 <null> 0x0
13+
; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 <null> 0x0
1414
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_line {
15-
; READOBJ-RELOCS: 0x5A R_RISCV_ADD16 - 0x0
16-
; READOBJ-RELOCS-NEXT: 0x5A R_RISCV_SUB16 - 0x0
15+
; READOBJ-RELOCS: 0x5A R_RISCV_ADD16 <null> 0x0
16+
; READOBJ-RELOCS-NEXT: 0x5A R_RISCV_SUB16 <null> 0x0
1717

1818
; Check that we can print the source, even with relocations.
1919
; OBJDUMP-SOURCE: Disassembly of section .text:

llvm/test/DebugInfo/RISCV/relax-debug-frame.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
; RUN: | FileCheck -check-prefix=RELAX-DWARFDUMP %s
55
;
66
; RELAX: Section ({{.*}}) .rela.eh_frame {
7-
; RELAX-NEXT: 0x1C R_RISCV_32_PCREL - 0x0
8-
; RELAX-NEXT: 0x20 R_RISCV_ADD32 - 0x0
9-
; RELAX-NEXT: 0x20 R_RISCV_SUB32 - 0x0
10-
; RELAX-NEXT: 0x30 R_RISCV_32_PCREL - 0x0
11-
; RELAX-NEXT: 0x34 R_RISCV_ADD32 - 0x0
12-
; RELAX-NEXT: 0x34 R_RISCV_SUB32 - 0x0
13-
; RELAX-NEXT: 0x44 R_RISCV_32_PCREL - 0x0
14-
; RELAX-NEXT: 0x48 R_RISCV_ADD32 - 0x0
15-
; RELAX-NEXT: 0x48 R_RISCV_SUB32 - 0x0
7+
; RELAX-NEXT: 0x1C R_RISCV_32_PCREL <null> 0x0
8+
; RELAX-NEXT: 0x20 R_RISCV_ADD32 <null> 0x0
9+
; RELAX-NEXT: 0x20 R_RISCV_SUB32 <null> 0x0
10+
; RELAX-NEXT: 0x30 R_RISCV_32_PCREL <null> 0x0
11+
; RELAX-NEXT: 0x34 R_RISCV_ADD32 <null> 0x0
12+
; RELAX-NEXT: 0x34 R_RISCV_SUB32 <null> 0x0
13+
; RELAX-NEXT: 0x44 R_RISCV_32_PCREL <null> 0x0
14+
; RELAX-NEXT: 0x48 R_RISCV_ADD32 <null> 0x0
15+
; RELAX-NEXT: 0x48 R_RISCV_SUB32 <null> 0x0
1616
; RELAX-NEXT: }
1717

1818
; RELAX-DWARFDUMP-NOT: error: failed to compute relocation

llvm/test/MC/ELF/RISCV/gen-dwarf.s

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
# CHECK-NEXT: 0x00000020: [DW_RLE_end_of_list ]
4141

4242
# RELOC: Section ([[#]]) .rela.eh_frame {
43-
# RELOC-NEXT: 0x1C R_RISCV_32_PCREL - 0x0
44-
# RELOC-NEXT: 0x20 R_RISCV_ADD32 - 0x0
45-
# RELOC-NEXT: 0x20 R_RISCV_SUB32 - 0x0
46-
# RELOC-NEXT: 0x25 R_RISCV_SET6 - 0x0
47-
# RELOC-NEXT: 0x25 R_RISCV_SUB6 - 0x0
48-
# RELOC-NEXT: 0x34 R_RISCV_32_PCREL - 0x0
49-
# RELOC-NEXT: 0x38 R_RISCV_ADD32 - 0x0
50-
# RELOC-NEXT: 0x38 R_RISCV_SUB32 - 0x0
43+
# RELOC-NEXT: 0x1C R_RISCV_32_PCREL <null> 0x0
44+
# RELOC-NEXT: 0x20 R_RISCV_ADD32 <null> 0x0
45+
# RELOC-NEXT: 0x20 R_RISCV_SUB32 <null> 0x0
46+
# RELOC-NEXT: 0x25 R_RISCV_SET6 <null> 0x0
47+
# RELOC-NEXT: 0x25 R_RISCV_SUB6 <null> 0x0
48+
# RELOC-NEXT: 0x34 R_RISCV_32_PCREL <null> 0x0
49+
# RELOC-NEXT: 0x38 R_RISCV_ADD32 <null> 0x0
50+
# RELOC-NEXT: 0x38 R_RISCV_SUB32 <null> 0x0
5151
# RELOC-NEXT: }
5252

5353
## TODO A section needs two relocations.
@@ -57,12 +57,12 @@
5757
# RELOC-NEXT: }
5858

5959
# RELOC: Section ([[#]]) .rela.debug_line {
60-
# RELOC: R_RISCV_ADD16 - 0x0
61-
# RELOC-NEXT: R_RISCV_SUB16 - 0x0
62-
# RELOC-NEXT: R_RISCV_ADD16 - 0x0
63-
# RELOC-NEXT: R_RISCV_SUB16 - 0x0
64-
# RELOC-NEXT: R_RISCV_ADD16 - 0x0
65-
# RELOC-NEXT: R_RISCV_SUB16 - 0x0
60+
# RELOC: R_RISCV_ADD16 <null> 0x0
61+
# RELOC-NEXT: R_RISCV_SUB16 <null> 0x0
62+
# RELOC-NEXT: R_RISCV_ADD16 <null> 0x0
63+
# RELOC-NEXT: R_RISCV_SUB16 <null> 0x0
64+
# RELOC-NEXT: R_RISCV_ADD16 <null> 0x0
65+
# RELOC-NEXT: R_RISCV_SUB16 <null> 0x0
6666
# RELOC: }
6767

6868
.section .text.foo,"ax"

llvm/test/MC/RISCV/cfi-advance.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# RUN: | FileCheck -check-prefix=CHECK-DWARFDUMP %s
55

66
# CHECK: .rela.eh_frame {
7-
# CHECK-NEXT: 0x1C R_RISCV_32_PCREL - 0x0
8-
# CHECK-NEXT: 0x20 R_RISCV_ADD32 - 0x0
9-
# CHECK-NEXT: 0x20 R_RISCV_SUB32 - 0x0
7+
# CHECK-NEXT: 0x1C R_RISCV_32_PCREL <null> 0x0
8+
# CHECK-NEXT: 0x20 R_RISCV_ADD32 <null> 0x0
9+
# CHECK-NEXT: 0x20 R_RISCV_SUB32 <null> 0x0
1010
# CHECK-NEXT: }
1111
# CHECK-DWARFDUMP: DW_CFA_advance_loc1
1212
# CHECK-DWARFDUMP-NEXT: DW_CFA_def_cfa_offset

llvm/test/MC/RISCV/fde-reloc.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func:
1212
.cfi_endproc
1313

1414
# CHECK: Section (4) .rela.eh_frame {
15-
# CHECK-NEXT: 0x1C R_RISCV_32_PCREL - 0x0
16-
# CHECK-NEXT: 0x20 R_RISCV_ADD32 - 0x0
17-
# CHECK-NEXT: 0x20 R_RISCV_SUB32 - 0x0
15+
# CHECK-NEXT: 0x1C R_RISCV_32_PCREL <null> 0x0
16+
# CHECK-NEXT: 0x20 R_RISCV_ADD32 <null> 0x0
17+
# CHECK-NEXT: 0x20 R_RISCV_SUB32 <null> 0x0
1818
# CHECK-NEXT: }

llvm/test/MC/RISCV/scoped-relaxation.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.dword function - .
1010

1111
# CHECK: 0x0 R_RISCV_ADD64 function 0x0
12-
# CHECK-NEXT: 0x0 R_RISCV_SUB64 - 0x0
12+
# CHECK-NEXT: 0x0 R_RISCV_SUB64 <null> 0x0
1313

1414
# Relaxed reference, this will resolve to a pair of `RISCV_ADD64` and
1515
# `RISCV_SUB64` relocation.
@@ -19,7 +19,7 @@
1919
.option pop
2020

2121
# CHECK: 0x8 R_RISCV_ADD64 function 0x0
22-
# CHECK-NEXT: 0x8 R_RISCV_SUB64 - 0x0
22+
# CHECK-NEXT: 0x8 R_RISCV_SUB64 <null> 0x0
2323

2424
# Unrelaxed reference, this will resolve to a pair of `RISCV_ADD64` and
2525
# `RISCV_SUB64` relocation due to relaxation being sticky to the file.
@@ -29,6 +29,6 @@
2929
.option pop
3030

3131
# CHECK: 0x10 R_RISCV_ADD64 function 0x0
32-
# CHECK-NEXT: 0x10 R_RISCV_SUB64 - 0x0
32+
# CHECK-NEXT: 0x10 R_RISCV_SUB64 <null> 0x0
3333

3434
# CHECK: }

llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,42 @@
1010
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
1111
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
1212
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
13-
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456
13+
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 <null> + 456
1414
# CHECK-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
1515
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 <?> + 678
16-
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 2
16+
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 <null> + 2
1717

1818
# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 5 entries:
1919
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
2020
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
2121
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
22-
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456
22+
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 <null> + 456
2323
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 <?> + 678
24-
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 2
24+
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 <null> + 2
2525

2626
# CHECK: 'RELA' relocation section at offset {{.*}} contains 120 bytes:
2727
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
2828
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
2929
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
30-
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456
31-
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 678
32-
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 2
30+
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 <null> + 456
31+
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 <null> + 678
32+
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 <null> + 2
3333

3434
# LLVM: Relocations [
3535
# LLVM-NEXT: Section (2) .rela.text {
3636
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x1
3737
# LLVM-NEXT: 0x0 R_X86_64_NONE sym 0x1
38-
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x456
38+
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x456
3939
# LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
4040
# LLVM-NEXT: 0x0 R_X86_64_NONE <?> 0x678
41-
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x2
41+
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x2
4242
# LLVM-NEXT: }
4343
# LLVM-NEXT: Section (4) .rela.dyn {
4444
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x1
4545
# LLVM-NEXT: 0x0 R_X86_64_NONE sym 0x1
46-
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x456
46+
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x456
4747
# LLVM-NEXT: 0x0 R_X86_64_NONE <?> 0x678
48-
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x2
48+
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x2
4949
# LLVM-NEXT: }
5050
# LLVM-NEXT: ]
5151

llvm/test/tools/yaml2obj/ELF/symbol-name.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Symbols:
3838
# BOTH-NEXT: Relocation {
3939
# BOTH-NEXT: Offset: 0x0
4040
# BOTH-NEXT: Type: R_X86_64_NONE (0)
41-
# BOTH-NEXT: Symbol: - (1)
41+
# BOTH-NEXT: Symbol: <null> (1)
4242
# BOTH-NEXT: Addend: 0x0
4343
# BOTH-NEXT: }
4444
# BOTH-NEXT: }

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,15 +3761,18 @@ void GNUELFDumper<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
37613761
if (RelSym.Sym)
37623762
Fields[3].Str =
37633763
to_string(format_hex_no_prefix(RelSym.Sym->getValue(), Width));
3764+
if (RelSym.Sym && RelSym.Name.empty())
3765+
Fields[4].Str = "<null>";
3766+
else
3767+
Fields[4].Str = std::string(RelSym.Name);
37643768

3765-
Fields[4].Str = std::string(RelSym.Name);
37663769
for (const Field &F : Fields)
37673770
printField(F);
37683771

37693772
std::string Addend;
37703773
if (std::optional<int64_t> A = R.Addend) {
37713774
int64_t RelAddend = *A;
3772-
if (!RelSym.Name.empty()) {
3775+
if (!Fields[4].Str.empty()) {
37733776
if (RelAddend < 0) {
37743777
Addend = " - ";
37753778
RelAddend = std::abs(RelAddend);
@@ -6951,6 +6954,8 @@ template <class ELFT>
69516954
void LLVMELFDumper<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
69526955
const RelSymbol<ELFT> &RelSym) {
69536956
StringRef SymbolName = RelSym.Name;
6957+
if (RelSym.Sym && RelSym.Name.empty())
6958+
SymbolName = "<null>";
69546959
SmallString<32> RelocName;
69556960
this->Obj.getRelocationTypeName(R.Type, RelocName);
69566961

0 commit comments

Comments
 (0)