[lld] [lld][WebAssembly] Move command-line option defaults into Config.h. NFC (PR #227911)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 16:57:37 PDT 2026


https://github.com/sbc100 updated https://github.com/llvm/llvm-project/pull/227911

>From d1be3ced62f83cb96c9693aca2220bb37eb2c30d Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Wed, 30 Sep 2026 16:35:02 -0700
Subject: [PATCH] [lld][WebAssembly] Move command-line option defaults into
 Config.h. NFC

Initialize all `Config` struct members with their default values in
`Config.h` and reference those defaults when parsing flags in
`Driver.cpp`.

This keeps the default values alongside the declarations which makes
finding them easier (IMHO).
---
 lld/wasm/Config.h   | 99 ++++++++++++++++++++++-----------------------
 lld/wasm/Driver.cpp | 43 +++++++++++---------
 2 files changed, 73 insertions(+), 69 deletions(-)

diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 260df6f9b8e24f..b80653bbab6ce5 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -15,12 +15,9 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/BinaryFormat/Wasm.h"
 #include "llvm/Support/CachePruning.h"
+#include "llvm/Support/CodeGen.h"
 #include <optional>
 
-namespace llvm {
-enum class CodeGenOptLevel;
-} // namespace llvm
-
 namespace lld::wasm {
 
 class InputFile;
@@ -52,65 +49,65 @@ enum class BuildIdKind { None, Fast, Sha1, Hexstring, Uuid };
 // and such fields have the same name as the corresponding options.
 // Most fields are initialized by the driver.
 struct Config {
-  bool allowMultipleDefinition;
-  bool bsymbolic;
-  bool checkFeatures;
-  bool compressRelocations;
-  bool demangle;
-  bool disableVerify;
-  bool emitRelocs;
-  bool exportAll;
-  bool exportDynamic;
-  bool exportTable;
-  bool extendedConst;
-  bool growableTable;
-  bool gcSections;
+  bool allowMultipleDefinition = false;
+  bool bsymbolic = false;
+  bool checkFeatures = true;
+  bool compressRelocations = false;
+  bool demangle = true;
+  bool disableVerify = false;
+  bool emitRelocs = false;
+  bool exportAll = false;
+  bool exportDynamic = false;
+  bool exportTable = false;
+  bool extendedConst = false;
+  bool growableTable = false;
+  bool gcSections = true;
   llvm::StringSet<> keepSections;
-  bool cooperativeThreading;
-  bool libcallThreadContext;
+  bool cooperativeThreading = false;
+  bool libcallThreadContext = false;
   std::optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport;
   std::optional<llvm::StringRef> memoryExport;
-  bool sharedMemory;
-  bool importTable;
-  bool importUndefined;
+  bool sharedMemory = false;
+  bool importTable = false;
+  bool importUndefined = false;
   std::optional<bool> is64;
-  bool mergeDataSegments;
-  bool noinhibitExec;
-  bool pie;
-  bool printGcSections;
-  bool relocatable;
-  bool saveTemps;
-  bool shared;
-  bool shlibSigCheck;
-  bool stripAll;
-  bool stripDebug;
-  bool stackFirst;
+  bool mergeDataSegments = true;
+  bool noinhibitExec = false;
+  bool pie = false;
+  bool printGcSections = false;
+  bool relocatable = false;
+  bool saveTemps = false;
+  bool shared = false;
+  bool shlibSigCheck = true;
+  bool stripAll = false;
+  bool stripDebug = false;
+  bool stackFirst = true;
   // Static linking is currently the default under WebAssembly.  This may
   // change as some point in the future if dynamic linking becomes more widely
   // used.
   bool isStatic = true;
-  bool thinLTOEmitImportsFiles;
-  bool thinLTOEmitIndexFiles;
-  bool thinLTOIndexOnly;
-  bool trace;
-  uint64_t globalBase;
-  uint64_t initialHeap;
-  uint64_t initialMemory;
-  uint64_t maxMemory;
-  bool noGrowableMemory;
+  bool thinLTOEmitImportsFiles = false;
+  bool thinLTOEmitIndexFiles = false;
+  bool thinLTOIndexOnly = false;
+  bool trace = false;
+  uint64_t globalBase = 0;
+  uint64_t initialHeap = 0;
+  uint64_t initialMemory = 0;
+  uint64_t maxMemory = 0;
+  bool noGrowableMemory = 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).
-  uint64_t tableBase;
-  uint64_t zStackSize;
-  uint64_t pageSize;
-  unsigned ltoPartitions;
-  unsigned ltoo;
-  llvm::CodeGenOptLevel ltoCgo;
-  unsigned optimize;
-  bool ltoDebugPassManager;
-  UnresolvedPolicy unresolvedSymbols;
+  uint64_t tableBase = 0;
+  uint64_t zStackSize = llvm::wasm::WasmDefaultPageSize;
+  uint64_t pageSize = llvm::wasm::WasmDefaultPageSize;
+  unsigned ltoPartitions = 1;
+  unsigned ltoo = 2;
+  llvm::CodeGenOptLevel ltoCgo = llvm::CodeGenOptLevel::Default;
+  unsigned optimize = 1;
+  bool ltoDebugPassManager = false;
+  UnresolvedPolicy unresolvedSymbols = UnresolvedPolicy::ReportError;
   BuildIdKind buildId = BuildIdKind::None;
 
   llvm::StringRef entry;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 1de9851d5ed3ee..a191cdffb477a2 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -497,12 +497,14 @@ static void readConfigs(opt::InputArgList &args) {
   ctx.arg.allowMultipleDefinition =
       hasZOption(args, "muldefs") ||
       args.hasFlag(OPT_allow_multiple_definition,
-                   OPT_no_allow_multiple_definition, false);
+                   OPT_no_allow_multiple_definition,
+                   ctx.arg.allowMultipleDefinition);
   ctx.arg.bsymbolic = args.hasArg(OPT_Bsymbolic);
-  ctx.arg.checkFeatures =
-      args.hasFlag(OPT_check_features, OPT_no_check_features, true);
+  ctx.arg.checkFeatures = args.hasFlag(
+      OPT_check_features, OPT_no_check_features, ctx.arg.checkFeatures);
   ctx.arg.compressRelocations = args.hasArg(OPT_compress_relocations);
-  ctx.arg.demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
+  ctx.arg.demangle =
+      args.hasFlag(OPT_demangle, OPT_no_demangle, ctx.arg.demangle);
   ctx.arg.disableVerify = args.hasArg(OPT_disable_verify);
   ctx.arg.emitRelocs = args.hasArg(OPT_emit_relocs);
   ctx.arg.entry = getEntry(args);
@@ -532,7 +534,7 @@ static void readConfigs(opt::InputArgList &args) {
   ctx.arg.importTable = args.hasArg(OPT_import_table);
   ctx.arg.importUndefined = args.hasArg(OPT_import_undefined);
   ctx.arg.cooperativeThreading = args.hasArg(OPT_cooperative_threading);
-  ctx.arg.ltoo = args::getInteger(args, OPT_lto_O, 2);
+  ctx.arg.ltoo = args::getInteger(args, OPT_lto_O, ctx.arg.ltoo);
   if (ctx.arg.ltoo > 3)
     error("invalid optimization level for LTO: " + Twine(ctx.arg.ltoo));
   unsigned ltoCgo =
@@ -541,11 +543,12 @@ static void readConfigs(opt::InputArgList &args) {
     ctx.arg.ltoCgo = *level;
   else
     error("invalid codegen optimization level for LTO: " + Twine(ltoCgo));
-  ctx.arg.ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
+  ctx.arg.ltoPartitions =
+      args::getInteger(args, OPT_lto_partitions, ctx.arg.ltoPartitions);
   ctx.arg.ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
   ctx.arg.ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
   ctx.arg.mapFile = args.getLastArgValue(OPT_Map);
-  ctx.arg.optimize = args::getInteger(args, OPT_O, 1);
+  ctx.arg.optimize = args::getInteger(args, OPT_O, ctx.arg.optimize);
   ctx.arg.outputFile = args.getLastArgValue(OPT_o);
   ctx.arg.relocatable = args.hasArg(OPT_relocatable);
   ctx.arg.rpath = args::getStrings(args, OPT_rpath);
@@ -556,16 +559,17 @@ static void readConfigs(opt::InputArgList &args) {
   ctx.arg.mergeDataSegments =
       args.hasFlag(OPT_merge_data_segments, OPT_no_merge_data_segments,
                    !ctx.arg.relocatable);
-  ctx.arg.pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
-  ctx.arg.printGcSections =
-      args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);
+  ctx.arg.pie = args.hasFlag(OPT_pie, OPT_no_pie, ctx.arg.pie);
+  ctx.arg.printGcSections = args.hasFlag(
+      OPT_print_gc_sections, OPT_no_print_gc_sections, ctx.arg.printGcSections);
   ctx.arg.saveTemps = args.hasArg(OPT_save_temps);
   ctx.arg.searchPaths = args::getStrings(args, OPT_library_path);
   ctx.arg.shared = args.hasArg(OPT_shared);
   ctx.arg.shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
   ctx.arg.stripAll = args.hasArg(OPT_strip_all);
   ctx.arg.stripDebug = args.hasArg(OPT_strip_debug);
-  ctx.arg.stackFirst = args.hasFlag(OPT_stack_first, OPT_no_stack_first, true);
+  ctx.arg.stackFirst =
+      args.hasFlag(OPT_stack_first, OPT_no_stack_first, ctx.arg.stackFirst);
   ctx.arg.trace = args.hasArg(OPT_trace);
   ctx.arg.thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
   ctx.arg.thinLTOCachePolicy = CHECK(
@@ -601,15 +605,18 @@ static void readConfigs(opt::InputArgList &args) {
   errorHandler().verbose = args.hasArg(OPT_verbose);
   LLVM_DEBUG(errorHandler().verbose = true);
 
-  ctx.arg.tableBase = args::getInteger(args, OPT_table_base, 0);
-  ctx.arg.globalBase = args::getInteger(args, OPT_global_base, 0);
-  ctx.arg.initialHeap = args::getInteger(args, OPT_initial_heap, 0);
-  ctx.arg.initialMemory = args::getInteger(args, OPT_initial_memory, 0);
-  ctx.arg.maxMemory = args::getInteger(args, OPT_max_memory, 0);
+  ctx.arg.tableBase = args::getInteger(args, OPT_table_base, ctx.arg.tableBase);
+  ctx.arg.globalBase =
+      args::getInteger(args, OPT_global_base, ctx.arg.globalBase);
+  ctx.arg.initialHeap =
+      args::getInteger(args, OPT_initial_heap, ctx.arg.initialHeap);
+  ctx.arg.initialMemory =
+      args::getInteger(args, OPT_initial_memory, ctx.arg.initialMemory);
+  ctx.arg.maxMemory = args::getInteger(args, OPT_max_memory, ctx.arg.maxMemory);
   ctx.arg.noGrowableMemory = args.hasArg(OPT_no_growable_memory);
   ctx.arg.zStackSize =
-      args::getZOptionValue(args, OPT_z, "stack-size", WasmDefaultPageSize);
-  ctx.arg.pageSize = args::getInteger(args, OPT_page_size, WasmDefaultPageSize);
+      args::getZOptionValue(args, OPT_z, "stack-size", ctx.arg.zStackSize);
+  ctx.arg.pageSize = args::getInteger(args, OPT_page_size, ctx.arg.pageSize);
   if (ctx.arg.pageSize != 1 && ctx.arg.pageSize != WasmDefaultPageSize)
     error("--page_size=N must be either 1 or 65536");
 



More information about the llvm-commits mailing list