[PATCH] Object/COFF: Define coff_symbol_generic
Rui Ueyama
ruiu at google.com
Mon Jun 29 16:03:01 PDT 2015
Hi majnemer,
If you need only Name and Value fields in a COFF symbol,
this data structure is one pointer smaller (or half of) COFFSymbolRef.
I'll use this class in LLD because we create millions of instances
for symbols read from the symbol table, and the size of the symbol
reference actually matters.
http://reviews.llvm.org/D10819
Files:
include/llvm/Object/COFF.h
lib/Object/COFFObjectFile.cpp
Index: include/llvm/Object/COFF.h
===================================================================
--- include/llvm/Object/COFF.h
+++ include/llvm/Object/COFF.h
@@ -249,6 +249,15 @@
typedef coff_symbol<support::ulittle16_t> coff_symbol16;
typedef coff_symbol<support::ulittle32_t> coff_symbol32;
+// Contains only common parts of coff_symbol16 and coff_symbol32.
+struct coff_symbol_generic {
+ union {
+ char ShortName[COFF::NameSize];
+ StringTableOffset Offset;
+ } Name;
+ support::ulittle32_t Value;
+};
+
class COFFSymbolRef {
public:
COFFSymbolRef(const coff_symbol16 *CS) : CS16(CS), CS32(nullptr) {}
@@ -259,6 +268,12 @@
return CS16 ? static_cast<const void *>(CS16) : CS32;
}
+ const coff_symbol_generic *getGeneric() const {
+ if (CS16)
+ return reinterpret_cast<const coff_symbol_generic *>(CS16);
+ return reinterpret_cast<const coff_symbol_generic *>(CS32);
+ }
+
friend bool operator<(COFFSymbolRef A, COFFSymbolRef B) {
return A.getRawPtr() < B.getRawPtr();
}
@@ -745,6 +760,8 @@
return std::error_code();
}
std::error_code getSymbolName(COFFSymbolRef Symbol, StringRef &Res) const;
+ std::error_code getSymbolName(const coff_symbol_generic *Symbol,
+ StringRef &Res) const;
ArrayRef<uint8_t> getSymbolAuxData(COFFSymbolRef Symbol) const;
Index: lib/Object/COFFObjectFile.cpp
===================================================================
--- lib/Object/COFFObjectFile.cpp
+++ lib/Object/COFFObjectFile.cpp
@@ -864,6 +864,12 @@
return std::error_code();
}
+std::error_code COFFObjectFile::getSymbolName(const coff_symbol_generic *Symbol,
+ StringRef &Res) const {
+ COFFSymbolRef S(reinterpret_cast<const coff_symbol16 *>(Symbol));
+ return getSymbolName(S, Res);
+}
+
ArrayRef<uint8_t>
COFFObjectFile::getSymbolAuxData(COFFSymbolRef Symbol) const {
const uint8_t *Aux = nullptr;
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10819.28721.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150629/a904583a/attachment.bin>
More information about the llvm-commits
mailing list