[lld] r344265 - [COFF] Add and use a Wordsize field in Config. NFCI.

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 10:45:58 PDT 2018


Author: mstorsjo
Date: Thu Oct 11 10:45:58 2018
New Revision: 344265

URL: http://llvm.org/viewvc/llvm-project?rev=344265&view=rev
Log:
[COFF] Add and use a Wordsize field in Config. NFCI.

Differential Revision: https://reviews.llvm.org/D53143

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/Chunks.h
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/DLL.cpp
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/SymbolTable.cpp

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=344265&r1=344264&r2=344265&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu Oct 11 10:45:58 2018
@@ -675,9 +675,7 @@ void LocalImportChunk::getBaserels(std::
   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) c
 }
 
 // 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()) {

Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=344265&r1=344264&r2=344265&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Thu Oct 11 10:45:58 2018
@@ -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;

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=344265&r1=344264&r2=344265&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Thu Oct 11 10:45:58 2018
@@ -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;

Modified: lld/trunk/COFF/DLL.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DLL.cpp?rev=344265&r1=344264&r2=344265&view=diff
==============================================================================
--- lld/trunk/COFF/DLL.cpp (original)
+++ lld/trunk/COFF/DLL.cpp Thu Oct 11 10:45:58 2018
@@ -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]);

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=344265&r1=344264&r2=344265&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Oct 11 10:45:58 2018
@@ -1367,6 +1367,7 @@ void LinkerDriver::link(ArrayRef<const c
     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,

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=344265&r1=344264&r2=344265&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Oct 11 10:45:58 2018
@@ -187,8 +187,7 @@ bool SymbolTable::handleMinGWAutomaticIm
   // 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());




More information about the llvm-commits mailing list