Index: COFF/Chunks.h =================================================================== --- COFF/Chunks.h +++ COFF/Chunks.h @@ -369,7 +369,7 @@ class LocalImportChunk : public Chunk { public: explicit LocalImportChunk(Defined *S) : Sym(S) { - Alignment = Config->is64() ? 8 : 4; + Alignment = Config->ptrSize(); } size_t getSize() const override; void getBaserels(std::vector *Res) override; Index: COFF/Chunks.cpp =================================================================== --- COFF/Chunks.cpp +++ COFF/Chunks.cpp @@ -679,9 +679,7 @@ Res->emplace_back(getRVA()); } -size_t LocalImportChunk::getSize() const { - return Config->is64() ? 8 : 4; -} +size_t LocalImportChunk::getSize() const { return Config->ptrSize(); } void LocalImportChunk::writeTo(uint8_t *Buf) const { if (Config->is64()) { @@ -845,9 +843,7 @@ } // MinGW specific. -size_t AbsolutePointerChunk::getSize() const { - return Config->is64() ? 8 : 4; -} +size_t AbsolutePointerChunk::getSize() const { return Config->ptrSize(); } void AbsolutePointerChunk::writeTo(uint8_t *Buf) const { if (Config->is64()) { Index: COFF/Config.h =================================================================== --- COFF/Config.h +++ COFF/Config.h @@ -82,6 +82,7 @@ struct Configuration { enum ManifestKind { SideBySide, Embed, No }; bool is64() { return Machine == AMD64 || Machine == ARM64; } + size_t ptrSize() { return is64() ? 8 : 4; } llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN; bool Verbose = false; Index: COFF/DLL.cpp =================================================================== --- COFF/DLL.cpp +++ COFF/DLL.cpp @@ -35,8 +35,6 @@ // Import table -static int ptrSize() { return Config->is64() ? 8 : 4; } - // A chunk for the import descriptor table. class HintNameChunk : public Chunk { public: @@ -61,8 +59,10 @@ // A chunk for the import descriptor table. class LookupChunk : public Chunk { public: - explicit LookupChunk(Chunk *C) : HintName(C) { Alignment = ptrSize(); } - size_t getSize() const override { return ptrSize(); } + explicit LookupChunk(Chunk *C) : HintName(C) { + Alignment = Config->ptrSize(); + } + size_t getSize() const override { return Config->ptrSize(); } void writeTo(uint8_t *Buf) const override { write32le(Buf + OutputSectionOff, HintName->getRVA()); @@ -76,8 +76,10 @@ // See Microsoft PE/COFF spec 7.1. Import Header for details. class OrdinalOnlyChunk : public Chunk { public: - explicit OrdinalOnlyChunk(uint16_t V) : Ordinal(V) { Alignment = ptrSize(); } - size_t getSize() const override { return ptrSize(); } + explicit OrdinalOnlyChunk(uint16_t V) : Ordinal(V) { + Alignment = Config->ptrSize(); + } + size_t getSize() const override { return Config->ptrSize(); } void writeTo(uint8_t *Buf) const override { // An import-by-ordinal slot has MSB 1 to indicate that @@ -353,8 +355,10 @@ // A chunk for the import descriptor table. class DelayAddressChunk : public Chunk { public: - explicit DelayAddressChunk(Chunk *C) : Thunk(C) { Alignment = ptrSize(); } - size_t getSize() const override { return ptrSize(); } + explicit DelayAddressChunk(Chunk *C) : Thunk(C) { + Alignment = Config->ptrSize(); + } + size_t getSize() const override { return Config->ptrSize(); } void writeTo(uint8_t *Buf) const override { if (Config->is64()) { @@ -493,8 +497,8 @@ Hints.push_back(C); } // Terminate with null values. - Lookups.push_back(make(ptrSize())); - Addresses.push_back(make(ptrSize())); + Lookups.push_back(make(Config->ptrSize())); + Addresses.push_back(make(Config->ptrSize())); for (int I = 0, E = Syms.size(); I < E; ++I) Syms[I]->setLocation(Addresses[Base + I]); Index: COFF/SymbolTable.cpp =================================================================== --- COFF/SymbolTable.cpp +++ COFF/SymbolTable.cpp @@ -187,8 +187,7 @@ // for __imp_ instead, and drop the whole .refptr. chunk. DefinedRegular *Refptr = dyn_cast_or_null(find((".refptr." + Name).str())); - size_t PtrSize = Config->is64() ? 8 : 4; - if (Refptr && Refptr->getChunk()->getSize() == PtrSize) { + if (Refptr && Refptr->getChunk()->getSize() == Config->ptrSize()) { SectionChunk *SC = dyn_cast_or_null(Refptr->getChunk()); if (SC && SC->Relocs.size() == 1 && *SC->symbols().begin() == Sym) { log("Replacing .refptr." + Name + " with " + Imp->getName());