Skip to content

Commit

Permalink
llvm-readobj: add support to dump (COFF) directives
Browse files Browse the repository at this point in the history
PE/COFF has a special section (.drectve) which can be used to pass options to
the linker (similar to LC_LINKER_OPTION).  Add support to llvm-readobj to print
the contents of the section for tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219228 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
compnerd committed Oct 7, 2014
1 parent b3a0758 commit db02fa5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/llvm-readobj/COFFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class COFFDumper : public ObjDumper {
void printDynamicSymbols() override;
void printUnwindInfo() override;
void printCOFFImports() override;
void printCOFFDirectives() override;

private:
void printSymbol(const SymbolRef &Sym);
Expand Down Expand Up @@ -932,3 +933,21 @@ void COFFDumper::printCOFFImports() {
printImportedSymbols(I->imported_symbol_begin(), I->imported_symbol_end());
}
}

void COFFDumper::printCOFFDirectives() {
for (const SectionRef &Section : Obj->sections()) {
StringRef Contents;
StringRef Name;

if (error(Section.getName(Name)))
continue;
if (Name != ".drectve")
continue;

if (error(Section.getContents(Contents)))
return;

W.printString("Directive(s)", Contents);
}
}

1 change: 1 addition & 0 deletions tools/llvm-readobj/ObjDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ObjDumper {

// Only implemented for PE/COFF.
virtual void printCOFFImports() { }
virtual void printCOFFDirectives() { }

protected:
StreamWriter& W;
Expand Down
7 changes: 7 additions & 0 deletions tools/llvm-readobj/llvm-readobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ namespace opts {
// -coff-imports
cl::opt<bool>
COFFImports("coff-imports", cl::desc("Display the PE/COFF import table"));

// -coff-directives
cl::opt<bool>
COFFDirectives("coff-directives",
cl::desc("Display the contents PE/COFF .drectve section"));
} // namespace opts

static int ReturnValue = EXIT_SUCCESS;
Expand Down Expand Up @@ -272,6 +277,8 @@ static void dumpObject(const ObjectFile *Obj) {
Dumper->printMipsPLTGOT();
if (opts::COFFImports)
Dumper->printCOFFImports();
if (opts::COFFDirectives)
Dumper->printCOFFDirectives();
}


Expand Down

0 comments on commit db02fa5

Please sign in to comment.