Skip to content

Commit f1e32bc

Browse files
committed
Optimize warning report format.
Signed-off-by: Ruoyu Qiu <cabbaken@outlook.com>
1 parent 21560c7 commit f1e32bc

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

llvm/test/tools/llvm-objdump/ELF/dynamic-section.test

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,15 @@ Sections:
475475
# RUN: llvm-objdump -p %t5 2>&1 | FileCheck %s --strict-whitespace -DFILE=%t5 --check-prefix=WARN
476476

477477
# WARN: Program Header:
478-
# WARN: LOAD off 0x00000000000000b0 vaddr 0x0000000000001000 paddr 0x0000000000001000 align 2**0
479-
# WARN: filesz 0x0000000000000040 memsz 0x0000000000000040 flags ---
480-
# WARN: DYNAMIC off 0x00000000000000c0 vaddr 0x000000000000101d paddr 0x000000000000101d align 2**0
481-
# WARN: filesz 0x0000000000000030 memsz 0x0000000000000030 flags ---
478+
# WARN: LOAD off 0x00000000000000b0 vaddr 0x0000000000001000 paddr 0x0000000000001000 align 2**0
479+
# WARN: filesz 0x0000000000000050 memsz 0x0000000000000050 flags ---
480+
# WARN: DYNAMIC off 0x00000000000000c0 vaddr 0x000000000000101d paddr 0x000000000000101d align 2**0
481+
# WARN: filesz 0x0000000000000040 memsz 0x0000000000000040 flags ---
482482
# WARN: Dynamic Section:
483483
# WARN: warning: '[[FILE]]': invalid string table offset
484-
# WARN: NEEDED 0x0000001245657656
484+
# WARN: NEEDED 0x0000000000000011
485485
# WARN: STRTAB 0x0000000000001000
486+
# WARN: STRSZ 0x0000000000000010
486487

487488
--- !ELF
488489
FileHeader:
@@ -500,9 +501,11 @@ Sections:
500501
Type: SHT_DYNAMIC
501502
Entries:
502503
- Tag: DT_NEEDED
503-
Value: 0x1245657656
504+
Value: 0x11
504505
- Tag: DT_STRTAB
505506
Value: 0x1000
507+
- Tag: DT_STRSZ
508+
Value: 0x10
506509
- Tag: DT_NULL
507510
Value: 0x0
508511
ProgramHeaders:

llvm/tools/llvm-objdump/ELFDump.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
223223
outs() << "\nDynamic Section:\n";
224224
typename ELFT::Xword StringTableSize{0};
225225
for (const typename ELFT::Shdr &Sec : cantFail(Elf.sections())) {
226-
if (Sec.sh_type == ELF::SHT_DYNSYM) {
226+
if (Sec.sh_type == ELF::SHT_DYNAMIC || Sec.sh_type == ELF::SHT_DYNSYM) {
227227
Expected<const typename ELFT::Shdr *> StringTableSecOrError =
228228
getSection<ELFT>(cantFail(Elf.sections()), Sec.sh_link);
229229
if (!StringTableSecOrError) {
230-
consumeError(StringTableSecOrError.takeError());
231-
break;
230+
reportWarning(toString(StringTableSecOrError.takeError()),
231+
Obj.getFileName());
232+
continue;
232233
}
233234
StringTableSize = StringTableSize < (*StringTableSecOrError)->sh_size
234235
? (*StringTableSecOrError)->sh_size
@@ -258,7 +259,9 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
258259
if (StrTabOrErr) {
259260
const char *Data = StrTabOrErr->data();
260261
if (Dyn.getVal() >= StringTableSize) {
261-
reportWarning("invalid string table offset", Obj.getFileName());
262+
reportWarning("invalid string table offset, string table size: 0x" +
263+
Twine::utohexstr(StringTableSize),
264+
Obj.getFileName());
262265
outs() << format(TagFmt.c_str(), Str.c_str())
263266
<< format(Fmt, (uint64_t)Dyn.getVal());
264267
continue;

0 commit comments

Comments
 (0)