diff options
| author | Martin Storsjo <martin@martin.st> | 2018-10-11 17:45:58 +0000 |
|---|---|---|
| committer | Martin Storsjo <martin@martin.st> | 2018-10-11 17:45:58 +0000 |
| commit | 8cc0f7126144d0336c78c3fa89ddb4f0a0ac0757 (patch) | |
| tree | 02b7687dea81c2266b6e75cc315a17819ad683f1 | |
| parent | 21eb363302bec770adf67b2494aa30ff2bcf5d65 (diff) | |
| download | bcm5719-llvm-8cc0f7126144d0336c78c3fa89ddb4f0a0ac0757.tar.gz bcm5719-llvm-8cc0f7126144d0336c78c3fa89ddb4f0a0ac0757.zip | |
[COFF] Add and use a Wordsize field in Config. NFCI.
Differential Revision: https://reviews.llvm.org/D53143
llvm-svn: 344265
| -rw-r--r-- | lld/COFF/Chunks.cpp | 8 | ||||
| -rw-r--r-- | lld/COFF/Chunks.h | 2 | ||||
| -rw-r--r-- | lld/COFF/Config.h | 1 | ||||
| -rw-r--r-- | lld/COFF/DLL.cpp | 22 | ||||
| -rw-r--r-- | lld/COFF/Driver.cpp | 1 | ||||
| -rw-r--r-- | lld/COFF/SymbolTable.cpp | 3 |
6 files changed, 18 insertions, 19 deletions
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 5fb33e1190c..9808c8be6b3 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -675,9 +675,7 @@ void LocalImportChunk::getBaserels(std::vector<Baserel> *Res) { Res->emplace_back(getRVA()); } -size_t LocalImportChunk::getSize() const { - return Config->is64() ? 8 : 4; -} +size_t LocalImportChunk::getSize() const { return Config->Wordsize; } void LocalImportChunk::writeTo(uint8_t *Buf) const { if (Config->is64()) { @@ -841,9 +839,7 @@ void MergeChunk::writeTo(uint8_t *Buf) const { } // MinGW specific. -size_t AbsolutePointerChunk::getSize() const { - return Config->is64() ? 8 : 4; -} +size_t AbsolutePointerChunk::getSize() const { return Config->Wordsize; } void AbsolutePointerChunk::writeTo(uint8_t *Buf) const { if (Config->is64()) { diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index 64a6626e194..5f2d8067c01 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -369,7 +369,7 @@ public: class LocalImportChunk : public Chunk { public: explicit LocalImportChunk(Defined *S) : Sym(S) { - Alignment = Config->is64() ? 8 : 4; + Alignment = Config->Wordsize; } size_t getSize() const override; void getBaserels(std::vector<Baserel> *Res) override; diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h index e639b77c48f..12b74c799db 100644 --- a/lld/COFF/Config.h +++ b/lld/COFF/Config.h @@ -84,6 +84,7 @@ struct Configuration { bool is64() { return Machine == AMD64 || Machine == ARM64; } llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN; + size_t Wordsize; bool Verbose = false; WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; Symbol *Entry = nullptr; diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp index 093eaa5e4f6..235cfa78ba9 100644 --- a/lld/COFF/DLL.cpp +++ b/lld/COFF/DLL.cpp @@ -35,8 +35,6 @@ namespace { // 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,8 @@ private: // 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->Wordsize; } + size_t getSize() const override { return Config->Wordsize; } void writeTo(uint8_t *Buf) const override { write32le(Buf + OutputSectionOff, HintName->getRVA()); @@ -76,8 +74,10 @@ public: // 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->Wordsize; + } + size_t getSize() const override { return Config->Wordsize; } void writeTo(uint8_t *Buf) const override { // An import-by-ordinal slot has MSB 1 to indicate that @@ -353,8 +353,10 @@ public: // 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->Wordsize; + } + size_t getSize() const override { return Config->Wordsize; } void writeTo(uint8_t *Buf) const override { if (Config->is64()) { @@ -493,8 +495,8 @@ void IdataContents::create() { Hints.push_back(C); } // Terminate with null values. - Lookups.push_back(make<NullChunk>(ptrSize())); - Addresses.push_back(make<NullChunk>(ptrSize())); + Lookups.push_back(make<NullChunk>(Config->Wordsize)); + Addresses.push_back(make<NullChunk>(Config->Wordsize)); for (int I = 0, E = Syms.size(); I < E; ++I) Syms[I]->setLocation(Addresses[Base + I]); diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index ce6d4ac6e3b..78b47040e03 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1367,6 +1367,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { warn("/machine is not specified. x64 is assumed"); Config->Machine = AMD64; } + Config->Wordsize = Config->is64() ? 8 : 4; // Input files can be Windows resource files (.res files). We use // WindowsResource to convert resource files to a regular COFF file, diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index f451beb63b0..2e5f00af3c4 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -187,8 +187,7 @@ bool SymbolTable::handleMinGWAutomaticImport(Symbol *Sym, StringRef Name) { // for __imp_<name> instead, and drop the whole .refptr.<name> chunk. DefinedRegular *Refptr = dyn_cast_or_null<DefinedRegular>(find((".refptr." + Name).str())); - size_t PtrSize = Config->is64() ? 8 : 4; - if (Refptr && Refptr->getChunk()->getSize() == PtrSize) { + if (Refptr && Refptr->getChunk()->getSize() == Config->Wordsize) { SectionChunk *SC = dyn_cast_or_null<SectionChunk>(Refptr->getChunk()); if (SC && SC->Relocs.size() == 1 && *SC->symbols().begin() == Sym) { log("Replacing .refptr." + Name + " with " + Imp->getName()); |

