Index: COFF/Symbols.h =================================================================== --- COFF/Symbols.h +++ COFF/Symbols.h @@ -131,15 +131,18 @@ friend SymbolBody; public: DefinedCOFF(Kind K, ObjectFile *F, COFFSymbolRef S) - : Defined(K), File(F), Sym(S) {} + : Defined(K), File(F), Sym(S.getRawPtr()) {} static bool classof(const SymbolBody *S) { return S->kind() <= LastDefinedCOFFKind; } + // Returns Sym->getValue() + uint32_t getValue(); + protected: ObjectFile *File; - COFFSymbolRef Sym; + const void *Sym; }; // Regular defined symbols read from object file symbol tables. @@ -147,7 +150,7 @@ public: DefinedRegular(ObjectFile *F, COFFSymbolRef S, SectionChunk *C) : DefinedCOFF(DefinedRegularKind, F, S), Data(&C->Ptr) { - IsExternal = Sym.isExternal(); + IsExternal = S.isExternal(); IsCOMDAT = C->isCOMDAT(); } @@ -156,15 +159,14 @@ } uint64_t getFileOff() { - return (*Data)->getFileOff() + Sym.getValue(); + return (*Data)->getFileOff() + getValue(); } - uint64_t getRVA() { return (*Data)->getRVA() + Sym.getValue(); } + uint64_t getRVA() { return (*Data)->getRVA() + getValue(); } bool isCOMDAT() { return IsCOMDAT; } bool isLive() const { return (*Data)->isLive(); } void markLive() { (*Data)->markLive(); } SectionChunk *getChunk() { return *Data; } - uint64_t getValue() { return Sym.getValue(); } private: SectionChunk **Data; @@ -174,7 +176,7 @@ public: DefinedCommon(ObjectFile *F, COFFSymbolRef S, CommonChunk *C) : DefinedCOFF(DefinedCommonKind, F, S), Data(C) { - IsExternal = Sym.isExternal(); + IsExternal = S.isExternal(); } static bool classof(const SymbolBody *S) { @@ -187,7 +189,7 @@ private: friend SymbolBody; - uint64_t getSize() { return Sym.getValue(); } + uint64_t getSize() { return getValue(); } CommonChunk *Data; }; Index: COFF/Symbols.cpp =================================================================== --- COFF/Symbols.cpp +++ COFF/Symbols.cpp @@ -31,7 +31,8 @@ // is a waste of time. if (Name.empty()) { auto *D = cast(this); - D->File->getCOFFObj()->getSymbolName(D->Sym, Name); + auto *Sym = reinterpret_cast(D->Sym); + D->File->getCOFFObj()->getSymbolName(COFFSymbolRef(Sym), Name); } return Name; } @@ -142,6 +143,16 @@ return N; } +uint32_t DefinedCOFF::getValue() { + // Sym points to either coff_symbol16 or coff_symbol32. + // getValue() returns the same value whichever we cast to because + // the value field starts at the same offset for 32 and 64 bits. + // (We don't want to store SymbolRef to DefinedCOFF because SymbolRef + // is one pointer larger than void *.) + COFFSymbolRef S(reinterpret_cast(Sym)); + return S.getValue(); +} + uint64_t Defined::getRVA() { switch (kind()) { case DefinedAbsoluteKind: