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 @@ -6,6 +6,8 @@ RUN: | FileCheck %s -check-prefixes=SYMTAB,DYN RUN: llvm-readobj -dyn-symbols %p/Inputs/gnuhash.so.elf-x86_64 --elf-output-style=GNU \ RUN: | FileCheck %s -check-prefixes=NO-SYMTAB,DYN +RUN: llvm-readobj -symbols -dyn-symbols %p/Inputs/gnuhash.so.elf-x86_64 --elf-output-style=GNU \ +RUN: | FileCheck %s -check-prefixes=SYMTAB,DYN ELF32: Symbol table '.symtab' contains 5 entries: ELF32-NEXT: Num: Value Size Type Bind Vis Ndx Name @@ -26,7 +28,7 @@ NO-SYMTAB-NOT: Symbol table '.symtab' -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 @@ -34,6 +36,7 @@ DYN-NEXT: 3: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 _end DYN-NEXT: 4: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 __bss_start +DYN-NOT: .dynsym NO-SYMTAB-NOT: Symbol table '.symtab' SYMTAB: Symbol table '.symtab' contains 12 entries: @@ -50,3 +53,5 @@ SYMTAB-NEXT: 9: 00000000000001b8 0 NOTYPE GLOBAL DEFAULT 4 foo SYMTAB-NEXT: 10: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 _edata SYMTAB-NEXT: 11: 0000000000200268 0 NOTYPE GLOBAL DEFAULT 5 _end + +DYN-NOT: .dynsym Index: tools/llvm-readobj/COFFDumper.cpp =================================================================== --- tools/llvm-readobj/COFFDumper.cpp +++ tools/llvm-readobj/COFFDumper.cpp @@ -80,8 +80,6 @@ void printFileHeaders() override; void printSectionHeaders() override; void printRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override; void printUnwindInfo() override; void printNeededLibraries() override; @@ -100,6 +98,8 @@ void printStackMap() const override; void printAddrsig() override; private: + void printSymbols() override; + void printDynamicSymbols() override; void printSymbol(const SymbolRef &Sym); void printRelocation(const SectionRef &Section, const RelocationRef &Reloc, uint64_t Bias = 0); 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 printHashSymbols() override; void printUnwindInfo() override; @@ -329,8 +328,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 printHashSymbols(const ELFFile *Obj) {} virtual void printDynamicRelocations(const ELFFile *Obj) = 0; virtual void printSymtabMessage(const ELFFile *Obj, StringRef Name, @@ -365,8 +364,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 printHashSymbols(const ELFO *Obj) override; void printDynamicRelocations(const ELFO *Obj) override; void printSymtabMessage(const ELFO *Obj, StringRef Name, @@ -459,8 +458,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; @@ -474,6 +473,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; @@ -1622,14 +1623,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 @@ -3175,16 +3173,14 @@ OS << "\n"; } -template void GNUStyle::printSymbols(const ELFO *Obj) { - if (opts::DynamicSymbols) - return; - this->dumper()->printSymbolsHelper(true); - this->dumper()->printSymbolsHelper(false); -} - template -void GNUStyle::printDynamicSymbols(const ELFO *Obj) { +void GNUStyle::printSymbols(const ELFO *Obj, bool PrintSymbols, + bool PrintDynamicSymbols) { + if (!PrintSymbols && !PrintDynamicSymbols) + return; this->dumper()->printSymbolsHelper(true); + if (PrintSymbols) + this->dumper()->printSymbolsHelper(false); } template void GNUStyle::printHashSymbols(const ELFO *Obj) { @@ -4413,6 +4409,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,6 @@ void printFileHeaders() override; void printSectionHeaders() override; void printRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override; void printUnwindInfo() override; void printStackMap() const override; @@ -52,6 +50,8 @@ template void printFileHeaders(const MachHeader &Header); + void printSymbols() override; + void printDynamicSymbols() override; void printSymbol(const SymbolRef &Symbol); void printRelocation(const RelocationRef &Reloc); Index: tools/llvm-readobj/ObjDumper.h =================================================================== --- tools/llvm-readobj/ObjDumper.h +++ tools/llvm-readobj/ObjDumper.h @@ -34,8 +34,12 @@ 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) { + if (PrintSymbols) + printSymbols(); + if (PrintDynamicSymbols) + printDynamicSymbols(); + } virtual void printUnwindInfo() = 0; // Only implemented for ELF at this time. @@ -93,6 +97,10 @@ protected: ScopedPrinter &W; + +private: + virtual void printSymbols() {}; + virtual void printDynamicSymbols() {}; }; std::error_code createCOFFDumper(const object::ObjectFile *Obj, Index: tools/llvm-readobj/WasmDumper.cpp =================================================================== --- tools/llvm-readobj/WasmDumper.cpp +++ tools/llvm-readobj/WasmDumper.cpp @@ -48,8 +48,6 @@ void printFileHeaders() override; void printSectionHeaders() override; void printRelocations() override; - void printSymbols() override; - void printDynamicSymbols() override { llvm_unreachable("unimplemented"); } void printUnwindInfo() override { llvm_unreachable("unimplemented"); } void printStackMap() const override { llvm_unreachable("unimplemented"); } @@ -58,6 +56,9 @@ void printRelocation(const SectionRef &Section, const RelocationRef &Reloc); private: + void printSymbols() override; + void printDynamicSymbols() override { llvm_unreachable("unimplemented"); } + const WasmObjectFile *Obj; }; 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 @@ -462,10 +462,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::HashSymbols) Dumper->printHashSymbols(); if (opts::UnwindInfo)