[lld] [lld][WebAssembly] Move linker global state in to context object. NFC (PR #78629)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 13:30:46 PST 2024


https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/78629

See lld/ELF/Config.h

>From f04337475f854a4f7ec975877ffb77b29e662848 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Thu, 18 Jan 2024 21:21:48 +0000
Subject: [PATCH] [lld][WebAssembly] Move linker global state in to context
 object. NFC

See lld/ELF/Config.h
---
 lld/wasm/Config.h              | 21 +++++++++----------
 lld/wasm/Driver.cpp            | 27 ++++++++++++------------
 lld/wasm/InputChunks.cpp       |  6 +++---
 lld/wasm/InputFiles.cpp        |  2 +-
 lld/wasm/LTO.cpp               |  2 +-
 lld/wasm/MarkLive.cpp          |  2 +-
 lld/wasm/OutputSections.cpp    |  6 +++---
 lld/wasm/OutputSegment.h       |  2 +-
 lld/wasm/Relocations.cpp       |  4 ++--
 lld/wasm/SymbolTable.cpp       |  5 ++---
 lld/wasm/SyntheticSections.cpp | 12 +++++------
 lld/wasm/Writer.cpp            | 38 +++++++++++++++++-----------------
 12 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 104d4704840149..2f69cfd3819eca 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -71,6 +71,11 @@ struct Configuration {
   uint64_t initialHeap;
   uint64_t initialMemory;
   uint64_t maxMemory;
+  // The table offset at which to place function addresses.  We reserve zero
+  // for the null function pointer.  This gets set to 1 for executables and 0
+  // for shared libraries (since they always added to a dynamic offset at
+  // runtime).
+  uint64_t tableBase;
   uint64_t zStackSize;
   unsigned ltoPartitions;
   unsigned ltoo;
@@ -96,11 +101,12 @@ struct Configuration {
   std::optional<std::vector<std::string>> features;
   std::optional<std::vector<std::string>> extraFeatures;
   llvm::SmallVector<uint8_t, 0> buildIdVector;
+};
 
-  // The following config options do not directly correspond to any
-  // particular command line options, and should probably be moved to separate
-  // Ctx struct as in ELF/Config.h
+// The only instance of Configuration struct.
+extern Configuration *config;
 
+struct Ctx {
   // True if we are creating position-independent code.
   bool isPic;
 
@@ -108,12 +114,6 @@ struct Configuration {
   // requires it to be allocated to table number 0.
   bool legacyFunctionTable = false;
 
-  // The table offset at which to place function addresses.  We reserve zero
-  // for the null function pointer.  This gets set to 1 for executables and 0
-  // for shared libraries (since they always added to a dynamic offset at
-  // runtime).
-  uint32_t tableBase = 0;
-
   // Will be set to true if bss data segments should be emitted. In most cases
   // this is not necessary.
   bool emitBssSegments = false;
@@ -124,8 +124,7 @@ struct Configuration {
       whyExtractRecords;
 };
 
-// The only instance of Configuration struct.
-extern Configuration *config;
+extern Ctx ctx;
 
 } // namespace lld::wasm
 
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index a354260c605258..6864b8232ba795 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -45,6 +45,7 @@ using namespace llvm::wasm;
 
 namespace lld::wasm {
 Configuration *config;
+Ctx ctx;
 
 namespace {
 
@@ -308,7 +309,7 @@ static std::optional<std::string> searchLibraryBaseName(StringRef name) {
   for (StringRef dir : config->searchPaths) {
     // Currently we don't enable dynamic linking at all unless -shared or -pie
     // are used, so don't even look for .so files in that case..
-    if (config->isPic && !config->isStatic)
+    if (ctx.isPic && !config->isStatic)
       if (std::optional<std::string> s = findFile(dir, "lib" + name + ".so"))
         return s;
     if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a"))
@@ -571,9 +572,9 @@ static void readConfigs(opt::InputArgList &args) {
 // This function initialize such members. See Config.h for the details
 // of these values.
 static void setConfigs() {
-  config->isPic = config->pie || config->shared;
+  ctx.isPic = config->pie || config->shared;
 
-  if (config->isPic) {
+  if (ctx.isPic) {
     if (config->exportTable)
       error("-shared/-pie is incompatible with --export-table");
     config->importTable = true;
@@ -680,7 +681,7 @@ static void checkOptions(opt::InputArgList &args) {
     warn("-Bsymbolic is only meaningful when combined with -shared");
   }
 
-  if (config->isPic) {
+  if (ctx.isPic) {
     if (config->globalBase)
       error("--global-base may not be used with -shared/-pie");
     if (config->tableBase)
@@ -707,7 +708,7 @@ static Symbol *handleUndefined(StringRef name, const char *option) {
   if (auto *lazySym = dyn_cast<LazySymbol>(sym)) {
     lazySym->fetch();
     if (!config->whyExtract.empty())
-      config->whyExtractRecords.emplace_back(option, sym->getFile(), *sym);
+      ctx.whyExtractRecords.emplace_back(option, sym->getFile(), *sym);
   }
 
   return sym;
@@ -722,7 +723,7 @@ static void handleLibcall(StringRef name) {
     MemoryBufferRef mb = lazySym->getMemberBuffer();
     if (isBitcode(mb)) {
       if (!config->whyExtract.empty())
-        config->whyExtractRecords.emplace_back("<libcall>", sym->getFile(),
+        ctx.whyExtractRecords.emplace_back("<libcall>", sym->getFile(),
                                                *sym);
       lazySym->fetch();
     }
@@ -742,7 +743,7 @@ static void writeWhyExtract() {
   }
 
   os << "reference\textracted\tsymbol\n";
-  for (auto &entry : config->whyExtractRecords) {
+  for (auto &entry : ctx.whyExtractRecords) {
     os << std::get<0>(entry) << '\t' << toString(std::get<1>(entry)) << '\t'
        << toString(std::get<2>(entry)) << '\n';
   }
@@ -811,7 +812,7 @@ static void createSyntheticSymbols() {
 
   bool is64 = config->is64.value_or(false);
 
-  if (config->isPic) {
+  if (ctx.isPic) {
     WasmSym::stackPointer =
         createUndefinedGlobal("__stack_pointer", config->is64.value_or(false)
                                                      ? &mutableGlobalTypeI64
@@ -850,7 +851,7 @@ static void createSyntheticSymbols() {
             "__wasm_init_tls"));
   }
 
-  if (config->isPic ||
+  if (ctx.isPic ||
       config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic) {
     // For PIC code, or when dynamically importing addresses, we create
     // synthetic functions that apply relocations.  These get called from
@@ -871,7 +872,7 @@ static void createOptionalSymbols() {
   if (!config->shared)
     WasmSym::dataEnd = symtab->addOptionalDataSymbol("__data_end");
 
-  if (!config->isPic) {
+  if (!ctx.isPic) {
     WasmSym::stackLow = symtab->addOptionalDataSymbol("__stack_low");
     WasmSym::stackHigh = symtab->addOptionalDataSymbol("__stack_high");
     WasmSym::globalBase = symtab->addOptionalDataSymbol("__global_base");
@@ -967,8 +968,8 @@ static void processStubLibraries() {
               depsAdded = true;
               lazy->fetch();
               if (!config->whyExtract.empty())
-                config->whyExtractRecords.emplace_back(stub_file->getName(),
-                                                       sym->getFile(), *sym);
+                ctx.whyExtractRecords.emplace_back(stub_file->getName(),
+                                                   sym->getFile(), *sym);
             }
           }
         }
@@ -1305,7 +1306,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
       sym->forceExport = true;
   }
 
-  if (!config->relocatable && !config->isPic) {
+  if (!config->relocatable && !ctx.isPic) {
     // Add synthetic dummies for weak undefined functions.  Must happen
     // after LTO otherwise functions may not yet have signatures.
     symtab->handleWeakUndefines();
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
index f55f54a9509c79..2074dd59c1dde4 100644
--- a/lld/wasm/InputChunks.cpp
+++ b/lld/wasm/InputChunks.cpp
@@ -378,7 +378,7 @@ void InputChunk::generateRelocationCode(raw_ostream &os) const {
     uint64_t offset = getVA(rel.Offset) - getInputSectionOffset();
 
     Symbol *sym = file->getSymbol(rel);
-    if (!config->isPic && sym->isDefined())
+    if (!ctx.isPic && sym->isDefined())
       continue;
 
     LLVM_DEBUG(dbgs() << "gen reloc: type=" << relocTypeToString(rel.Type)
@@ -390,7 +390,7 @@ void InputChunk::generateRelocationCode(raw_ostream &os) const {
     writeSleb128(os, offset, "offset");
 
     // In PIC mode we need to add the __memory_base
-    if (config->isPic) {
+    if (ctx.isPic) {
       writeU8(os, WASM_OPCODE_GLOBAL_GET, "GLOBAL_GET");
       if (isTLS())
         writeUleb128(os, WasmSym::tlsBase->getGlobalIndex(), "tls_base");
@@ -417,7 +417,7 @@ void InputChunk::generateRelocationCode(raw_ostream &os) const {
         writeU8(os, opcode_reloc_add, "ADD");
       }
     } else {
-      assert(config->isPic);
+      assert(ctx.isPic);
       const GlobalSymbol* baseSymbol = WasmSym::memoryBase;
       if (rel.Type == R_WASM_TABLE_INDEX_I32 ||
           rel.Type == R_WASM_TABLE_INDEX_I64)
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 97c88587231ba9..19c76e49027896 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -351,7 +351,7 @@ void ObjFile::addLegacyIndirectFunctionTableIfNeeded(
 
   // We assume that this compilation unit has unrelocatable references to
   // this table.
-  config->legacyFunctionTable = true;
+  ctx.legacyFunctionTable = true;
 }
 
 static bool shouldMerge(const WasmSection &sec) {
diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp
index 4b22e4ccc1dc3e..e523f0f6171535 100644
--- a/lld/wasm/LTO.cpp
+++ b/lld/wasm/LTO.cpp
@@ -55,7 +55,7 @@ static std::unique_ptr<lto::LTO> createLTO() {
 
   if (config->relocatable)
     c.RelocModel = std::nullopt;
-  else if (config->isPic)
+  else if (ctx.isPic)
     c.RelocModel = Reloc::PIC_;
   else
     c.RelocModel = Reloc::Static;
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp
index a59a80ad2cc3a7..773af2f7e2360e 100644
--- a/lld/wasm/MarkLive.cpp
+++ b/lld/wasm/MarkLive.cpp
@@ -187,7 +187,7 @@ bool MarkLive::isCallCtorsLive() {
 
   // In Emscripten-style PIC, we call `__wasm_call_ctors` which calls
   // `__wasm_apply_data_relocs`.
-  if (config->isPic)
+  if (ctx.isPic)
     return true;
 
   // If there are any init functions, mark `__wasm_call_ctors` live so that
diff --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp
index 9c4383c6144bcc..3974146ab7270b 100644
--- a/lld/wasm/OutputSections.cpp
+++ b/lld/wasm/OutputSections.cpp
@@ -107,7 +107,7 @@ void DataSection::finalizeContents() {
   });
 #endif
 
-  assert((config->sharedMemory || !config->isPic || config->extendedConst ||
+  assert((config->sharedMemory || !ctx.isPic || config->extendedConst ||
           activeCount <= 1) &&
          "output segments should have been combined by now");
 
@@ -124,7 +124,7 @@ void DataSection::finalizeContents() {
     if (segment->initFlags & WASM_DATA_SEGMENT_HAS_MEMINDEX)
       writeUleb128(os, 0, "memory index");
     if ((segment->initFlags & WASM_DATA_SEGMENT_IS_PASSIVE) == 0) {
-      if (config->isPic && config->extendedConst) {
+      if (ctx.isPic && config->extendedConst) {
         writeU8(os, WASM_OPCODE_GLOBAL_GET, "global get");
         writeUleb128(os, WasmSym::memoryBase->getGlobalIndex(),
                      "literal (global index)");
@@ -136,7 +136,7 @@ void DataSection::finalizeContents() {
       } else {
         WasmInitExpr initExpr;
         initExpr.Extended = false;
-        if (config->isPic) {
+        if (ctx.isPic) {
           assert(segment->startVA == 0);
           initExpr.Inst.Opcode = WASM_OPCODE_GLOBAL_GET;
           initExpr.Inst.Value.Global = WasmSym::memoryBase->getGlobalIndex();
diff --git a/lld/wasm/OutputSegment.h b/lld/wasm/OutputSegment.h
index e1e43c1f9a36a9..701df1fecc4b89 100644
--- a/lld/wasm/OutputSegment.h
+++ b/lld/wasm/OutputSegment.h
@@ -27,7 +27,7 @@ class OutputSegment {
   // to the output binary.  However if the memory is imported, and
   // we can't use memory.fill during startup (due to lack of bulk
   // memory feature) then we include BSS segments verbatim.
-  bool requiredInBinary() const { return !isBss || config->emitBssSegments; }
+  bool requiredInBinary() const { return !isBss || ctx.emitBssSegments; }
 
   bool isTLS() const { return name == ".tdata"; }
 
diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index ce41cdcb3e07f4..fcffacbc77af01 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -19,7 +19,7 @@ using namespace llvm::wasm;
 namespace lld::wasm {
 
 static bool requiresGOTAccess(const Symbol *sym) {
-  if (!config->isPic &&
+  if (!ctx.isPic &&
       config->unresolvedSymbols != UnresolvedPolicy::ImportDynamic)
     return false;
   if (sym->isHidden() || sym->isLocal())
@@ -141,7 +141,7 @@ void scanRelocations(InputChunk *chunk) {
       break;
     }
 
-    if (config->isPic ||
+    if (ctx.isPic ||
         (sym->isUndefined() &&
          config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic)) {
       switch (reloc.Type) {
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index b5c138cd76392d..79905167e1b828 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -535,8 +535,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name,
     } else {
       lazy->fetch();
       if (!config->whyExtract.empty())
-        config->whyExtractRecords.emplace_back(toString(file), s->getFile(),
-                                               *s);
+        ctx.whyExtractRecords.emplace_back(toString(file), s->getFile(), *s);
     }
   } else {
     auto existingFunction = dyn_cast<FunctionSymbol>(s);
@@ -774,7 +773,7 @@ void SymbolTable::addLazy(ArchiveFile *file, const Archive::Symbol *sym) {
   const InputFile *oldFile = s->getFile();
   file->addMember(sym);
   if (!config->whyExtract.empty())
-    config->whyExtractRecords.emplace_back(toString(oldFile), s->getFile(), *s);
+    ctx.whyExtractRecords.emplace_back(toString(oldFile), s->getFile(), *s);
 }
 
 bool SymbolTable::addComdat(StringRef name) {
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 3a9c147161a2d3..f95174fe6f2695 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -55,7 +55,7 @@ class SubSection {
 } // namespace
 
 bool DylinkSection::isNeeded() const {
-  return config->isPic ||
+  return ctx.isPic ||
          config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic ||
          !symtab->sharedFiles.empty();
 }
@@ -174,7 +174,7 @@ void ImportSection::addGOTEntry(Symbol *sym) {
     return;
   LLVM_DEBUG(dbgs() << "addGOTEntry: " << toString(*sym) << "\n");
   sym->setGOTIndex(numImportedGlobals++);
-  if (config->isPic) {
+  if (ctx.isPic) {
     // Any symbol that is assigned an normal GOT entry must be exported
     // otherwise the dynamic linker won't be able create the entry that contains
     // it.
@@ -319,7 +319,7 @@ void TableSection::addTable(InputTable *table) {
     return;
   // Some inputs require that the indirect function table be assigned to table
   // number 0.
-  if (config->legacyFunctionTable &&
+  if (ctx.legacyFunctionTable &&
       isa<DefinedTable>(WasmSym::indirectFunctionTable) &&
       cast<DefinedTable>(WasmSym::indirectFunctionTable)->table == table) {
     if (out.importSec->getNumImportedTables()) {
@@ -474,7 +474,7 @@ void GlobalSection::writeBody() {
       // In the case of dynamic linking, unless we have 'extended-const'
       // available, these global must to be mutable since they get updated to
       // the correct runtime value during `__wasm_apply_global_relocs`.
-      if (!config->extendedConst && config->isPic && !sym->isTLS())
+      if (!config->extendedConst && ctx.isPic && !sym->isTLS())
         mutable_ = true;
       // With multi-theadeding any TLS globals must be mutable since they get
       // set during `__wasm_apply_global_tls_relocs`
@@ -487,7 +487,7 @@ void GlobalSection::writeBody() {
     bool useExtendedConst = false;
     uint32_t globalIdx;
     int64_t offset;
-    if (config->extendedConst && config->isPic) {
+    if (config->extendedConst && ctx.isPic) {
       if (auto *d = dyn_cast<DefinedData>(sym)) {
         if (!sym->isTLS()) {
           globalIdx = WasmSym::memoryBase->getGlobalIndex();
@@ -582,7 +582,7 @@ void ElemSection::writeBody() {
 
   WasmInitExpr initExpr;
   initExpr.Extended = false;
-  if (config->isPic) {
+  if (ctx.isPic) {
     initExpr.Inst.Opcode = WASM_OPCODE_GLOBAL_GET;
     initExpr.Inst.Value.Global =
         (config->is64.value_or(false) ? WasmSym::tableBase32
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 805018c58dccb4..7c19a1baf4c045 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -332,7 +332,7 @@ void Writer::layoutMemory() {
   uint64_t memoryPtr = 0;
 
   auto placeStack = [&]() {
-    if (config->relocatable || config->isPic)
+    if (config->relocatable || ctx.isPic)
       return;
     memoryPtr = alignTo(memoryPtr, stackAlignment);
     if (WasmSym::stackLow)
@@ -415,7 +415,7 @@ void Writer::layoutMemory() {
 
   uint64_t staticDataSize = memoryPtr - dataStart;
   log("mem: static data = " + Twine(staticDataSize));
-  if (config->isPic)
+  if (ctx.isPic)
     out.dylinkSec->memSize = staticDataSize;
 
   if (!config->stackFirst)
@@ -489,7 +489,7 @@ void Writer::layoutMemory() {
     if (max == 0) {
       // If no maxMemory config was supplied but we are building with
       // shared memory, we need to pick a sensible upper limit.
-      if (config->isPic)
+      if (ctx.isPic)
         max = maxMemorySetting;
       else
         max = memoryPtr;
@@ -568,7 +568,7 @@ void Writer::populateTargetFeatures() {
   SmallSet<std::string, 8> &allowed = out.targetFeaturesSec->features;
   bool tlsUsed = false;
 
-  if (config->isPic) {
+  if (ctx.isPic) {
     // This should not be necessary because all PIC objects should
     // contain the mutable-globals feature.
     // TODO (https://github.com/llvm/llvm-project/issues/51681)
@@ -683,7 +683,7 @@ void Writer::populateTargetFeatures() {
   // the bss segments, so these segments need to exist in the binary.
   if (config->emitRelocs ||
       (config->memoryImport.has_value() && !allowed.count("bulk-memory")))
-    config->emitBssSegments = true;
+    ctx.emitBssSegments = true;
 
   if (allowed.count("extended-const"))
     config->extendedConst = true;
@@ -734,18 +734,18 @@ static bool shouldImport(Symbol *sym) {
     return true;
   if (!sym->isUndefined())
     return false;
-  if (sym->isWeak() && !config->relocatable && !config->isPic)
+  if (sym->isWeak() && !config->relocatable && !ctx.isPic)
     return false;
 
   // In PIC mode we only need to import functions when they are called directly.
   // Indirect usage all goes via GOT imports.
-  if (config->isPic) {
+  if (ctx.isPic) {
     if (auto *f = dyn_cast<UndefinedFunction>(sym))
       if (!f->isCalledDirectly)
         return false;
   }
 
-  if (config->isPic || config->relocatable || config->importUndefined ||
+  if (ctx.isPic || config->relocatable || config->importUndefined ||
       config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic)
     return true;
   if (config->allowUndefinedSymbols.count(sym->getName()) != 0)
@@ -873,7 +873,7 @@ void Writer::calculateTypes() {
 // which calls the constructors and destructors.
 void Writer::createCommandExportWrappers() {
   // This logic doesn't currently support Emscripten-style PIC mode.
-  assert(!config->isPic);
+  assert(!ctx.isPic);
 
   // If there are no ctors and there's no libc `__wasm_call_dtors` to
   // call, don't wrap the exports.
@@ -1072,7 +1072,7 @@ void Writer::combineOutputSegments() {
   // This restriction does not apply when the extended const extension is
   // available: https://github.com/WebAssembly/extended-const
   assert(!config->extendedConst);
-  assert(config->isPic && !config->sharedMemory);
+  assert(ctx.isPic && !config->sharedMemory);
   if (segments.size() <= 1)
     return;
   OutputSegment *combined = make<OutputSegment>(".data");
@@ -1174,7 +1174,7 @@ void Writer::createSyntheticInitFunctions() {
     }
   }
 
-  if (config->isPic && out.globalSec->needsRelocations()) {
+  if (ctx.isPic && out.globalSec->needsRelocations()) {
     WasmSym::applyGlobalRelocs = symtab->addSyntheticFunction(
         "__wasm_apply_global_relocs", WASM_SYMBOL_VISIBILITY_HIDDEN,
         make<SyntheticFunction>(nullSignature, "__wasm_apply_global_relocs"));
@@ -1257,7 +1257,7 @@ void Writer::createInitMemoryFunction() {
     //    (i32.const 1)
 
     auto writeGetFlagAddress = [&]() {
-      if (config->isPic) {
+      if (ctx.isPic) {
         writeU8(os, WASM_OPCODE_LOCAL_GET, "local.get");
         writeUleb128(os, 0, "local 0");
       } else {
@@ -1267,7 +1267,7 @@ void Writer::createInitMemoryFunction() {
 
     if (config->sharedMemory) {
       // With PIC code we cache the flag address in local 0
-      if (config->isPic) {
+      if (ctx.isPic) {
         writeUleb128(os, 1, "num local decls");
         writeUleb128(os, 2, "local count");
         writeU8(os, is64 ? WASM_TYPE_I64 : WASM_TYPE_I32, "address type");
@@ -1317,7 +1317,7 @@ void Writer::createInitMemoryFunction() {
         // instructions take as their first argument the destination
         // address.
         writePtrConst(os, s->startVA, is64, "destination address");
-        if (config->isPic) {
+        if (ctx.isPic) {
           writeU8(os, WASM_OPCODE_GLOBAL_GET, "GLOBAL_GET");
           writeUleb128(os, WasmSym::memoryBase->getGlobalIndex(),
                        "__memory_base");
@@ -1329,7 +1329,7 @@ void Writer::createInitMemoryFunction() {
         // global.  This allows the runtime to use this static copy of the
         // TLS data for the first/main thread.
         if (config->sharedMemory && s->isTLS()) {
-          if (config->isPic) {
+          if (ctx.isPic) {
             // Cache the result of the addionion in local 0
             writeU8(os, WASM_OPCODE_LOCAL_TEE, "local.tee");
             writeUleb128(os, 1, "local 1");
@@ -1339,7 +1339,7 @@ void Writer::createInitMemoryFunction() {
           writeU8(os, WASM_OPCODE_GLOBAL_SET, "GLOBAL_SET");
           writeUleb128(os, WasmSym::tlsBase->getGlobalIndex(),
                        "__tls_base");
-          if (config->isPic) {
+          if (ctx.isPic) {
             writeU8(os, WASM_OPCODE_LOCAL_GET, "local.tee");
             writeUleb128(os, 1, "local 1");
           }
@@ -1687,7 +1687,7 @@ void Writer::createSyntheticSectionsPostLayout() {
 void Writer::run() {
   // For PIC code the table base is assigned dynamically by the loader.
   // For non-PIC, we start at 1 so that accessing table index 0 always traps.
-  if (!config->isPic) {
+  if (!ctx.isPic) {
     if (WasmSym::definedTableBase)
       WasmSym::definedTableBase->setVA(config->tableBase);
     if (WasmSym::definedTableBase32)
@@ -1734,7 +1734,7 @@ void Writer::run() {
   // `__memory_base` import.  Unless we support the extended const expression we
   // can't do addition inside the constant expression, so we much combine the
   // segments into a single one that can live at `__memory_base`.
-  if (config->isPic && !config->extendedConst && !config->sharedMemory) {
+  if (ctx.isPic && !config->extendedConst && !config->sharedMemory) {
     // In shared memory mode all data segments are passive and initialized
     // via __wasm_init_memory.
     log("-- combineOutputSegments");
@@ -1779,7 +1779,7 @@ void Writer::run() {
     // If the input contains a call to `__wasm_call_ctors`, either in one of
     // the input objects or an explicit export from the command-line, we
     // assume ctors and dtors are taken care of already.
-    if (!config->relocatable && !config->isPic &&
+    if (!config->relocatable && !ctx.isPic &&
         !WasmSym::callCtors->isUsedInRegularObj &&
         !WasmSym::callCtors->isExported()) {
       log("-- createCommandExportWrappers");



More information about the llvm-commits mailing list