Skip to content

Commit 1565317

Browse files
committed
Revert D139181 "[lld][Alignment][NFC] Use Align instead of log2 of alignment in Wasm Sections"
As discussed on the patch the Align type is probably not a good fit for linkers. This reverts commit cfe77f2.
1 parent 3e2a6d7 commit 1565317

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

lld/wasm/InputChunks.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class InputChunk {
8585
OutputSection *outputSec = nullptr;
8686
uint32_t comdat = UINT32_MAX;
8787
uint32_t inputSectionOffset = 0;
88-
llvm::Align alignment;
88+
uint32_t alignment;
8989
uint32_t flags;
9090

9191
// Only applies to data segments.
@@ -109,8 +109,8 @@ class InputChunk {
109109
protected:
110110
InputChunk(ObjFile *f, Kind k, StringRef name, uint32_t alignment = 0,
111111
uint32_t flags = 0)
112-
: name(name), file(f), alignment(1ULL << alignment), flags(flags),
113-
sectionKind(k), live(!config->gcSections), discarded(false) {}
112+
: name(name), file(f), alignment(alignment), flags(flags), sectionKind(k),
113+
live(!config->gcSections), discarded(false) {}
114114
ArrayRef<uint8_t> data() const { return rawData; }
115115
uint64_t getTombstone() const;
116116

lld/wasm/OutputSegment.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ namespace wasm {
2222
void OutputSegment::addInputSegment(InputChunk *inSeg) {
2323
alignment = std::max(alignment, inSeg->alignment);
2424
inputSegments.push_back(inSeg);
25-
size = llvm::alignTo(size, inSeg->alignment);
25+
size = llvm::alignTo(size, 1ULL << inSeg->alignment);
2626
LLVM_DEBUG(dbgs() << "addInputSegment: " << inSeg->name << " oname=" << name
27-
<< " size=" << inSeg->getSize() << " align="
28-
<< Log2(inSeg->alignment) << " at:" << size << "\n");
27+
<< " size=" << inSeg->getSize()
28+
<< " align=" << inSeg->alignment << " at:" << size << "\n");
2929
inSeg->outputSeg = this;
3030
inSeg->outputSegmentOffset = size;
3131
size += inSeg->getSize();
@@ -56,9 +56,8 @@ void OutputSegment::finalizeInputSegments() {
5656
});
5757
if (i == mergedSegments.end()) {
5858
LLVM_DEBUG(llvm::dbgs() << "new merge segment: " << name
59-
<< " alignment=" << Log2(ms->alignment) << "\n");
60-
auto *syn =
61-
make<SyntheticMergedChunk>(name, Log2(ms->alignment), ms->flags);
59+
<< " alignment=" << ms->alignment << "\n");
60+
auto *syn = make<SyntheticMergedChunk>(name, ms->alignment, ms->flags);
6261
syn->outputSeg = this;
6362
mergedSegments.push_back(syn);
6463
i = std::prev(mergedSegments.end());
@@ -75,7 +74,7 @@ void OutputSegment::finalizeInputSegments() {
7574
inputSegments = newSegments;
7675
size = 0;
7776
for (InputChunk *seg : inputSegments) {
78-
size = llvm::alignTo(size, seg->alignment);
77+
size = llvm::alignTo(size, 1ULL << seg->alignment);
7978
LLVM_DEBUG(llvm::dbgs() << "outputSegmentOffset set: " << seg->name
8079
<< " -> " << size << "\n");
8180
seg->outputSegmentOffset = size;

lld/wasm/OutputSegment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class OutputSegment {
3838
uint32_t linkingFlags = 0;
3939
uint32_t initFlags = 0;
4040
uint32_t sectionOffset = 0;
41-
llvm::Align alignment;
41+
uint32_t alignment = 0;
4242
uint64_t startVA = 0;
4343
std::vector<InputChunk *> inputSegments;
4444

lld/wasm/SyntheticSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ void LinkingSection::writeBody() {
668668
writeUleb128(sub.os, dataSegments.size(), "num data segments");
669669
for (const OutputSegment *s : dataSegments) {
670670
writeStr(sub.os, s->name, "segment name");
671-
writeUleb128(sub.os, Log2(s->alignment), "alignment");
671+
writeUleb128(sub.os, s->alignment, "alignment");
672672
writeUleb128(sub.os, s->linkingFlags, "flags");
673673
}
674674
sub.writeTo(os);

lld/wasm/Writer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,11 @@ void Writer::layoutMemory() {
288288

289289
out.dylinkSec->memAlign = 0;
290290
for (OutputSegment *seg : segments) {
291-
out.dylinkSec->memAlign =
292-
std::max(out.dylinkSec->memAlign, Log2(seg->alignment));
293-
memoryPtr = alignTo(memoryPtr, seg->alignment);
291+
out.dylinkSec->memAlign = std::max(out.dylinkSec->memAlign, seg->alignment);
292+
memoryPtr = alignTo(memoryPtr, 1ULL << seg->alignment);
294293
seg->startVA = memoryPtr;
295294
log(formatv("mem: {0,-15} offset={1,-8} size={2,-8} align={3}", seg->name,
296-
memoryPtr, seg->size, Log2(seg->alignment)));
295+
memoryPtr, seg->size, seg->alignment));
297296

298297
if (!config->relocatable && seg->isTLS()) {
299298
if (WasmSym::tlsSize) {
@@ -302,7 +301,7 @@ void Writer::layoutMemory() {
302301
}
303302
if (WasmSym::tlsAlign) {
304303
auto *tlsAlign = cast<DefinedGlobal>(WasmSym::tlsAlign);
305-
setGlobalPtr(tlsAlign, seg->alignment.value());
304+
setGlobalPtr(tlsAlign, int64_t{1} << seg->alignment);
306305
}
307306
if (!config->sharedMemory && WasmSym::tlsBase) {
308307
auto *tlsBase = cast<DefinedGlobal>(WasmSym::tlsBase);

0 commit comments

Comments
 (0)