[PATCH] D77640: [llvm-objdump] Fix unstable disassembly output for sections with same address
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 06:28:15 PDT 2020
jhenderson updated this revision to Diff 255657.
jhenderson marked an inline comment as done.
jhenderson added a comment.
Address nits. I'll wait until either I get another thumbs up or tomorrow morning, whichever comes earlier, to give others a chance to chime in.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77640/new/
https://reviews.llvm.org/D77640
Files:
llvm/test/tools/llvm-objdump/X86/disassemble-same-section-addr.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1228,7 +1228,11 @@
std::vector<std::pair<uint64_t, SectionRef>> SectionAddresses;
for (SectionRef Sec : Obj->sections())
SectionAddresses.emplace_back(Sec.getAddress(), Sec);
- stable_sort(SectionAddresses);
+ llvm::stable_sort(SectionAddresses,
+ [](const std::pair<uint64_t, SectionRef> &LHS,
+ const std::pair<uint64_t, SectionRef> &RHS) {
+ return LHS.first < RHS.first;
+ });
// Linked executables (.exe and .dll files) typically don't include a real
// symbol table but they might contain an export table.
Index: llvm/test/tools/llvm-objdump/X86/disassemble-same-section-addr.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/X86/disassemble-same-section-addr.test
@@ -0,0 +1,39 @@
+## This test shows that llvm-objdump can handle sections with the same address
+## when symbols in those sections are referenced. In the past, the section
+## picked was non-deterministic, resulting in different symbols being found for
+## the section. The test uses YAML for the input, as we need a fully linked ELF
+## to reproduce the original failure.
+
+# RUN: yaml2obj %s -o %t1 -D SECTION=.second
+# RUN: llvm-objdump -d %t1 | FileCheck %s
+# RUN: yaml2obj %s -o %t2 -D SECTION=.first
+## FIXME: this case should print "<target>" too.
+# RUN: llvm-objdump -d %t2 | FileCheck %s --check-prefix=FAIL
+
+# CHECK: callq 0x5 <target>
+# FAIL: callq 0x5{{$}}
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .caller
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ Address: 0x0
+ Content: e800000000 # Call instruction to next address.
+ - Name: .first
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ Address: 0x5
+ - Name: .second
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ Address: 0x5
+Symbols:
+ - Name: target
+ Section: [[SECTION]]
+ Value: 0x5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77640.255657.patch
Type: text/x-patch
Size: 2316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200407/51cdf7d5/attachment.bin>
More information about the llvm-commits
mailing list