From: Saleem Abdulrasool <compnerd@compnerd.org>
Date: Tue, 7 Oct 2014 19:37:52 +0000 (+0000)
Subject: llvm-readobj: add support to dump (COFF) directives
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=db02fa5a110329535dda8c059549f2eed406d481;p=oota-llvm.git

llvm-readobj: add support to dump (COFF) directives

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
---

diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index 8e7fcc06c1b..84cd9a689e3 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -56,6 +56,7 @@ public:
   void printDynamicSymbols() override;
   void printUnwindInfo() override;
   void printCOFFImports() override;
+  void printCOFFDirectives() override;
 
 private:
   void printSymbol(const SymbolRef &Sym);
@@ -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);
+  }
+}
+
diff --git a/tools/llvm-readobj/ObjDumper.h b/tools/llvm-readobj/ObjDumper.h
index 8f0c171233e..b898224a44d 100644
--- a/tools/llvm-readobj/ObjDumper.h
+++ b/tools/llvm-readobj/ObjDumper.h
@@ -45,6 +45,7 @@ public:
 
   // Only implemented for PE/COFF.
   virtual void printCOFFImports() { }
+  virtual void printCOFFDirectives() { }
 
 protected:
   StreamWriter& W;
diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp
index 31a011d2b9e..55eadd887c7 100644
--- a/tools/llvm-readobj/llvm-readobj.cpp
+++ b/tools/llvm-readobj/llvm-readobj.cpp
@@ -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;
@@ -272,6 +277,8 @@ static void dumpObject(const ObjectFile *Obj) {
       Dumper->printMipsPLTGOT();
   if (opts::COFFImports)
     Dumper->printCOFFImports();
+  if (opts::COFFDirectives)
+    Dumper->printCOFFDirectives();
 }