Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/docs/CommandGuide/llvm-readelf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ OPTIONS
``GNU`` (the default) output mimics the equivalent GNU :program:`readelf`
output. ``JSON`` is JSON formatted output intended for machine consumption.

.. option:: --extra-sym-info

Display extra information (section name) when showing symbols.

.. option:: --section-groups, -g

Display section groups.
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/aarch64-symbols-stother.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# RUN: llvm-readobj --symbols %t.o | FileCheck %s --check-prefix=LLVM
# RUN: llvm-readobj --symbols %t.o --elf-output-style=JSON --pretty-print | FileCheck %s --check-prefix=JSON
# RUN: llvm-readelf --symbols %t.o | FileCheck %s --check-prefix=GNU
# RUN: llvm-readelf --symbols --extra-sym-info %t.o | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=GNUX

# LLVM: Name: foo1
# LLVM: Other [ (0x80)
Expand All @@ -29,6 +30,14 @@
# GNU-NEXT: 3: 0000000000000000 0 NOTYPE LOCAL PROTECTED [VARIANT_PCS] UND foo3
# GNU-NEXT: 4: 0000000000000000 0 NOTYPE LOCAL PROTECTED UND foo4

# GNUX:Symbol table '.symtab' contains 5 entries:
# GNUX-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]
# GNUX-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
# GNUX-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT [VARIANT_PCS] UND foo1
# GNUX-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT [VARIANT_PCS | 40] UND foo2
# GNUX-NEXT: 3: 0000000000000000 0 NOTYPE LOCAL PROTECTED [VARIANT_PCS] UND foo3
# GNUX-NEXT: 4: 0000000000000000 0 NOTYPE LOCAL PROTECTED UND foo4

# JSON: "Name": "foo1",
# JSON: "Other": {
# JSON-NEXT: "Value": 128,
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/section-symbols.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# RUN: FileCheck %s -DFILE=%t1 --check-prefix=LLVM1 --implicit-check-not="warning:"
# RUN: llvm-readelf %t1 --symbols --relocations 2>&1 | \
# RUN: FileCheck %s -DFILE=%t1 --check-prefix=GNU1 --implicit-check-not="warning:"
# RUN: llvm-readelf %t1 --symbols -X 2>&1 | \
# RUN: FileCheck %s -DFILE=%t1 --check-prefix=GNUX1 --implicit-check-not="warning:"

# LLVM1: Relocations [
# LLVM1-NEXT: Section (5) .rela.foo {
Expand Down Expand Up @@ -62,6 +64,22 @@
# GNU1-NEXT: warning: '[[FILE]]': a section [index 3] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table
# GNU1-NEXT: 9: {{.*}} SECTION {{.*}} 3 <section 3>

# GNUX1: Symbol table '.symtab' contains 10 entries:
# GNUX1-NEXT: Num: {{.*}} Type {{.*}} Ndx(SecName) Name
# GNUX1-NEXT: 0: {{.*}} NOTYPE {{.*}} UND {{$}}
# GNUX1-NEXT: 1: {{.*}} SECTION {{.*}} 1 (.foo) .foo
# GNUX1-NEXT: 2: {{.*}} SECTION {{.*}} 1 (.foo) symbol1
# GNUX1-NEXT: warning: '[[FILE]]': invalid section index: 67
# GNUX1-NEXT: 3: {{.*}} SECTION {{.*}} 67 <section 67>
# GNUX1-NEXT: 4: {{.*}} SECTION {{.*}} 67 symbol2
# GNUX1-NEXT: 5: {{.*}} SECTION {{.*}} 2 (.bar) .bar
# GNUX1-NEXT: 6: {{.*}} SECTION {{.*}} 2 (.bar) symbol3
# GNUX1-NEXT: warning: '[[FILE]]': invalid section index: 66
# GNUX1-NEXT: 7: {{.*}} SECTION {{.*}} 66 <section 66>
# GNUX1-NEXT: 8: {{.*}} SECTION {{.*}} 66 symbol4
# GNUX1-NEXT: warning: '[[FILE]]': a section [index 3] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table
# GNUX1-NEXT: 9: {{.*}} SECTION {{.*}} 3 <section 3>

