[lld] r313204 - Remove {get, set}Align accessor functions and use Alignment member variable instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 14:54:55 PDT 2017


Author: ruiu
Date: Wed Sep 13 14:54:55 2017
New Revision: 313204

URL: http://llvm.org/viewvc/llvm-project?rev=313204&view=rev
Log:
Remove {get,set}Align accessor functions and use Alignment member variable instead.

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/Chunks.h
    lld/trunk/COFF/DLL.cpp
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/ICF.cpp
    lld/trunk/COFF/MapFile.cpp
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Wed Sep 13 14:54:55 2017
@@ -36,7 +36,7 @@ SectionChunk::SectionChunk(ObjFile *F, c
   // Initialize SectionName.
   File->getCOFFObj()->getSectionName(Header, SectionName);
 
-  Align = Header->getAlignment();
+  Alignment = Header->getAlignment();
 
   // Chunks may be discarded during comdat merging.
   Discarded = false;
@@ -374,11 +374,7 @@ void SectionChunk::replace(SectionChunk
 CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) {
   // Common symbols are aligned on natural boundaries up to 32 bytes.
   // This is what MSVC link.exe does.
-  Align = std::min(uint64_t(32), PowerOf2Ceil(Sym.getValue()));
-}
-
-void CommonChunk::setAlign(uint32_t NewAlign) {
-  Align = std::max(Align, NewAlign);
+  Alignment = std::min(uint64_t(32), PowerOf2Ceil(Sym.getValue()));
 }
 
 uint32_t CommonChunk::getPermissions() const {
@@ -393,7 +389,7 @@ void StringChunk::writeTo(uint8_t *Buf)
 ImportThunkChunkX64::ImportThunkChunkX64(Defined *S) : ImpSymbol(S) {
   // Intel Optimization Manual says that all branch targets
   // should be 16-byte aligned. MSVC linker does this too.
-  Align = 16;
+  Alignment = 16;
 }
 
 void ImportThunkChunkX64::writeTo(uint8_t *Buf) const {

Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Wed Sep 13 14:54:55 2017
@@ -62,7 +62,6 @@ public:
 
   // The writer sets and uses the addresses.
   uint64_t getRVA() const { return RVA; }
-  uint32_t getAlign() const { return Align; }
   void setRVA(uint64_t V) { RVA = V; }
 
   // Returns true if this has non-zero data. BSS chunks return
@@ -92,23 +91,22 @@ public:
   // bytes, so this is used only for logging or debugging.
   virtual StringRef getDebugName() { return ""; }
 
+  // The alignment of this chunk. The writer uses the value.
+  uint32_t Alignment = 1;
+
 protected:
   Chunk(Kind K = OtherKind) : ChunkKind(K) {}
   const Kind ChunkKind;
 
-  // The alignment of this chunk. The writer uses the value.
-  uint32_t Align = 1;
-
   // The RVA of this chunk in the output. The writer sets a value.
   uint64_t RVA = 0;
 
+  // The output section for this chunk.
+  OutputSection *Out = nullptr;
+
 public:
   // The offset from beginning of the output section. The writer sets a value.
   uint64_t OutputSectionOff = 0;
-
-protected:
-  // The output section for this chunk.
-  OutputSection *Out = nullptr;
 };
 
 // A chunk corresponding a section of an input file.
@@ -243,7 +241,6 @@ public:
   bool hasData() const override { return false; }
   uint32_t getPermissions() const override;
   StringRef getSectionName() const override { return ".bss"; }
-  void setAlign(uint32_t NewAlign);
 
 private:
   const COFFSymbolRef Sym;

Modified: lld/trunk/COFF/DLL.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DLL.cpp?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/DLL.cpp (original)
+++ lld/trunk/COFF/DLL.cpp Wed Sep 13 14:54:55 2017
@@ -61,7 +61,7 @@ private:
 // A chunk for the import descriptor table.
 class LookupChunk : public Chunk {
 public:
-  explicit LookupChunk(Chunk *C) : HintName(C) { Align = ptrSize(); }
+  explicit LookupChunk(Chunk *C) : HintName(C) { Alignment = ptrSize(); }
   size_t getSize() const override { return ptrSize(); }
 
   void writeTo(uint8_t *Buf) const override {
@@ -76,7 +76,7 @@ public:
 // See Microsoft PE/COFF spec 7.1. Import Header for details.
 class OrdinalOnlyChunk : public Chunk {
 public:
-  explicit OrdinalOnlyChunk(uint16_t V) : Ordinal(V) { Align = ptrSize(); }
+  explicit OrdinalOnlyChunk(uint16_t V) : Ordinal(V) { Alignment = ptrSize(); }
   size_t getSize() const override { return ptrSize(); }
 
   void writeTo(uint8_t *Buf) const override {
@@ -117,7 +117,6 @@ public:
   explicit NullChunk(size_t N) : Size(N) {}
   bool hasData() const override { return false; }
   size_t getSize() const override { return Size; }
-  void setAlign(size_t N) { Align = N; }
 
 private:
   size_t Size;
@@ -302,7 +301,7 @@ public:
 // A chunk for the import descriptor table.
 class DelayAddressChunk : public Chunk {
 public:
-  explicit DelayAddressChunk(Chunk *C) : Thunk(C) { Align = ptrSize(); }
+  explicit DelayAddressChunk(Chunk *C) : Thunk(C) { Alignment = ptrSize(); }
   size_t getSize() const override { return ptrSize(); }
 
   void writeTo(uint8_t *Buf) const override {
@@ -535,7 +534,7 @@ void DelayLoadContents::create(Defined *
     for (int I = 0, E = Syms.size(); I < E; ++I)
       Syms[I]->setLocation(Addresses[Base + I]);
     auto *MH = make<NullChunk>(8);
-    MH->setAlign(8);
+    MH->Alignment = 8;
     ModuleHandles.push_back(MH);
 
     // Fill the delay import table header fields.

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Sep 13 14:54:55 2017
@@ -1201,18 +1201,22 @@ void LinkerDriver::link(ArrayRef<const c
   // Set extra alignment for .comm symbols
   for (auto Pair : Config->AlignComm) {
     StringRef Name = Pair.first;
-    int Align = Pair.second;
+    uint32_t Alignment = Pair.second;
+
     Symbol *Sym = Symtab->find(Name);
     if (!Sym) {
       warn("/aligncomm symbol " + Name + " not found");
       continue;
     }
+
     auto *DC = dyn_cast<DefinedCommon>(Sym->body());
     if (!DC) {
       warn("/aligncomm symbol " + Name + " of wrong kind");
       continue;
     }
-    DC->getChunk()->setAlign(Align);
+
+    CommonChunk *C = DC->getChunk();
+    C->Alignment = std::max(C->Alignment, Alignment);
   }
 
   // Windows specific -- Create a side-by-side manifest file.

Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Wed Sep 13 14:54:55 2017
@@ -61,12 +61,9 @@ private:
 
 // Returns a hash value for S.
 uint32_t ICF::getHash(SectionChunk *C) {
-  return hash_combine(C->getPermissions(),
-                      hash_value(C->SectionName),
-                      C->NumRelocs,
-                      C->getAlign(),
-                      uint32_t(C->Header->SizeOfRawData),
-                      C->Checksum);
+  return hash_combine(C->getPermissions(), hash_value(C->SectionName),
+                      C->NumRelocs, C->Alignment,
+                      uint32_t(C->Header->SizeOfRawData), C->Checksum);
 }
 
 // Returns true if section S is subject of ICF.
@@ -137,11 +134,9 @@ bool ICF::equalsConstant(const SectionCh
 
   // Compare section attributes and contents.
   return A->getPermissions() == B->getPermissions() &&
-         A->SectionName == B->SectionName &&
-         A->getAlign() == B->getAlign() &&
+         A->SectionName == B->SectionName && A->Alignment == B->Alignment &&
          A->Header->SizeOfRawData == B->Header->SizeOfRawData &&
-         A->Checksum == B->Checksum &&
-         A->getContents() == B->getContents();
+         A->Checksum == B->Checksum && A->getContents() == B->getContents();
 }
 
 // Compare "moving" part of two sections, namely relocation targets.

Modified: lld/trunk/COFF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/MapFile.cpp (original)
+++ lld/trunk/COFF/MapFile.cpp Wed Sep 13 14:54:55 2017
@@ -115,7 +115,7 @@ void coff::writeMapFile(ArrayRef<OutputS
       if (!SC)
         continue;
 
-      writeHeader(OS, SC->getRVA(), SC->getSize(), SC->getAlign());
+      writeHeader(OS, SC->getRVA(), SC->getSize(), SC->Alignment);
       OS << indent(1) << SC->File->getName() << ":(" << SC->getSectionName()
          << ")\n";
       for (DefinedRegular *Sym : SectionSyms[SC])

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=313204&r1=313203&r2=313204&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Sep 13 14:54:55 2017
@@ -183,7 +183,7 @@ void OutputSection::addChunk(Chunk *C) {
   Chunks.push_back(C);
   C->setOutputSection(this);
   uint64_t Off = Header.VirtualSize;
-  Off = alignTo(Off, C->getAlign());
+  Off = alignTo(Off, C->Alignment);
   C->setRVA(Off);
   C->OutputSectionOff = Off;
   Off += C->getSize();




More information about the llvm-commits mailing list