Skip to content

Commit f87c98d

Browse files
committed
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 32a4ad3. This reverts commit 7fe13af. This reverts commit 51fbc1b. This reverts commit f80950a. This reverts commit 0778cad. This reverts commit 8b70d52.
1 parent 1de0199 commit f87c98d

File tree

4 files changed

+3
-57
lines changed

4 files changed

+3
-57
lines changed

lld/COFF/Writer.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ class Writer {
241241
void addSyntheticIdata();
242242
void fixPartialSectionChars(StringRef name, uint32_t chars);
243243
bool fixGnuImportChunks();
244-
void fixTlsAlignment();
245244
PartialSection *createPartialSection(StringRef name, uint32_t outChars);
246245
PartialSection *findPartialSection(StringRef name, uint32_t outChars);
247246

@@ -268,7 +267,6 @@ class Writer {
268267
DelayLoadContents delayIdata;
269268
EdataContents edata;
270269
bool setNoSEHCharacteristic = false;
271-
uint32_t tlsAlignment = 0;
272270

273271
DebugDirectoryChunk *debugDirectory = nullptr;
274272
std::vector<std::pair<COFF::DebugType, Chunk *>> debugRecords;
@@ -635,11 +633,6 @@ void Writer::run() {
635633
writeSections();
636634
sortExceptionTable();
637635

638-
// Fix up the alignment in the TLS Directory's characteristic field,
639-
// if a specific alignment value is needed
640-
if (tlsAlignment)
641-
fixTlsAlignment();
642-
643636
t1.stop();
644637

645638
if (!config->pdbPath.empty() && config->debug) {
@@ -873,10 +866,6 @@ void Writer::createSections() {
873866
StringRef name = c->getSectionName();
874867
if (shouldStripSectionSuffix(sc, name))
875868
name = name.split('$').first;
876-
877-
if (name.startswith(".tls"))
878-
tlsAlignment = std::max(tlsAlignment, c->getAlignment());
879-
880869
PartialSection *pSec = createPartialSection(name,
881870
c->getOutputCharacteristics());
882871
pSec->chunks.push_back(c);
@@ -2049,33 +2038,3 @@ PartialSection *Writer::findPartialSection(StringRef name, uint32_t outChars) {
20492038
return it->second;
20502039
return nullptr;
20512040
}
2052-
2053-
void Writer::fixTlsAlignment() {
2054-
Defined *tlsSym =
2055-
dyn_cast_or_null<Defined>(symtab->findUnderscore("_tls_used"));
2056-
if (!tlsSym)
2057-
return;
2058-
2059-
OutputSection *sec = tlsSym->getChunk()->getOutputSection();
2060-
assert(sec && tlsSym->getRVA() >= sec->getRVA() &&
2061-
"no output section for _tls_used");
2062-
2063-
uint8_t *secBuf = buffer->getBufferStart() + sec->getFileOff();
2064-
uint64_t tlsOffset = tlsSym->getRVA() - sec->getRVA();
2065-
uint64_t directorySize = config->is64()
2066-
? sizeof(object::coff_tls_directory64)
2067-
: sizeof(object::coff_tls_directory32);
2068-
2069-
if (tlsOffset + directorySize > sec->getRawSize())
2070-
fatal("_tls_used sym is malformed");
2071-
2072-
if (config->is64()) {
2073-
object::coff_tls_directory64 *tlsDir =
2074-
reinterpret_cast<object::coff_tls_directory64 *>(&secBuf[tlsOffset]);
2075-
tlsDir->setAlignment(tlsAlignment);
2076-
} else {
2077-
object::coff_tls_directory32 *tlsDir =
2078-
reinterpret_cast<object::coff_tls_directory32 *>(&secBuf[tlsOffset]);
2079-
tlsDir->setAlignment(tlsAlignment);
2080-
}
2081-
}

lld/test/COFF/tls-alignment-32.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s
1414

1515
; CHECK: TLSDirectory {
16-
; CHECK: Characteristics [ (0x600000)
17-
; CHECK-NEXT: IMAGE_SCN_ALIGN_32BYTES (0x600000)
16+
; CHECK: Characteristics [ (0x0)
1817

1918
target triple = "i686-pc-windows-msvc"
2019

lld/test/COFF/tls-alignment-64.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
; RUN: llvm-readobj --coff-tls-directory %t.exe | FileCheck %s
1414

1515
; CHECK: TLSDirectory {
16-
; CHECK: Characteristics [ (0x700000)
17-
; CHECK-NEXT: IMAGE_SCN_ALIGN_64BYTES (0x700000)
16+
; CHECK: Characteristics [ (0x0)
1817

1918
target triple = "x86_64-pc-windows-msvc"
2019

llvm/include/llvm/Object/COFF.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -576,22 +576,11 @@ struct coff_tls_directory {
576576

577577
uint32_t getAlignment() const {
578578
// Bit [20:24] contains section alignment.
579-
uint32_t Shift = (Characteristics & COFF::IMAGE_SCN_ALIGN_MASK) >> 20;
579+
uint32_t Shift = (Characteristics & 0x00F00000) >> 20;
580580
if (Shift > 0)
581581
return 1U << (Shift - 1);
582582
return 0;
583583
}
584-
585-
void setAlignment(uint32_t Align) {
586-
uint32_t AlignBits = 0;
587-
if (Align) {
588-
assert(llvm::isPowerOf2_32(Align) && "alignment is not a power of 2");
589-
assert(llvm::Log2_32(Align) <= 13 && "alignment requested is too large");
590-
AlignBits = (llvm::Log2_32(Align) + 1) << 20;
591-
}
592-
Characteristics =
593-
(Characteristics & ~COFF::IMAGE_SCN_ALIGN_MASK) | AlignBits;
594-
}
595584
};
596585

597586
using coff_tls_directory32 = coff_tls_directory<support::little32_t>;

0 commit comments

Comments
 (0)