--- !ELF
FileHeader:
Class: ELFCLASS32
Expand Down
71 changes: 59 additions & 12 deletions llvm/test/tools/llvm-readobj/ELF/symbols.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
# RUN: yaml2obj %s -DBITS=64 -DTYPE=ET_REL -o %t64
# RUN: llvm-readobj --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readelf --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64
# RUN: llvm-readelf -s --extra-sym-info %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64X
# RUN: yaml2obj %s -DBITS=32 -DTYPE=ET_REL -o %t32
# RUN: llvm-readobj --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readelf --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32
# RUN: llvm-readelf -s -X %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32X
## b) Check dynamic objects.
# RUN: yaml2obj %s -DBITS=64 -DTYPE=ET_DYN -o %t64.so
# RUN: llvm-readobj --symbols %t64.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readobj --symbols %t64.so > %t64llvm.txt
# RUN: FileCheck --input-file=%t64llvm.txt %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readelf --symbols %t64.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64
## --extra-sym-info is a no-op for llvm-readobj.
# RUN: llvm-readobj --symbols --extra-sym-info %t64.so | diff %t64llvm.txt -
# RUN: yaml2obj %s -DBITS=32 -DTYPE=ET_DYN -o %t32.so
# RUN: llvm-readobj --symbols %t32.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM
# RUN: llvm-readelf --symbols %t32.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32
Expand All @@ -41,7 +46,7 @@
# SYMBOLS-LLVM-NEXT: Binding: Local (0x0)
# SYMBOLS-LLVM-NEXT: Type: None (0x0)
# SYMBOLS-LLVM-NEXT: Other: 0
# SYMBOLS-LLVM-NEXT: Section: Undefined (0x0)
# SYMBOLS-LLVM-NEXT: Section: .text (0x1)
# SYMBOLS-LLVM-NEXT: }
# SYMBOLS-LLVM-NEXT: Symbol {
# SYMBOLS-LLVM-NEXT: Name: bar (1)
Expand All @@ -52,19 +57,44 @@
# SYMBOLS-LLVM-NEXT: Other: 0
# SYMBOLS-LLVM-NEXT: Section: Undefined (0x0)
# SYMBOLS-LLVM-NEXT: }
# SYMBOLS-LLVM-NEXT: Symbol {
# SYMBOLS-LLVM-NEXT: Name: data (9)
# SYMBOLS-LLVM-NEXT: Value: 0x3
# SYMBOLS-LLVM-NEXT: Size: 0
# SYMBOLS-LLVM-NEXT: Binding: Global (0x1)
# SYMBOLS-LLVM-NEXT: Type: None (0x0)
# SYMBOLS-LLVM-NEXT: Other: 0
# SYMBOLS-LLVM-NEXT: Section: .data (0x2)
# SYMBOLS-LLVM-NEXT: }
# SYMBOLS-LLVM-NEXT:]

# SYMBOLS-GNU64:Symbol table '.symtab' contains 3 entries:
# SYMBOLS-GNU64:Symbol table '.symtab' contains 4 entries:
# SYMBOLS-GNU64-NEXT: Num: Value Size Type Bind Vis Ndx Name
# SYMBOLS-GNU64-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
# SYMBOLS-GNU64-NEXT: 1: 0000000000000001 0 NOTYPE LOCAL DEFAULT UND foo
# SYMBOLS-GNU64-NEXT: 1: 0000000000000001 0 NOTYPE LOCAL DEFAULT 1 foo
# SYMBOLS-GNU64-NEXT: 2: 0000000000000002 0 NOTYPE LOCAL DEFAULT UND bar
# SYMBOLS-GNU64-NEXT: 3: 0000000000000003 0 NOTYPE GLOBAL DEFAULT 2 data

# SYMBOLS-GNU64X:Symbol table '.symtab' contains 4 entries:
#SYMBOLS-GNU64X-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]
#SYMBOLS-GNU64X-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
#SYMBOLS-GNU64X-NEXT: 1: 0000000000000001 0 NOTYPE LOCAL DEFAULT 1 (.text) foo
#SYMBOLS-GNU64X-NEXT: 2: 0000000000000002 0 NOTYPE LOCAL DEFAULT UND bar
#SYMBOLS-GNU64X-NEXT: 3: 0000000000000003 0 NOTYPE GLOBAL DEFAULT 2 (.data) data

# SYMBOLS-GNU32:Symbol table '.symtab' contains 3 entries:
# SYMBOLS-GNU32:Symbol table '.symtab' contains 4 entries:
# SYMBOLS-GNU32-NEXT: Num: Value Size Type Bind Vis Ndx Name
# SYMBOLS-GNU32-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# SYMBOLS-GNU32-NEXT: 1: 00000001 0 NOTYPE LOCAL DEFAULT UND foo
# SYMBOLS-GNU32-NEXT: 1: 00000001 0 NOTYPE LOCAL DEFAULT 1 foo
# SYMBOLS-GNU32-NEXT: 2: 00000002 0 NOTYPE LOCAL DEFAULT UND bar
# SYMBOLS-GNU32-NEXT: 3: 00000003 0 NOTYPE GLOBAL DEFAULT 2 data

