[llvm] 644e6d7 - [llvm-objdump] --disassemble-symbols: skip inline relocs from symbols that are not dumped (#75724)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 18 09:53:48 PST 2023
Author: Fangrui Song
Date: 2023-12-18T09:53:44-08:00
New Revision: 644e6d7d8be29b170d3fabe8e388ae5478b4adcf
URL: https://github.com/llvm/llvm-project/commit/644e6d7d8be29b170d3fabe8e388ae5478b4adcf
DIFF: https://github.com/llvm/llvm-project/commit/644e6d7d8be29b170d3fabe8e388ae5478b4adcf.diff
LOG: [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.
Added:
Modified:
llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test b/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
index 62776f8c5a9900..6f268247e8ebbb 100644
--- a/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
+++ b/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
@@ -35,6 +35,11 @@
# CHECK2-EMPTY:
# CHECK2-NEXT: 0000000000000037 <rodata3>:
# CHECK2-NEXT: ...
+# CHECK2-NEXT: 3f: 00 00 addb %al, (%rax)
+# CHECK2-NEXT: 000000000000003f: R_X86_64_64 x3
+# CHECK2-NEXT: 41: 00 00 addb %al, (%rax)
+# CHECK2-NEXT: 43: 00 00 addb %al, (%rax)
+# CHECK2-NEXT: 45: 00 00 addb %al, (%rax)
# CHECK2-NOT: {{.}}
## Check that without -reloc all zeroes would be omitted.
diff --git a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
index 6c3c0bd1c98038..d9f486ce28a779 100644
--- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
+++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
@@ -22,11 +22,8 @@
# CHECK-NEXT: 000000000040000d: R_X86_64_32 .rodata
# CHECK-NOT: {{.}}
-## FIXME: --disassemble-symbols: remove inline relocs from skipped functions
# CHECK2:000000000040000c <text1>:
#CHECK2-NEXT: 40000c: bf 10 00 40 00 movl $4194320, %edi # imm = 0x400010
-#CHECK2-NEXT: 0000000000400002: R_X86_64_32 .rodata
-#CHECK2-NEXT: 0000000000400007: R_X86_64_PLT32 puts-0x4
#CHECK2-NEXT: 000000000040000d: R_X86_64_32 .rodata
#CHECK2-NOT: {{.}}
diff --git a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
index 33438cbfa126e1..cce0712e8fa0d9 100644
--- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
+++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
@@ -28,19 +28,15 @@
# CHECK-NEXT: 000000000000001a: R_X86_64_REX_GOTPCRELX var-0x4
# CHECK-NOT: {{.}}
-## FIXME: --disassemble-symbols: remove inline relocs from skipped functions
# CHECK2: 000000000000000a <x2>:
# CHECK2-NEXT: a: 90 nop
-# CHECK2-NEXT: 0000000000000001: R_X86_64_PC32 foo-0x4
-# CHECK2-NEXT: 0000000000000002: R_X86_64_NONE bar+0x8
-# CHECK2-NEXT: 0000000000000006: R_X86_64_PLT32 foo+0x1
# CHECK2-NEXT: b: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x12 <x3>
# CHECK2-NEXT: 000000000000000e: R_X86_64_REX_GOTPCRELX var-0x4
# CHECK2-EMPTY:
# CHECK2-NEXT: 0000000000000017 <x4>:
# CHECK2-NEXT: 17: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x1e <x4+0x7>
-# CHECK2-NEXT: 0000000000000013: R_X86_64_PLT32 foo-0x4
# CHECK2-NEXT: 000000000000001a: R_X86_64_REX_GOTPCRELX var-0x4
+# CHECK2-NOT: {{.}}
.globl x1, x2, x3, x4
x1:
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 12bb70d5537d8a..1cdd84b20970fe 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1948,6 +1948,13 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
continue;
}
+ // Skip relocations from symbols that are not dumped.
+ for (; RelCur != RelEnd; ++RelCur) {
+ uint64_t Offset = RelCur->getOffset() - RelAdjustment;
+ if (Index <= Offset)
+ break;
+ }
+
bool DumpARMELFData = false;
bool DumpTracebackTableForXCOFFFunction =
Obj.isXCOFF() && Section.isText() && TracebackTable &&
@@ -2214,7 +2221,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
while (RelCur != RelEnd) {
uint64_t Offset = RelCur->getOffset() - RelAdjustment;
// If this relocation is hidden, skip it.
- if (getHidden(*RelCur) || SectionAddr + Offset < StartAddress) {
+ if (getHidden(*RelCur)) {
++RelCur;
continue;
}
More information about the llvm-commits
mailing list