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) {}
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();
}
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;
std::error_code COFFObjectFile::getSymbolName(COFFSymbolRef Symbol,
StringRef &Res) const {
+ return getSymbolName(Symbol.getGeneric(), Res);
+}
+
+std::error_code COFFObjectFile::getSymbolName(const coff_symbol_generic *Symbol,
+ StringRef &Res) const {
// Check for string table entry. First 4 bytes are 0.
- if (Symbol.getStringTableOffset().Zeroes == 0) {
- uint32_t Offset = Symbol.getStringTableOffset().Offset;
- if (std::error_code EC = getString(Offset, Res))
+ if (Symbol->Name.Offset.Zeroes == 0) {
+ if (std::error_code EC = getString(Symbol->Name.Offset.Offset, Res))
return EC;
return std::error_code();
}
- if (Symbol.getShortName()[COFF::NameSize - 1] == 0)
+ if (Symbol->Name.ShortName[COFF::NameSize - 1] == 0)
// Null terminated, let ::strlen figure out the length.
- Res = StringRef(Symbol.getShortName());
+ Res = StringRef(Symbol->Name.ShortName);
else
// Not null terminated, use all 8 bytes.
- Res = StringRef(Symbol.getShortName(), COFF::NameSize);
+ Res = StringRef(Symbol->Name.ShortName, COFF::NameSize);
return std::error_code();
}