# SYMBOLS-GNU32X:Symbol table '.symtab' contains 4 entries:
#SYMBOLS-GNU32X-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]
#SYMBOLS-GNU32X-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
#SYMBOLS-GNU32X-NEXT: 1: 00000001 0 NOTYPE LOCAL DEFAULT 1 (.text) foo
#SYMBOLS-GNU32X-NEXT: 2: 00000002 0 NOTYPE LOCAL DEFAULT UND bar
#SYMBOLS-GNU32X-NEXT: 3: 00000003 0 NOTYPE GLOBAL DEFAULT 2 (.data) data

## Case 2: Check flag aliases produce identical output
# RUN: llvm-readobj --symbols %t64 > %t.symbols
Expand Down Expand Up @@ -100,10 +130,10 @@
## Case 6: Test that the Num index starts from zero at every new symbol table.
# RUN: llvm-readelf --symbols %t64 %t64 | FileCheck %s --check-prefix=NUM-INDEX

# NUM-INDEX: Symbol table '.symtab' contains 3 entries:
# NUM-INDEX: Symbol table '.symtab' contains 4 entries:
# NUM-INDEX-NEXT: Num: {{.*}}
# NUM-INDEX-NEXT: 0: {{.*}}
# NUM-INDEX: Symbol table '.symtab' contains 3 entries:
# NUM-INDEX: Symbol table '.symtab' contains 4 entries:
# NUM-INDEX-NEXT: Num: {{.*}}
# NUM-INDEX-NEXT: 0: {{.*}}

Expand All @@ -112,11 +142,21 @@ FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: [[TYPE]]
Sections:
- Name: .text
Type: SHT_PROGBITS
- Name: .data
Type: SHT_PROGBITS
Symbols:
- Name: foo
Value: 0x1
- Name: bar
Value: 0x2
- Name: foo
Value: 0x1
Section: .text
- Name: bar
Value: 0x2
- Name: data
Value: 0x3
Binding: STB_GLOBAL
Section: .data
DynamicSymbols:
- Name: zed

Expand Down Expand Up @@ -232,6 +272,13 @@ Symbols:
## Test a symbol defined relative to a section with an invalid name.
# RUN: yaml2obj --docnum=3 %s -o %t64.err4
# RUN: llvm-readelf -s %t64.err4 2>&1 | FileCheck /dev/null --implicit-check-not=warning:
# RUN: llvm-readelf -s -X %t64.err4 2>&1 | \
# RUN: FileCheck %s -DFILE=%t64.err4 --check-prefix=INVALID-SECNAME-GNU --implicit-check-not=warning:

# INVALID-SECNAME-GNU: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]
# INVALID-SECNAME-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# INVALID-SECNAME-GNU-NEXT: warning: '[[FILE]]': a section [index 1] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table
# INVALID-SECNAME-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 1 foo

--- !ELF
FileHeader:
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/symtab-shndx.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readelf --symbols --dyn-syms %t1 2>&1 | FileCheck %s --check-prefix=GNU
# RUN: llvm-readelf --symbols --dyn-syms --extra-sym-info %t1 2>&1 | FileCheck %s --check-prefix=GNUX
# RUN: llvm-readobj --symbols --dyn-syms %t1 2>&1 | FileCheck %s --check-prefix=LLVM

# GNU: Symbol table '.dynsym' contains 3 entries:
Expand All @@ -20,6 +21,17 @@
# GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 sym1
# GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 sym2

# GNUX: Symbol table '.dynsym' contains 3 entries:
# GNUX-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]
# GNUX-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# GNUX-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 3 (.section3) dynsym1
# GNUX-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 (.section2) dynsym2
# GNUX: Symbol table '.symtab' contains 3 entries:
# GNUX-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]
# GNUX-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# GNUX-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 (.section2) sym1
# GNUX-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 (.section1) sym2

# LLVM: Symbols [
# LLVM-NEXT: Symbol {
# LLVM-NEXT: Name: (0)
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-readobj/COFFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class COFFDumper : public ObjDumper {

private:
StringRef getSymbolName(uint32_t Index);
void printSymbols() override;
void printSymbols(bool ExtraSymInfo) override;
void printDynamicSymbols() override;
void printSymbol(const SymbolRef &Sym);
void printRelocation(const SectionRef &Section, const RelocationRef &Reloc,
Expand Down Expand Up @@ -1609,7 +1609,7 @@ void COFFDumper::printRelocation(const SectionRef &Section,
}
}

void COFFDumper::printSymbols() {
void COFFDumper::printSymbols(bool /*ExtraSymInfo*/) {
ListScope Group(W, "Symbols");

for (const SymbolRef &Symbol : Obj->symbols())
Expand Down
Loading