[llvm] f87c98d - Revert "[LLD] Set alignment as part of Characteristics in TLS table."

Luqman Aden via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 15 00:26:36 PDT 2020


Author: Luqman Aden
Date: 2020-10-15T00:21:36-07:00
New Revision: f87c98def86be7b737799e9980af2a0b77e9bc28

URL: https://github.com/llvm/llvm-project/commit/f87c98def86be7b737799e9980af2a0b77e9bc28
DIFF: https://github.com/llvm/llvm-project/commit/f87c98def86be7b737799e9980af2a0b77e9bc28.diff

LOG: Revert "[LLD] Set alignment as part of Characteristics in TLS table."

Revert individual wip commits and will instead follow up with a
single commit with all the changes. Makes cherry-picking easier
and will contain all the right tags.

This reverts commit 32a4ad3b6ce6028a371b028cf06fa5feff9534bf.
This reverts commit 7fe13af676678815989a6d0ece684687953245e7.
This reverts commit 51fbc1bef657bb0f5808986555ec3517a84768c4.
This reverts commit f80950a8bb985c082b26534b0e157447bf803935.
This reverts commit 0778cad9f325df4d7b32b22f3dba201a16a0b8fe.
This reverts commit 8b70d527d7ec1c8b9e921177119a0d906ffad4f0.

Added: 
    

Modified: 
    lld/COFF/Writer.cpp
    lld/test/COFF/tls-alignment-32.ll
    lld/test/COFF/tls-alignment-64.ll
    llvm/include/llvm/Object/COFF.h

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 534ea82dc3c2..c13cd34f2ddc 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -241,7 +241,6 @@ class Writer {
   void addSyntheticIdata();
   void fixPartialSectionChars(StringRef name, uint32_t chars);
   bool fixGnuImportChunks();
-  void fixTlsAlignment();
   PartialSection *createPartialSection(StringRef name, uint32_t outChars);
   PartialSection *findPartialSection(StringRef name, uint32_t outChars);
 
@@ -268,7 +267,6 @@ class Writer {
   DelayLoadContents delayIdata;
   EdataContents edata;
   bool setNoSEHCharacteristic = false;
-  uint32_t tlsAlignment = 0;
 
   DebugDirectoryChunk *debugDirectory = nullptr;
   std::vector<std::pair<COFF::DebugType, Chunk *>> debugRecords;
@@ -635,11 +633,6 @@ void Writer::run() {
   writeSections();
   sortExceptionTable();
 
-  // Fix up the alignment in the TLS Directory's characteristic field,
-  // if a specific alignment value is needed
-  if (tlsAlignment)
-    fixTlsAlignment();
-
   t1.stop();
 
   if (!config->pdbPath.empty() && config->debug) {
@@ -873,10 +866,6 @@ void Writer::createSections() {
     StringRef name = c->getSectionName();
     if (shouldStripSectionSuffix(sc, name))
       name = name.split('$').first;
-
-    if (name.startswith(".tls"))
-      tlsAlignment = std::max(tlsAlignment, c->getAlignment());
-
     PartialSection *pSec = createPartialSection(name,
                                                 c->getOutputCharacteristics());
     pSec->chunks.push_back(c);
@@ -2049,33 +2038,3 @@ PartialSection *Writer::findPartialSection(StringRef name, uint32_t outChars) {
     return it->second;
   return nullptr;
 }
-
-void Writer::fixTlsAlignment() {
-  Defined *tlsSym =
-      dyn_cast_or_null<Defined>(symtab->findUnderscore("_tls_used"));
-  if (!tlsSym)
-    return;
-
-  OutputSection *sec = tlsSym->getChunk()->getOutputSection();
-  assert(sec && tlsSym->getRVA() >= sec->getRVA() &&
-         "no output section for _tls_used");
-
-  uint8_t *secBuf = buffer->getBufferStart() + sec->getFileOff();
-  uint64_t tlsOffset = tlsSym->getRVA() - sec->getRVA();
-  uint64_t directorySize = config->is64()
-                               ? sizeof(object::coff_tls_directory64)
-                               : sizeof(object::coff_tls_directory32);
-
-  if (tlsOffset + directorySize > sec->getRawSize())
-    fatal("_tls_used sym is malformed");
-
-  if (config->is64()) {
-    object::coff_tls_directory64 *tlsDir =
-        reinterpret_cast<object::coff_tls_directory64 *>(&secBuf[tlsOffset]);
-    tlsDir->setAlignment(tlsAlignment);
-  } else {
-    object::coff_tls_directory32 *tlsDir =
-        reinterpret_cast<object::coff_tls_directory32 *>(&secBuf[tlsOffset]);
-    tlsDir->setAlignment(tlsAlignment);
-  }
-}

diff  --git a/lld/test/COFF/tls-alignment-32.ll b/lld/test/COFF/tls-alignment-32.ll
index 8df11e7fd1c2..bf9df5ca725f 100644
--- a/lld/test/COFF/tls-alignment-32.ll
+++ b/lld/test/COFF/tls-alignment-32.ll
@@ -13,8 +13,7 @@
 ; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s
 
 ; CHECK: TLSDirectory {
-; CHECK: Characteristics [ (0x600000)
-; CHECK-NEXT: IMAGE_SCN_ALIGN_32BYTES (0x600000)
+; CHECK: Characteristics [ (0x0)
 
 target triple = "i686-pc-windows-msvc"
 

diff  --git a/lld/test/COFF/tls-alignment-64.ll b/lld/test/COFF/tls-alignment-64.ll
index 04813ca0021e..056bce97aae0 100644
--- a/lld/test/COFF/tls-alignment-64.ll
+++ b/lld/test/COFF/tls-alignment-64.ll
@@ -13,8 +13,7 @@
 ; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s
 
 ; CHECK: TLSDirectory {
-; CHECK: Characteristics [ (0x700000)
-; CHECK-NEXT: IMAGE_SCN_ALIGN_64BYTES (0x700000)
+; CHECK: Characteristics [ (0x0)
 
 target triple = "x86_64-pc-windows-msvc"
 

diff  --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index e7cf1b5495c6..505aab8bff5b 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -576,22 +576,11 @@ struct coff_tls_directory {
 
   uint32_t getAlignment() const {
     // Bit [20:24] contains section alignment.
-    uint32_t Shift = (Characteristics & COFF::IMAGE_SCN_ALIGN_MASK) >> 20;
+    uint32_t Shift = (Characteristics & 0x00F00000) >> 20;
     if (Shift > 0)
       return 1U << (Shift - 1);
     return 0;
   }
-
-  void setAlignment(uint32_t Align) {
-    uint32_t AlignBits = 0;
-    if (Align) {
-      assert(llvm::isPowerOf2_32(Align) && "alignment is not a power of 2");
-      assert(llvm::Log2_32(Align) <= 13 && "alignment requested is too large");
-      AlignBits = (llvm::Log2_32(Align) + 1) << 20;
-    }
-    Characteristics =
-        (Characteristics & ~COFF::IMAGE_SCN_ALIGN_MASK) | AlignBits;
-  }
 };
 
 using coff_tls_directory32 = coff_tls_directory<support::little32_t>;


        


More information about the llvm-commits mailing list