Skip to content

Commit 29161bc

Browse files
committed
Applied suggestions
1 parent 59844ee commit 29161bc

8 files changed

+170
-171
lines changed

lld/wasm/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct Ctx {
143143
llvm::SmallVector<InputTable *, 0> syntheticTables;
144144

145145
// Linker-generated symbols like __wasm_init_memory, __heap_base, etc.
146-
std::unique_ptr<WasmSym> wasmSym;
146+
WasmSym sym{};
147147

148148
// True if we are creating position-independent code.
149149
bool isPic = false;

lld/wasm/Driver.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ void Ctx::reset() {
7070
isPic = false;
7171
legacyFunctionTable = false;
7272
emitBssSegments = false;
73-
wasmSym.reset();
74-
wasmSym = std::make_unique<WasmSym>();
73+
sym = WasmSym{};
7574
}
7675

7776
namespace {
@@ -947,14 +946,14 @@ static void createSyntheticSymbols() {
947946
true};
948947
static llvm::wasm::WasmGlobalType mutableGlobalTypeI64 = {WASM_TYPE_I64,
949948
true};
950-
ctx.wasmSym->callCtors = symtab->addSyntheticFunction(
949+
ctx.sym.callCtors = symtab->addSyntheticFunction(
951950
"__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN,
952951
make<SyntheticFunction>(nullSignature, "__wasm_call_ctors"));
953952

954953
bool is64 = ctx.arg.is64.value_or(false);
955954

956955
if (ctx.isPic) {
957-
ctx.wasmSym->stackPointer =
956+
ctx.sym.stackPointer =
958957
createUndefinedGlobal("__stack_pointer", ctx.arg.is64.value_or(false)
959958
? &mutableGlobalTypeI64
960959
: &mutableGlobalTypeI32);
@@ -964,22 +963,22 @@ static void createSyntheticSymbols() {
964963
// See:
965964
// https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md
966965
auto *globalType = is64 ? &globalTypeI64 : &globalTypeI32;
967-
ctx.wasmSym->memoryBase =
966+
ctx.sym.memoryBase =
968967
createUndefinedGlobal("__memory_base", globalType);
969-
ctx.wasmSym->tableBase = createUndefinedGlobal("__table_base", globalType);
970-
ctx.wasmSym->memoryBase->markLive();
971-
ctx.wasmSym->tableBase->markLive();
968+
ctx.sym.tableBase = createUndefinedGlobal("__table_base", globalType);
969+
ctx.sym.memoryBase->markLive();
970+
ctx.sym.tableBase->markLive();
972971
} else {
973972
// For non-PIC code
974-
ctx.wasmSym->stackPointer = createGlobalVariable("__stack_pointer", true);
975-
ctx.wasmSym->stackPointer->markLive();
973+
ctx.sym.stackPointer = createGlobalVariable("__stack_pointer", true);
974+
ctx.sym.stackPointer->markLive();
976975
}
977976

978977
if (ctx.arg.sharedMemory) {
979-
ctx.wasmSym->tlsBase = createGlobalVariable("__tls_base", true);
980-
ctx.wasmSym->tlsSize = createGlobalVariable("__tls_size", false);
981-
ctx.wasmSym->tlsAlign = createGlobalVariable("__tls_align", false);
982-
ctx.wasmSym->initTLS = symtab->addSyntheticFunction(
978+
ctx.sym.tlsBase = createGlobalVariable("__tls_base", true);
979+
ctx.sym.tlsSize = createGlobalVariable("__tls_size", false);
980+
ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false);
981+
ctx.sym.initTLS = symtab->addSyntheticFunction(
983982
"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
984983
make<SyntheticFunction>(is64 ? i64ArgSignature : i32ArgSignature,
985984
"__wasm_init_tls"));
@@ -990,27 +989,27 @@ static void createOptionalSymbols() {
990989
if (ctx.arg.relocatable)
991990
return;
992991

993-
ctx.wasmSym->dsoHandle = symtab->addOptionalDataSymbol("__dso_handle");
992+
ctx.sym.dsoHandle = symtab->addOptionalDataSymbol("__dso_handle");
994993

995994
if (!ctx.arg.shared)
996-
ctx.wasmSym->dataEnd = symtab->addOptionalDataSymbol("__data_end");
995+
ctx.sym.dataEnd = symtab->addOptionalDataSymbol("__data_end");
997996

998997
if (!ctx.isPic) {
999-
ctx.wasmSym->stackLow = symtab->addOptionalDataSymbol("__stack_low");
1000-
ctx.wasmSym->stackHigh = symtab->addOptionalDataSymbol("__stack_high");
1001-
ctx.wasmSym->globalBase = symtab->addOptionalDataSymbol("__global_base");
1002-
ctx.wasmSym->heapBase = symtab->addOptionalDataSymbol("__heap_base");
1003-
ctx.wasmSym->heapEnd = symtab->addOptionalDataSymbol("__heap_end");
1004-
ctx.wasmSym->definedMemoryBase =
998+
ctx.sym.stackLow = symtab->addOptionalDataSymbol("__stack_low");
999+
ctx.sym.stackHigh = symtab->addOptionalDataSymbol("__stack_high");
1000+
ctx.sym.globalBase = symtab->addOptionalDataSymbol("__global_base");
1001+
ctx.sym.heapBase = symtab->addOptionalDataSymbol("__heap_base");
1002+
ctx.sym.heapEnd = symtab->addOptionalDataSymbol("__heap_end");
1003+
ctx.sym.definedMemoryBase =
10051004
symtab->addOptionalDataSymbol("__memory_base");
1006-
ctx.wasmSym->definedTableBase =
1005+
ctx.sym.definedTableBase =
10071006
symtab->addOptionalDataSymbol("__table_base");
10081007
}
10091008

1010-
ctx.wasmSym->firstPageEnd =
1009+
ctx.sym.firstPageEnd =
10111010
symtab->addOptionalDataSymbol("__wasm_first_page_end");
1012-
if (ctx.wasmSym->firstPageEnd)
1013-
ctx.wasmSym->firstPageEnd->setVA(ctx.arg.pageSize);
1011+
if (ctx.sym.firstPageEnd)
1012+
ctx.sym.firstPageEnd->setVA(ctx.arg.pageSize);
10141013

10151014
// For non-shared memory programs we still need to define __tls_base since we
10161015
// allow object files built with TLS to be linked into single threaded
@@ -1022,7 +1021,7 @@ static void createOptionalSymbols() {
10221021
// __tls_size and __tls_align are not needed in this case since they are only
10231022
// needed for __wasm_init_tls (which we do not create in this case).
10241023
if (!ctx.arg.sharedMemory)
1025-
ctx.wasmSym->tlsBase = createOptionalGlobal("__tls_base", false);
1024+
ctx.sym.tlsBase = createOptionalGlobal("__tls_base", false);
10261025
}
10271026

10281027
static void processStubLibrariesPreLTO() {
@@ -1397,9 +1396,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
13971396
// by libc/etc., because destructors are registered dynamically with
13981397
// `__cxa_atexit` and friends.
13991398
if (!ctx.arg.relocatable && !ctx.arg.shared &&
1400-
!ctx.wasmSym->callCtors->isUsedInRegularObj &&
1401-
ctx.wasmSym->callCtors->getName() != ctx.arg.entry &&
1402-
!ctx.arg.exportedSymbols.count(ctx.wasmSym->callCtors->getName())) {
1399+
!ctx.sym.callCtors->isUsedInRegularObj &&
1400+
ctx.sym.callCtors->getName() != ctx.arg.entry &&
1401+
!ctx.arg.exportedSymbols.count(ctx.sym.callCtors->getName())) {
14031402
if (Symbol *callDtors =
14041403
handleUndefined("__wasm_call_dtors", "<internal>")) {
14051404
if (auto *callDtorsFunc = dyn_cast<DefinedFunction>(callDtors)) {
@@ -1408,7 +1407,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
14081407
!callDtorsFunc->signature->Returns.empty())) {
14091408
error("__wasm_call_dtors must have no argument or return values");
14101409
}
1411-
ctx.wasmSym->callDtors = callDtorsFunc;
1410+
ctx.sym.callDtors = callDtorsFunc;
14121411
} else {
14131412
error("__wasm_call_dtors must be a function");
14141413
}
@@ -1501,7 +1500,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
15011500
markLive();
15021501

15031502
// Provide the indirect function table if needed.
1504-
ctx.wasmSym->indirectFunctionTable =
1503+
ctx.sym.indirectFunctionTable =
15051504
symtab->resolveIndirectFunctionTable(/*required =*/false);
15061505

15071506
if (errorCount())

lld/wasm/InputChunks.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
411411
if (ctx.isPic) {
412412
writeU8(os, WASM_OPCODE_GLOBAL_GET, "GLOBAL_GET");
413413
if (isTLS())
414-
writeUleb128(os, ctx.wasmSym->tlsBase->getGlobalIndex(), "tls_base");
414+
writeUleb128(os, ctx.sym.tlsBase->getGlobalIndex(), "tls_base");
415415
else
416-
writeUleb128(os, ctx.wasmSym->memoryBase->getGlobalIndex(),
416+
writeUleb128(os, ctx.sym.memoryBase->getGlobalIndex(),
417417
"memory_base");
418418
writeU8(os, opcode_ptr_add, "ADD");
419419
}
@@ -437,12 +437,12 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
437437
}
438438
} else {
439439
assert(ctx.isPic);
440-
const GlobalSymbol *baseSymbol = ctx.wasmSym->memoryBase;
440+
const GlobalSymbol *baseSymbol = ctx.sym.memoryBase;
441441
if (rel.Type == R_WASM_TABLE_INDEX_I32 ||
442442
rel.Type == R_WASM_TABLE_INDEX_I64)
443-
baseSymbol = ctx.wasmSym->tableBase;
443+
baseSymbol = ctx.sym.tableBase;
444444
else if (sym->isTLS())
445-
baseSymbol = ctx.wasmSym->tlsBase;
445+
baseSymbol = ctx.sym.tlsBase;
446446
writeU8(os, WASM_OPCODE_GLOBAL_GET, "GLOBAL_GET");
447447
writeUleb128(os, baseSymbol->getGlobalIndex(), "base");
448448
writeU8(os, opcode_reloc_const, "CONST");

lld/wasm/MarkLive.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ void MarkLive::run() {
114114
if (sym->isNoStrip() || sym->isExported())
115115
enqueue(sym);
116116

117-
if (ctx.wasmSym->callDtors)
118-
enqueue(ctx.wasmSym->callDtors);
117+
if (ctx.sym.callDtors)
118+
enqueue(ctx.sym.callDtors);
119119

120120
for (const ObjFile *obj : ctx.objectFiles)
121121
if (obj->isLive()) {
@@ -131,7 +131,7 @@ void MarkLive::run() {
131131
// If we have any non-discarded init functions, mark `__wasm_call_ctors` as
132132
// live so that we assign it an index and call it.
133133
if (isCallCtorsLive())
134-
ctx.wasmSym->callCtors->markLive();
134+
ctx.sym.callCtors->markLive();
135135
}
136136

137137
void MarkLive::mark() {

lld/wasm/OutputSections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void DataSection::finalizeContents() {
124124
if ((segment->initFlags & WASM_DATA_SEGMENT_IS_PASSIVE) == 0) {
125125
if (ctx.isPic && ctx.arg.extendedConst) {
126126
writeU8(os, WASM_OPCODE_GLOBAL_GET, "global get");
127-
writeUleb128(os, ctx.wasmSym->memoryBase->getGlobalIndex(),
127+
writeUleb128(os, ctx.sym.memoryBase->getGlobalIndex(),
128128
"literal (global index)");
129129
if (segment->startVA) {
130130
writePtrConst(os, segment->startVA, is64, "offset");
@@ -138,7 +138,7 @@ void DataSection::finalizeContents() {
138138
assert(segment->startVA == 0);
139139
initExpr.Inst.Opcode = WASM_OPCODE_GLOBAL_GET;
140140
initExpr.Inst.Value.Global =
141-
ctx.wasmSym->memoryBase->getGlobalIndex();
141+
ctx.sym.memoryBase->getGlobalIndex();
142142
} else {
143143
initExpr = intConst(segment->startVA, is64);
144144
}

lld/wasm/Symbols.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -541,103 +541,103 @@ class LazySymbol : public Symbol {
541541
struct WasmSym {
542542
// __global_base
543543
// Symbol marking the start of the global section.
544-
DefinedData *globalBase = nullptr;
544+
DefinedData *globalBase;
545545

546546
// __stack_pointer/__stack_low/__stack_high
547547
// Global that holds current value of stack pointer and data symbols marking
548548
// the start and end of the stack region. stackPointer is initialized to
549549
// stackHigh and grows downwards towards stackLow
550-
GlobalSymbol *stackPointer = nullptr;
551-
DefinedData *stackLow = nullptr;
552-
DefinedData *stackHigh = nullptr;
550+
GlobalSymbol *stackPointer;
551+
DefinedData *stackLow;
552+
DefinedData *stackHigh;
553553

554554
// __tls_base
555555
// Global that holds the address of the base of the current thread's
556556
// TLS block.
557-
GlobalSymbol *tlsBase = nullptr;
557+
GlobalSymbol *tlsBase;
558558

559559
// __tls_size
560560
// Symbol whose value is the size of the TLS block.
561-
GlobalSymbol *tlsSize = nullptr;
561+
GlobalSymbol *tlsSize;
562562

563563
// __tls_size
564564
// Symbol whose value is the alignment of the TLS block.
565-
GlobalSymbol *tlsAlign = nullptr;
565+
GlobalSymbol *tlsAlign;
566566

567567
// __data_end
568568
// Symbol marking the end of the data and bss.
569-
DefinedData *dataEnd = nullptr;
569+
DefinedData *dataEnd;
570570

571571
// __heap_base/__heap_end
572572
// Symbols marking the beginning and end of the "heap". It starts at the end
573573
// of the data, bss and explicit stack, and extends to the end of the linear
574574
// memory allocated by wasm-ld. This region of memory is not used by the
575575
// linked code, so it may be used as a backing store for `sbrk` or `malloc`
576576
// implementations.
577-
DefinedData *heapBase = nullptr;
578-
DefinedData *heapEnd = nullptr;
577+
DefinedData *heapBase;
578+
DefinedData *heapEnd;
579579

580580
// __wasm_first_page_end
581581
// A symbol whose address is the end of the first page in memory (if any).
582-
DefinedData *firstPageEnd = nullptr;
582+
DefinedData *firstPageEnd;
583583

584584
// __wasm_init_memory_flag
585585
// Symbol whose contents are nonzero iff memory has already been initialized.
586-
DefinedData *initMemoryFlag = nullptr;
586+
DefinedData *initMemoryFlag;
587587

588588
// __wasm_init_memory
589589
// Function that initializes passive data segments during instantiation.
590-
DefinedFunction *initMemory = nullptr;
590+
DefinedFunction *initMemory;
591591

592592
// __wasm_call_ctors
593593
// Function that directly calls all ctors in priority order.
594-
DefinedFunction *callCtors = nullptr;
594+
DefinedFunction *callCtors;
595595

596596
// __wasm_call_dtors
597597
// Function that calls the libc/etc. cleanup function.
598-
DefinedFunction *callDtors = nullptr;
598+
DefinedFunction *callDtors;
599599

600600
// __wasm_apply_global_relocs
601601
// Function that applies relocations to wasm globals post-instantiation.
602602
// Unlike __wasm_apply_data_relocs this needs to run on every thread.
603-
DefinedFunction *applyGlobalRelocs = nullptr;
603+
DefinedFunction *applyGlobalRelocs;
604604

605605
// __wasm_apply_tls_relocs
606606
// Like __wasm_apply_data_relocs but for TLS section. These must be
607607
// delayed until __wasm_init_tls.
608-
DefinedFunction *applyTLSRelocs = nullptr;
608+
DefinedFunction *applyTLSRelocs;
609609

610610
// __wasm_apply_global_tls_relocs
611611
// Like applyGlobalRelocs but for globals that hold TLS addresses. These
612612
// must be delayed until __wasm_init_tls.
613-
DefinedFunction *applyGlobalTLSRelocs = nullptr;
613+
DefinedFunction *applyGlobalTLSRelocs;
614614

615615
// __wasm_init_tls
616616
// Function that allocates thread-local storage and initializes it.
617-
DefinedFunction *initTLS = nullptr;
617+
DefinedFunction *initTLS;
618618

619619
// Pointer to the function that is to be used in the start section.
620620
// (normally an alias of initMemory, or applyGlobalRelocs).
621-
DefinedFunction *startFunction = nullptr;
621+
DefinedFunction *startFunction;
622622

623623
// __dso_handle
624624
// Symbol used in calls to __cxa_atexit to determine current DLL
625-
DefinedData *dsoHandle = nullptr;
625+
DefinedData *dsoHandle;
626626

627627
// __table_base
628628
// Used in PIC code for offset of indirect function table
629-
UndefinedGlobal *tableBase = nullptr;
630-
DefinedData *definedTableBase = nullptr;
629+
UndefinedGlobal *tableBase;
630+
DefinedData *definedTableBase;
631631

632632
// __memory_base
633633
// Used in PIC code for offset of global data
634-
UndefinedGlobal *memoryBase = nullptr;
635-
DefinedData *definedMemoryBase = nullptr;
634+
UndefinedGlobal *memoryBase;
635+
DefinedData *definedMemoryBase;
636636

637637
// __indirect_function_table
638638
// Used as an address space for function pointers, with each function that is
639639
// used as a function pointer being allocated a slot.
640-
TableSymbol *indirectFunctionTable = nullptr;
640+
TableSymbol *indirectFunctionTable;
641641
};
642642

643643
// A buffer class that is large enough to hold any Symbol-derived

0 commit comments

Comments
 (0)