Skip to content

Commit 644e6d7

Browse files
authored
[llvm-objdump] --disassemble-symbols: skip inline relocs from symbols that are not dumped (#75724)
When a section contains two functions x1 and x2, we incorrectly display x1's relocations when dumping x2 for `--disassemble-symbols=x2 -r`. Fix #75539 by ignoring these relocations.
1 parent 96aca7c commit 644e6d7

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
# CHECK2-EMPTY:
3636
# CHECK2-NEXT: 0000000000000037 <rodata3>:
3737
# CHECK2-NEXT: ...
38+
# CHECK2-NEXT: 3f: 00 00 addb %al, (%rax)
39+
# CHECK2-NEXT: 000000000000003f: R_X86_64_64 x3
40+
# CHECK2-NEXT: 41: 00 00 addb %al, (%rax)
41+
# CHECK2-NEXT: 43: 00 00 addb %al, (%rax)
42+
# CHECK2-NEXT: 45: 00 00 addb %al, (%rax)
3843
# CHECK2-NOT: {{.}}
3944

4045
## Check that without -reloc all zeroes would be omitted.

llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
# CHECK-NEXT: 000000000040000d: R_X86_64_32 .rodata
2323
# CHECK-NOT: {{.}}
2424

25-
## FIXME: --disassemble-symbols: remove inline relocs from skipped functions
2625
# CHECK2:000000000040000c <text1>:
2726
#CHECK2-NEXT: 40000c: bf 10 00 40 00 movl $4194320, %edi # imm = 0x400010
28-
#CHECK2-NEXT: 0000000000400002: R_X86_64_32 .rodata
29-
#CHECK2-NEXT: 0000000000400007: R_X86_64_PLT32 puts-0x4
3027
#CHECK2-NEXT: 000000000040000d: R_X86_64_32 .rodata
3128
#CHECK2-NOT: {{.}}
3229

llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@
2828
# CHECK-NEXT: 000000000000001a: R_X86_64_REX_GOTPCRELX var-0x4
2929
# CHECK-NOT: {{.}}
3030

31-
## FIXME: --disassemble-symbols: remove inline relocs from skipped functions
3231
# CHECK2: 000000000000000a <x2>:
3332
# CHECK2-NEXT: a: 90 nop
34-
# CHECK2-NEXT: 0000000000000001: R_X86_64_PC32 foo-0x4
35-
# CHECK2-NEXT: 0000000000000002: R_X86_64_NONE bar+0x8
36-
# CHECK2-NEXT: 0000000000000006: R_X86_64_PLT32 foo+0x1
3733
# CHECK2-NEXT: b: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x12 <x3>
3834
# CHECK2-NEXT: 000000000000000e: R_X86_64_REX_GOTPCRELX var-0x4
3935
# CHECK2-EMPTY:
4036
# CHECK2-NEXT: 0000000000000017 <x4>:
4137
# CHECK2-NEXT: 17: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x1e <x4+0x7>
42-
# CHECK2-NEXT: 0000000000000013: R_X86_64_PLT32 foo-0x4
4338
# CHECK2-NEXT: 000000000000001a: R_X86_64_REX_GOTPCRELX var-0x4
39+
# CHECK2-NOT: {{.}}
4440

4541
.globl x1, x2, x3, x4
4642
x1:

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,13 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
19481948
continue;
19491949
}
19501950

1951+
// Skip relocations from symbols that are not dumped.
1952+
for (; RelCur != RelEnd; ++RelCur) {
1953+
uint64_t Offset = RelCur->getOffset() - RelAdjustment;
1954+
if (Index <= Offset)
1955+
break;
1956+
}
1957+
19511958
bool DumpARMELFData = false;
19521959
bool DumpTracebackTableForXCOFFFunction =
19531960
Obj.isXCOFF() && Section.isText() && TracebackTable &&
@@ -2214,7 +2221,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
22142221
while (RelCur != RelEnd) {
22152222
uint64_t Offset = RelCur->getOffset() - RelAdjustment;
22162223
// If this relocation is hidden, skip it.
2217-
if (getHidden(*RelCur) || SectionAddr + Offset < StartAddress) {
2224+
if (getHidden(*RelCur)) {
22182225
++RelCur;
22192226
continue;
22202227
}

0 commit comments

Comments
 (0)