Index: test/tools/llvm-readobj/demangle.test =================================================================== --- test/tools/llvm-readobj/demangle.test +++ test/tools/llvm-readobj/demangle.test @@ -67,24 +67,18 @@ # LLVM-COMMON-NEXT: ] ## Check GNU output style. -## FIXME: The extra run for --symbols is because GNU mode only prints the dynamic symbols, -## if --dyn-symbols is specified, even if --symbols is specified. -# RUN: llvm-readelf --relocations --dyn-symbols --dyn-relocations \ +# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \ # RUN: --elf-section-groups --demangle %t.so > %t.gnu.long -# RUN: llvm-readelf --symbols --demangle %t.so >> %t.gnu.long -# RUN: llvm-readelf --relocations --dyn-symbols --dyn-relocations \ +# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \ # RUN: --elf-section-groups -C %t.so > %t.gnu.short -# RUN: llvm-readelf --symbols -C %t.so >> %t.gnu.short # RUN: FileCheck %s --input-file %t.gnu.long --check-prefixes=GNU-COMMON,GNU-DEMANGLE # RUN: diff %t.gnu.long %t.gnu.short ## Check that default is no demangling. -# RUN: llvm-readelf --relocations --dyn-symbols --dyn-relocations \ +# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \ # RUN: --elf-section-groups %t.so > %t.gnu.default -# RUN: llvm-readelf --symbols %t.so >> %t.gnu.default -# RUN: llvm-readelf --relocations --dyn-symbols --dyn-relocations \ +# RUN: llvm-readelf --symbols --relocations --dyn-symbols --dyn-relocations \ # RUN: --elf-section-groups --demangle=false %t.so > %t.gnu.nodemangle -# RUN: llvm-readelf --symbols --demangle=false %t.so >> %t.gnu.nodemangle # RUN: FileCheck %s --input-file %t.gnu.default --check-prefixes=GNU-COMMON,GNU-MANGLED # RUN: diff %t.gnu.default %t.gnu.nodemangle @@ -104,10 +98,6 @@ # GNU-DEMANGLE-NEXT: foo(int){{$}} # GNU-MANGLED-NEXT: _Z3fooi{{$}} -# GNU-COMMON: COMDAT group section [{{.*}}] `.group' -# GNU-DEMANGLE-SAME: [foo(char)] -# GNU-MANGLED-SAME: [_Z3fooc] - # GNU-COMMON: Symbol table '.symtab' contains 3 entries: # GNU-COMMON-NEXT: Num: Value Size Type Bind Vis Ndx Name # GNU-COMMON-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @@ -116,6 +106,10 @@ # GNU-MANGLED-NEXT: _Z3fooc{{$}} # GNU-MANGLED-NEXT: _Z4blahf{{$}} +# GNU-COMMON: COMDAT group section [{{.*}}] `.group' +# GNU-DEMANGLE-SAME: [foo(char)] +# GNU-MANGLED-SAME: [_Z3fooc] + !ELF FileHeader: Class: ELFCLASS64 Index: test/tools/llvm-readobj/gnu-symbols.test =================================================================== --- test/tools/llvm-readobj/gnu-symbols.test +++ test/tools/llvm-readobj/gnu-symbols.test @@ -4,8 +4,8 @@ RUN: | FileCheck %s -check-prefix ELF64 RUN: llvm-readobj -symbols %p/Inputs/gnuhash.so.elf-x86_64 --elf-output-style=GNU \ RUN: | FileCheck %s -check-prefix DYN -RUN: llvm-readobj -dyn-symbols %p/Inputs/dynamic-table-exe.x86 --elf-output-style=GNU \ -RUN: | FileCheck %s -check-prefix HASH +RUN: llvm-readobj -symbols -dyn-symbols %p/Inputs/gnuhash.so.elf-x86_64 --elf-output-style=GNU \ +RUN: | FileCheck %s -check-prefix DYN ELF32: Symbol table '.symtab' contains 5 entries: ELF32-NEXT: Num: Value Size Type Bind Vis Ndx Name @@ -24,7 +24,7 @@ ELF64-NEXT: 4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _GLOBAL_OFFSET_TABLE_ ELF64-NEXT: 5: 0000000000000000 0 TLS GLOBAL DEFAULT UND sym -DYN:Symbol table '.dynsym' contains 5 entries: +DYN: Symbol table '.dynsym' contains 5 entries: DYN-NEXT: Num: Value Size Type Bind Vis Ndx Name DYN-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND DYN-NEXT: 1: 00000000000001b8 0 NOTYPE GLOBAL DEFAULT 4 foo @@ -32,6 +32,8 @@ DYN-NEXT: 3: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 _end DYN-NEXT: 4: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 __bss_start +DYN-NOT: .dynsym + DYN: Symbol table '.symtab' contains 12 entries: DYN-NEXT: Num: Value Size Type Bind Vis Ndx Name DYN-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @@ -47,28 +49,4 @@ DYN-NEXT: 10: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 _edata DYN-NEXT: 11: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 _end -HASH: Symbol table of .hash for image: -HASH-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name -HASH-NEXT: 9 0: 00000000 0 FUNC GLOBAL DEFAULT UND __gxx_personality_v0@CXXABI_1.3 -HASH-NEXT: 13 0: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS _edata{{$}} -HASH-NEXT: 7 0: 00000000 0 FUNC GLOBAL DEFAULT UND _ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@GLIBCXX_3.4 -HASH-NEXT: 2 0: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses{{$}} -HASH-NEXT: 1 0: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__{{$}} -HASH-NEXT: 16 1: 00000850 81 FUNC GLOBAL DEFAULT 14 main{{$}} -HASH-NEXT: 10 1: 00000000 0 FUNC GLOBAL DEFAULT UND _Unwind_Resume@GCC_3.0 -HASH-NEXT: 8 1: 00000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 -HASH-NEXT: 12 1: 00001b68 0 NOTYPE GLOBAL DEFAULT ABS _end{{$}} -HASH-NEXT: 6 1: 00000000 0 FUNC GLOBAL DEFAULT UND _ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@GLIBCXX_3.4 -HASH-NEXT: 5 1: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable{{$}} -HASH-NEXT: 4 1: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable{{$}} -HASH-NEXT: 3 1: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 -HASH-NEXT: 11 2: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.1.3 -HASH-NEXT: 15 2: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS __bss_start{{$}} -HASH-NEXT: 14 2: 0000093c 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used{{$}} -HASH: Symbol table of .gnu.hash for image: -HASH-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name -HASH-NEXT: 12 0: 00001b68 0 NOTYPE GLOBAL DEFAULT ABS _end{{$}} -HASH-NEXT: 13 0: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS _edata{{$}} -HASH-NEXT: 14 1: 0000093c 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used{{$}} -HASH-NEXT: 15 1: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS __bss_start{{$}} -HASH-NEXT: 16 1: 00000850 81 FUNC GLOBAL DEFAULT 14 main{{$}} +DYN-NOT: .dynsym Index: tools/llvm-readobj/COFFDumper.cpp =================================================================== --- tools/llvm-readobj/COFFDumper.cpp +++ tools/llvm-readobj/COFFDumper.cpp @@ -80,8 +80,7 @@ void printFileHeaders() override; void printSectionHeaders() override; void printRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override; + void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; void printUnwindInfo() override; void printNeededLibraries() override; @@ -100,6 +99,8 @@ void printStackMap() const override; void printAddrsig() override; private: + void printSymbols(); + void printDynamicSymbols(); void printSymbol(const SymbolRef &Sym); void printRelocation(const SectionRef &Section, const RelocationRef &Reloc, uint64_t Bias = 0); @@ -1388,6 +1389,13 @@ } } +void COFFDumper::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { + if (PrintSymbols) + printSymbols(); + if (PrintDynamicSymbols) + printDynamicSymbols(); +} + void COFFDumper::printSymbols() { ListScope Group(W, "Symbols"); Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -147,8 +147,7 @@ void printSectionHeaders() override; void printRelocations() override; void printDynamicRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override; + void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; void printUnwindInfo() override; void printDynamicTable() override; @@ -328,8 +327,8 @@ virtual void printGroupSections(const ELFFile *Obj) = 0; virtual void printRelocations(const ELFFile *Obj) = 0; virtual void printSectionHeaders(const ELFFile *Obj) = 0; - virtual void printSymbols(const ELFFile *Obj) = 0; - virtual void printDynamicSymbols(const ELFFile *Obj) = 0; + virtual void printSymbols(const ELFFile *Obj, bool PrintSymbols, + bool PrintDynamicSymbols) = 0; virtual void printDynamicRelocations(const ELFFile *Obj) = 0; virtual void printSymtabMessage(const ELFFile *obj, StringRef Name, size_t Offset) {} @@ -363,8 +362,8 @@ void printGroupSections(const ELFFile *Obj) override; void printRelocations(const ELFO *Obj) override; void printSectionHeaders(const ELFO *Obj) override; - void printSymbols(const ELFO *Obj) override; - void printDynamicSymbols(const ELFO *Obj) override; + void printSymbols(const ELFO *Obj, bool PrintSymbols, + bool PrintDynamicSymbols) override; void printDynamicRelocations(const ELFO *Obj) override; void printSymtabMessage(const ELFO *Obj, StringRef Name, size_t Offset) override; @@ -433,6 +432,7 @@ void printRelocHeader(unsigned SType); void printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, const Elf_Rela &R, bool IsRela); + void printDynamicSymbols(const ELFO *Obj); void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, StringRef StrTable, bool IsDynamic) override; std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol, @@ -456,8 +456,8 @@ void printRelocations(const ELFO *Obj) override; void printRelocations(const Elf_Shdr *Sec, const ELFO *Obj); void printSectionHeaders(const ELFO *Obj) override; - void printSymbols(const ELFO *Obj) override; - void printDynamicSymbols(const ELFO *Obj) override; + void printSymbols(const ELFO *Obj, bool PrintSymbols, + bool PrintDynamicSymbols) override; void printDynamicRelocations(const ELFO *Obj) override; void printProgramHeaders(const ELFO *Obj) override; void printHashHistogram(const ELFFile *Obj) override; @@ -471,6 +471,8 @@ private: void printRelocation(const ELFO *Obj, Elf_Rela Rel, const Elf_Shdr *SymTab); void printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel); + void printSymbols(const ELFO *Obj); + void printDynamicSymbols(const ELFO *Obj); void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, StringRef StrTable, bool IsDynamic) override; @@ -1619,14 +1621,11 @@ ELFDumperStyle->printDynamicRelocations(ObjF->getELFFile()); } -template -void ELFDumper::printSymbols() { - ELFDumperStyle->printSymbols(ObjF->getELFFile()); -} - -template -void ELFDumper::printDynamicSymbols() { - ELFDumperStyle->printDynamicSymbols(ObjF->getELFFile()); +template +void ELFDumper::printSymbols(bool PrintSymbols, + bool PrintDynamicSymbols) { + ELFDumperStyle->printSymbols(ObjF->getELFFile(), PrintSymbols, + PrintDynamicSymbols); } template void ELFDumper::printHashHistogram() { @@ -3167,11 +3166,14 @@ OS << "\n"; } -template void GNUStyle::printSymbols(const ELFO *Obj) { - if (opts::DynamicSymbols) +template +void GNUStyle::printSymbols(const ELFO *Obj, bool PrintSymbols, + bool PrintDynamicSymbols) { + if (!PrintSymbols && !PrintDynamicSymbols) return; this->dumper()->printSymbolsHelper(true); - this->dumper()->printSymbolsHelper(false); + if (PrintSymbols) + this->dumper()->printSymbolsHelper(false); } template @@ -4405,6 +4407,15 @@ W.printHex("Section", SectionName, SectionIndex); } +template +void LLVMStyle::printSymbols(const ELFO *Obj, bool PrintSymbols, + bool PrintDynamicSymbols) { + if (PrintSymbols) + printSymbols(Obj); + if (PrintDynamicSymbols) + printDynamicSymbols(Obj); +} + template void LLVMStyle::printSymbols(const ELFO *Obj) { ListScope Group(W, "Symbols"); this->dumper()->printSymbolsHelper(false); Index: tools/llvm-readobj/MachODumper.cpp =================================================================== --- tools/llvm-readobj/MachODumper.cpp +++ tools/llvm-readobj/MachODumper.cpp @@ -33,8 +33,7 @@ void printFileHeaders() override; void printSectionHeaders() override; void printRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override; + void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; void printUnwindInfo() override; void printStackMap() const override; @@ -52,6 +51,8 @@ template void printFileHeaders(const MachHeader &Header); + void printSymbols(); + void printDynamicSymbols(); void printSymbol(const SymbolRef &Symbol); void printRelocation(const RelocationRef &Reloc); @@ -590,6 +591,13 @@ } } +void MachODumper::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { + if (PrintSymbols) + printSymbols(); + if (PrintDynamicSymbols) + printDynamicSymbols(); +} + void MachODumper::printSymbols() { ListScope Group(W, "Symbols"); Index: tools/llvm-readobj/ObjDumper.h =================================================================== --- tools/llvm-readobj/ObjDumper.h +++ tools/llvm-readobj/ObjDumper.h @@ -34,8 +34,7 @@ virtual void printFileHeaders() = 0; virtual void printSectionHeaders() = 0; virtual void printRelocations() = 0; - virtual void printSymbols() = 0; - virtual void printDynamicSymbols() = 0; + virtual void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) = 0; virtual void printUnwindInfo() = 0; // Only implemented for ELF at this time. Index: tools/llvm-readobj/WasmDumper.cpp =================================================================== --- tools/llvm-readobj/WasmDumper.cpp +++ tools/llvm-readobj/WasmDumper.cpp @@ -48,12 +48,12 @@ void printFileHeaders() override; void printSectionHeaders() override; void printRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override { llvm_unreachable("unimplemented"); } + void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; void printUnwindInfo() override { llvm_unreachable("unimplemented"); } void printStackMap() const override { llvm_unreachable("unimplemented"); } protected: + void printSymbols(); void printSymbol(const SymbolRef &Sym); void printRelocation(const SectionRef &Section, const RelocationRef &Reloc); @@ -139,6 +139,13 @@ } } +void WasmDumper::printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { + if (PrintSymbols) + printSymbols(); + if (PrintDynamicSymbols) + llvm_unreachable("unimplemented"); +} + void WasmDumper::printSymbols() { ListScope Group(W, "Symbols"); Index: tools/llvm-readobj/llvm-readobj.h =================================================================== --- tools/llvm-readobj/llvm-readobj.h +++ tools/llvm-readobj/llvm-readobj.h @@ -51,7 +51,6 @@ extern llvm::cl::opt SectionRelocations; extern llvm::cl::opt SectionSymbols; extern llvm::cl::opt SectionData; - extern llvm::cl::opt DynamicSymbols; extern llvm::cl::opt ExpandRelocs; extern llvm::cl::opt RawRelr; extern llvm::cl::opt CodeViewSubsectionBytes; Index: tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- tools/llvm-readobj/llvm-readobj.cpp +++ tools/llvm-readobj/llvm-readobj.cpp @@ -457,10 +457,8 @@ Dumper->printRelocations(); if (opts::DynRelocs) Dumper->printDynamicRelocations(); - if (opts::Symbols) - Dumper->printSymbols(); - if (opts::DynamicSymbols) - Dumper->printDynamicSymbols(); + if (opts::Symbols || opts::DynamicSymbols) + Dumper->printSymbols(opts::Symbols, opts::DynamicSymbols); if (opts::UnwindInfo) Dumper->printUnwindInfo(); if (opts::DynamicTable)