[llvm-commits] PATCH: Adding accessors to llvm::Object:COFFObjectFile

Michael Spencer bigcheesegs at gmail.com
Thu Jun 14 17:35:05 PDT 2012


On Thu, Jun 14, 2012 at 5:16 PM, Marshall Clow <mclow.lists at gmail.com> wrote:
> So that clients can (if they need to) get at the underlying structures in the file
>
> Adds three new routines:
>
> error_code getCOFFSection(section_iterator &It, const coff_section *&section) const;
> error_code getCOFFSymbol(symbol_iterator &It, const coff_symbol *&symbol) const;
> error_code getSymbolAuxData(const coff_symbol *symbol,  ArrayRef<uint8_t> &Data) const;
>
> -- Marshall
>
> Marshall Clow     Idio Software   <mailto:mclow.lists at gmail.com>
>
> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
>        -- Yu Suzuki
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>

Index: include/llvm/Object/COFF.h
===================================================================
--- include/llvm/Object/COFF.h	(revision 158453)
+++ include/llvm/Object/COFF.h	(working copy)
@@ -168,6 +168,9 @@
   virtual section_iterator begin_sections() const;
   virtual section_iterator end_sections() const;

+  error_code getCOFFSection(section_iterator &It, const coff_section
*&section) const;
+  error_code getCOFFSymbol(symbol_iterator &It, const coff_symbol
*&symbol) const;
+

These are nofail operations, they don't need error_code. They should
just return the pointer.

   virtual uint8_t getBytesInAddress() const;
   virtual StringRef getFileFormatName() const;
   virtual unsigned getArch() const;
@@ -184,6 +187,9 @@
     return ec;
   }
   error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const;
+  error_code getSymbolAuxData(const coff_symbol *symbol,
+                                ArrayRef<uint8_t> &Data) const;
+
   error_code getSectionName(const coff_section *Sec, StringRef &Res) const;
   error_code getSectionContents(const coff_section *Sec,
                                 ArrayRef<uint8_t> &Res) const;
Index: lib/Object/COFFObjectFile.cpp
===================================================================
--- lib/Object/COFFObjectFile.cpp	(revision 158453)
+++ lib/Object/COFFObjectFile.cpp	(working copy)
@@ -622,6 +622,15 @@
   return object_error::success;
 }

+error_code COFFObjectFile::getSymbolAuxData(const coff_symbol *symbol,
+                                ArrayRef<uint8_t> &Data) const {
+// AUX data comes immediately after the symbol in COFF
+  Data = ArrayRef<uint8_t>(
+    reinterpret_cast<const uint8_t *>(symbol + 1),
+    symbol->NumberOfAuxSymbols * sizeof(coff_symbol));

This should verify the NumberOfAuxSymbols is valid and does not cause
Data to reference non-symboltable data.

+  return object_error::success;
+}
+
 error_code COFFObjectFile::getSectionName(const coff_section *Sec,
                                           StringRef &Res) const {
   StringRef Name;
@@ -694,6 +703,19 @@
   return object_error::success;
 }

+error_code COFFObjectFile::getCOFFSection(
+               section_iterator &It, const coff_section *&section) const {
+  section = toSec(It->getRawDataRefImpl());
+  return object_error::success;
+}
+
+error_code COFFObjectFile::getCOFFSymbol(
+               symbol_iterator &It, const coff_symbol *&symbol) const {
+  symbol = toSymb(It->getRawDataRefImpl());
+  return object_error::success;
+}
+
+
 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
   case COFF::enum: res = #enum; break;

With those changes it looks good to me.

- Michael Spencer




More information about the llvm-commits mailing list