[llvm] r344818 - [llvm-objdump] Fix --file-headers (-f) option
Petar Jovanovic via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 19 15:16:49 PDT 2018
Author: petarj
Date: Fri Oct 19 15:16:49 2018
New Revision: 344818
URL: http://llvm.org/viewvc/llvm-project?rev=344818&view=rev
Log:
[llvm-objdump] Fix --file-headers (-f) option
Changed the format call to match the surrounding code. Previously it was
printing an unsigned int while the return type being printed was
long unsigned int or wider. This caused problems for big-endian systems
which were discovered on mips64.
Also, the printed address had less characters than it should because the
character count was directly obtained from the number of bytes in the
address.
The tests were adapted to fit this fix and now use longer addresses.
Patch by Milos Stojanovic.
Differential Revision: https://reviews.llvm.org/D53403
Modified:
llvm/trunk/test/tools/llvm-objdump/file-headers-coff.test
llvm/trunk/test/tools/llvm-objdump/file-headers-elf.test
llvm/trunk/test/tools/llvm-objdump/file-headers-pe.test
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/test/tools/llvm-objdump/file-headers-coff.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/file-headers-coff.test?rev=344818&r1=344817&r2=344818&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/file-headers-coff.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/file-headers-coff.test Fri Oct 19 15:16:49 2018
@@ -10,4 +10,4 @@ sections:
symbols:
# CHECK: architecture: i386
-# CHECK: start address: 0x0000
+# CHECK: start address: 0x00000000
Modified: llvm/trunk/test/tools/llvm-objdump/file-headers-elf.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/file-headers-elf.test?rev=344818&r1=344817&r2=344818&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/file-headers-elf.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/file-headers-elf.test Fri Oct 19 15:16:49 2018
@@ -8,7 +8,7 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
- Entry: 0x123456
+ Entry: 0x123456789abcde
# CHECK: architecture: x86_64
-# CHECK: start address: 0x00123456
+# CHECK: start address: 0x00123456789abcde
Modified: llvm/trunk/test/tools/llvm-objdump/file-headers-pe.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/file-headers-pe.test?rev=344818&r1=344817&r2=344818&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/file-headers-pe.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/file-headers-pe.test Fri Oct 19 15:16:49 2018
@@ -7,7 +7,7 @@ header: !Header
Machine: IMAGE_FILE_MACHINE_I386
Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ]
OptionalHeader:
- AddressOfEntryPoint: 0x1234
+ AddressOfEntryPoint: 0x123456
# Unfortunately, all these flags are mandatory to set AddressOfEntryPoint.
# All the values are randomly picked. They can't interfere in what
# we are testing here.
@@ -30,4 +30,4 @@ sections:
symbols:
# CHECK: architecture: i386
-# CHECK: start address: 0x1234
+# CHECK: start address: 0x00123456
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=344818&r1=344817&r2=344818&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Fri Oct 19 15:16:49 2018
@@ -2220,8 +2220,11 @@ static void printFileHeaders(const Objec
Expected<uint64_t> StartAddrOrErr = o->getStartAddress();
if (!StartAddrOrErr)
report_error(o->getFileName(), StartAddrOrErr.takeError());
+
+ StringRef Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
+ uint64_t Address = StartAddrOrErr.get();
outs() << "start address: "
- << format("0x%0*x", o->getBytesInAddress(), StartAddrOrErr.get())
+ << "0x" << format(Fmt.data(), Address)
<< "\n";
}
More information about the llvm-commits
mailing list