From 4c511cd88fa3bd986227122f36af6fbcdceb2b33 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 17 Aug 2014 16:31:39 +0000 Subject: [PATCH] Fix an off-by-one bug in the target independent llvm-objdump. It would prevent the display of a single byte instruction before a label. Patch by Steve King! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215837 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/Inputs/trivial-label-test.elf-x86-64 | Bin 0 -> 741 bytes test/Object/X86/objdump-label.test | 10 ++++++++++ tools/llvm-objdump/llvm-objdump.cpp | 15 +++++---------- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 test/Object/Inputs/trivial-label-test.elf-x86-64 create mode 100644 test/Object/X86/objdump-label.test diff --git a/test/Object/Inputs/trivial-label-test.elf-x86-64 b/test/Object/Inputs/trivial-label-test.elf-x86-64 new file mode 100644 index 0000000000000000000000000000000000000000..76f4499a834415d76ea6b21e63bdf91f24eb198e GIT binary patch literal 741 zcmb<-^>JfjWMpQ50!9Wq21XbMi7r55JAl~^4D1Xn3=<{*IeI0j6(tOMNyWtsdc_&V zB}FBPNkA5iuFM7VQxZ!OkxU_v333|D~KpZ3haw{^B19H&)2$DB|3a)@E289pItso%@sJIxAMt3_% z>IPIlFH{|jLbo3#j!v_J1sE~X4kr$Ah`HEJXT~rEVjDA7pM(5^#YbuR`3y;kMGQ%$ GxeNfJK^dU{ literal 0 HcmV?d00001 diff --git a/test/Object/X86/objdump-label.test b/test/Object/X86/objdump-label.test new file mode 100644 index 00000000000..f8b933451e5 --- /dev/null +++ b/test/Object/X86/objdump-label.test @@ -0,0 +1,10 @@ +RUN: llvm-objdump -d %p/../Inputs/trivial-label-test.elf-x86-64 \ +RUN: | FileCheck %s -check-prefix ELF-x86-64 + +ELF-x86-64: file format ELF64-x86-64 +ELF-x86-64: Disassembly of section .text: +ELF-x86-64: foo: +ELF-x86-64: 0: 90 nop +ELF-x86-64: bum: +ELF-x86-64: 1: 90 nop + diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index ebcee3b7f63..d7c9df1d6e7 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -494,17 +494,12 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { std::vector::const_iterator rel_end = Rels.end(); // Disassemble symbol by symbol. for (unsigned si = 0, se = Symbols.size(); si != se; ++si) { + uint64_t Start = Symbols[si].first; - uint64_t End; - // The end is either the size of the section or the beginning of the next - // symbol. - if (si == se - 1) - End = SectSize; - // Make sure this symbol takes up space. - else if (Symbols[si + 1].first != Start) - End = Symbols[si + 1].first - 1; - else - // This symbol has the same address as the next symbol. Skip it. + // The end is either the section end or the beginning of the next symbol. + uint64_t End = (si == se - 1) ? SectSize : Symbols[si + 1].first; + // If this symbol has the same address as the next symbol, then skip it. + if (Start == End) continue; outs() << '\n' << Symbols[si].second << ":\n"; -- 2.34.1