[llvm] r206126 - tools: teach objdump about FILE aux records

Saleem Abdulrasool compnerd at compnerd.org
Sat Apr 12 20:11:09 PDT 2014


Author: compnerd
Date: Sat Apr 12 22:11:08 2014
New Revision: 206126

URL: http://llvm.org/viewvc/llvm-project?rev=206126&view=rev
Log:
tools: teach objdump about FILE aux records

Add support for file auxiliary symbol entries in COFF symbol tables.  A COFF
symbol table with a FILE entry is followed by sizeof(__FILE__) / 18 auxiliary
symbol records which contain the filename.  Read them and form the original
filename that the record contains.  Then display the name in the output.

Added:
    llvm/trunk/test/tools/llvm-objdump/Inputs/file.obj.coff-arm   (with props)
    llvm/trunk/test/tools/llvm-objdump/coff-file.test
Modified:
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=206126&r1=206125&r2=206126&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Sat Apr 12 22:11:08 2014
@@ -287,6 +287,10 @@ struct coff_aux_weak_external {
   char Unused[10];
 };
 
+struct coff_aux_file {
+  char FileName[18];
+};
+
 struct coff_aux_section_definition {
   support::ulittle32_t Length;
   support::ulittle16_t NumberOfRelocations;

Added: llvm/trunk/test/tools/llvm-objdump/Inputs/file.obj.coff-arm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/Inputs/file.obj.coff-arm?rev=206126&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-objdump/Inputs/file.obj.coff-arm (added) and llvm/trunk/test/tools/llvm-objdump/Inputs/file.obj.coff-arm Sat Apr 12 22:11:08 2014 differ

Propchange: llvm/trunk/test/tools/llvm-objdump/Inputs/file.obj.coff-arm
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/llvm-objdump/coff-file.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/coff-file.test?rev=206126&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/coff-file.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/coff-file.test Sat Apr 12 22:11:08 2014
@@ -0,0 +1,5 @@
+RUN: llvm-objdump -t %p/Inputs/file.obj.coff-arm | FileCheck %s
+
+CHECK: .file
+CHECK-NEXT: AUX /Users/compnerd/work/llvm/test/tools/llvm-readobj/Inputs/file.asm
+

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=206126&r1=206125&r2=206126&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Sat Apr 12 22:11:08 2014
@@ -669,11 +669,21 @@ static void PrintCOFFSymbolTable(const C
   const coff_symbol *symbol = 0;
   for (int i = 0, e = header->NumberOfSymbols; i != e; ++i) {
     if (aux_count--) {
-      // Figure out which type of aux this is.
-      if (symbol->isSectionDefinition()) { // Section definition.
+      switch (symbol->StorageClass) {
+      default: outs() << "AUX Unknown\n";
+      case COFF::IMAGE_SYM_CLASS_STATIC:
+        // Section definition.  Follows a symbol-table record that defines a
+        // section.  Such a record has a symbol name that is the name of a
+        // section and has storage class STATIC (3).
+        if (symbol->Value) {
+          errs() << "invalid entry in Symbol Table";
+          break;
+        }
+
         const coff_aux_section_definition *asd;
         if (error(coff->getAuxSymbol<coff_aux_section_definition>(i, asd)))
           return;
+
         outs() << "AUX "
                << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
                          , unsigned(asd->Length)
@@ -683,8 +693,20 @@ static void PrintCOFFSymbolTable(const C
                << format("assoc %d comdat %d\n"
                          , unsigned(asd->Number)
                          , unsigned(asd->Selection));
-      } else
-        outs() << "AUX Unknown\n";
+        break;
+      case COFF::IMAGE_SYM_CLASS_FILE:
+        SmallString<261> FileName;
+        for (unsigned AI = i, AE = i + aux_count + 1; AI < AE; ++AI) {
+          const coff_aux_file *AF;
+          if (error(coff->getAuxSymbol<coff_aux_file>(AI, AF)))
+            return;
+          FileName.append(&AF->FileName[0], &AF->FileName[18]);
+        }
+        outs() << "AUX " << FileName << '\n';
+        i = i + aux_count;
+        aux_count = 0;
+        break;
+      }
     } else {
       StringRef name;
       if (error(coff->getSymbol(i, symbol))) return;





More information about the llvm-commits mailing list