diff --git a/llvm/test/tools/llvm-objdump/ELF/section-symbols.test b/llvm/test/tools/llvm-objdump/ELF/section-symbols.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/ELF/section-symbols.test @@ -0,0 +1,40 @@ +## ELF section symbols use the corresponding section names when printing +## unnamed symbols. This test verifies this and also that appropriate things +## are printed if the section is somehow invalid. + +# RUN: yaml2obj %s -o %t1 +# RUN: llvm-objdump --syms %t1 2>&1 | FileCheck %s -DFILE=%t1 + +# CHECK: SYMBOL TABLE: +# CHECK-NEXT: 00000000 l d .foo 00000000 .foo +# CHECK-NEXT: 00000000 l d .foo 00000000 .foo +# CHECK-NEXT: warning: '[[FILE]]': invalid section index: 67 +# CHECK-NEXT: warning: '[[FILE]]': invalid section index: 68 +# CHECK-NOT: {{.}} + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS +Symbols: +## Case 1: a valid unnamed section symbol. + - Name: "" + Section: .foo + Type: STT_SECTION +## Case 2: a valid named section symbol. + - Name: "symbol1" + Section: .foo + Type: STT_SECTION +## Case 3: an unnamed section symbol with invalid index. + - Name: "" + Index: 0x43 + Type: STT_SECTION +## Case 4: a named section symbol with invalid index. + - Name: "symbol2" + Index: 0x44 + Type: STT_SECTION diff --git a/llvm/test/tools/llvm-objdump/invalid-symbol-table-size.test b/llvm/test/tools/llvm-objdump/invalid-symbol-table-size.test --- a/llvm/test/tools/llvm-objdump/invalid-symbol-table-size.test +++ b/llvm/test/tools/llvm-objdump/invalid-symbol-table-size.test @@ -3,17 +3,17 @@ ## a) Broken .symtab symbol table. Valid .dynsym symbol table. # RUN: yaml2obj -DBITS=32 -DSIZE=33 -DDYNSIZE=32 %s -o %t.32-bit.o -# RUN: not llvm-objdump --syms %t.32-bit.o 2>&1 | FileCheck -DSIZE=33 -DSYMSIZE=16 -DINDEX=2 %s +# RUN: llvm-objdump --syms %t.32-bit.o 2>&1 | FileCheck -DSIZE=33 -DSYMSIZE=16 -DINDEX=2 %s # RUN: yaml2obj -DBITS=64 -DSIZE=49 -DDYNSIZE=48 %s -o %t.64-bit.o -# RUN: not llvm-objdump --syms %t.64-bit.o 2>&1 | FileCheck -DSIZE=49 -DSYMSIZE=24 -DINDEX=2 %s +# RUN: llvm-objdump --syms %t.64-bit.o 2>&1 | FileCheck -DSIZE=49 -DSYMSIZE=24 -DINDEX=2 %s ## b) Broken .dynsym symbol table. Valid .symtab symbol table. # RUN: yaml2obj -DBITS=32 -DSIZE=32 -DDYNSIZE=33 %s -o %t.32-bit.o -# RUN: not llvm-objdump --dynamic-syms %t.32-bit.o 2>&1 | FileCheck -DSIZE=33 -DSYMSIZE=16 -DINDEX=3 %s +# RUN: llvm-objdump --dynamic-syms %t.32-bit.o 2>&1 | FileCheck -DSIZE=33 -DSYMSIZE=16 -DINDEX=3 %s # RUN: yaml2obj -DBITS=64 -DSIZE=48 -DDYNSIZE=49 %s -o %t.64-bit.o -# RUN: not llvm-objdump --dynamic-syms %t.64-bit.o 2>&1 | FileCheck -DSIZE=49 -DSYMSIZE=24 -DINDEX=3 %s +# RUN: llvm-objdump --dynamic-syms %t.64-bit.o 2>&1 | FileCheck -DSIZE=49 -DSYMSIZE=24 -DINDEX=3 %s -# CHECK: error: {{.*}} section [index [[INDEX]]] has an invalid sh_size ([[SIZE]]) which is not a multiple of its sh_entsize ([[SYMSIZE]]) +# CHECK: warning: {{.*}} section [index [[INDEX]]] has an invalid sh_size ([[SIZE]]) which is not a multiple of its sh_entsize ([[SYMSIZE]]) --- !ELF FileHeader: diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2419,8 +2419,12 @@ StringRef FileName, StringRef ArchiveName, StringRef ArchitectureName, bool DumpDynamic) { const MachOObjectFile *MachO = dyn_cast(&O); - uint64_t Address = unwrapOrError(Symbol.getAddress(), FileName, ArchiveName, - ArchitectureName); + Expected AddrOrErr = Symbol.getAddress(); + if (!AddrOrErr) { + reportWarning(toString(AddrOrErr.takeError()), FileName); + return; + } + uint64_t Address = *AddrOrErr; if ((Address < StartAddress) || (Address > StopAddress)) return; SymbolRef::Type Type =