aboutsummaryrefslogtreecommitdiff
path: root/lld/wasm/Driver.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 17:50:40 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 17:50:40 +0900
commitfea7da1b00cc97d742faede2df96c7d327950f49 (patch)
tree4de1d6b4ddc69f4f32daabb11ad5c71ab0cf895e /lld/wasm/Driver.cpp
parent9b99dde0d47102625d93c5d1cbbc04951025a6c9 (diff)
parent0aa930a41f2d1ebf1fa90ec42da8f96d15a4dcbb (diff)
downloadllvm-users/chapuni/cov/single/nextcount.zip
llvm-users/chapuni/cov/single/nextcount.tar.gz
llvm-users/chapuni/cov/single/nextcount.tar.bz2
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/chapuni/cov/single/nextcountusers/chapuni/cov/single/nextcount
Diffstat (limited to 'lld/wasm/Driver.cpp')
-rw-r--r--lld/wasm/Driver.cpp306
1 files changed, 152 insertions, 154 deletions
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 0247195..c3a74dd 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -44,17 +44,16 @@ using namespace llvm::sys;
using namespace llvm::wasm;
namespace lld::wasm {
-ConfigWrapper config;
Ctx ctx;
void errorOrWarn(const llvm::Twine &msg) {
- if (config->noinhibitExec)
+ if (ctx.arg.noinhibitExec)
warn(msg);
else
error(msg);
}
-Ctx::Ctx() : arg(config.c) {}
+Ctx::Ctx() {}
void Ctx::reset() {
arg.~Config();
@@ -268,7 +267,7 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
static void readImportFile(StringRef filename) {
if (std::optional<MemoryBufferRef> buf = readFile(filename))
for (StringRef sym : args::getLines(*buf))
- config->allowUndefinedSymbols.insert(sym);
+ ctx.arg.allowUndefinedSymbols.insert(sym);
}
// Returns slices of MB by parsing MB as an archive file.
@@ -345,7 +344,7 @@ void LinkerDriver::addFile(StringRef path) {
case file_magic::bitcode:
case file_magic::wasm_object: {
auto obj = createObjectFile(mbref, "", 0, inLib);
- if (config->isStatic && isa<SharedFile>(obj)) {
+ if (ctx.arg.isStatic && isa<SharedFile>(obj)) {
error("attempted static link of dynamic object " + path);
break;
}
@@ -364,7 +363,7 @@ void LinkerDriver::addFile(StringRef path) {
}
static std::optional<std::string> findFromSearchPaths(StringRef path) {
- for (StringRef dir : config->searchPaths)
+ for (StringRef dir : ctx.arg.searchPaths)
if (std::optional<std::string> s = findFile(dir, path))
return s;
return std::nullopt;
@@ -373,8 +372,8 @@ static std::optional<std::string> findFromSearchPaths(StringRef path) {
// This is for -l<basename>. We'll look for lib<basename>.a from
// search paths.
static std::optional<std::string> searchLibraryBaseName(StringRef name) {
- for (StringRef dir : config->searchPaths) {
- if (!config->isStatic)
+ for (StringRef dir : ctx.arg.searchPaths) {
+ if (!ctx.arg.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"))
@@ -408,10 +407,10 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
addFile(arg->getValue());
break;
case OPT_Bstatic:
- config->isStatic = true;
+ ctx.arg.isStatic = true;
break;
case OPT_Bdynamic:
- config->isStatic = false;
+ ctx.arg.isStatic = false;
break;
case OPT_whole_archive:
inWholeArchive = true;
@@ -527,99 +526,98 @@ getBuildId(opt::InputArgList &args) {
// Initializes Config members by the command line options.
static void readConfigs(opt::InputArgList &args) {
- config->allowMultipleDefinition =
+ ctx.arg.allowMultipleDefinition =
hasZOption(args, "muldefs") ||
args.hasFlag(OPT_allow_multiple_definition,
OPT_no_allow_multiple_definition, false);
- config->bsymbolic = args.hasArg(OPT_Bsymbolic);
- config->checkFeatures =
+ ctx.arg.bsymbolic = args.hasArg(OPT_Bsymbolic);
+ ctx.arg.checkFeatures =
args.hasFlag(OPT_check_features, OPT_no_check_features, true);
- config->compressRelocations = args.hasArg(OPT_compress_relocations);
- config->demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
- config->disableVerify = args.hasArg(OPT_disable_verify);
- config->emitRelocs = args.hasArg(OPT_emit_relocs);
- config->experimentalPic = args.hasArg(OPT_experimental_pic);
- config->entry = getEntry(args);
- config->exportAll = args.hasArg(OPT_export_all);
- config->exportTable = args.hasArg(OPT_export_table);
- config->growableTable = args.hasArg(OPT_growable_table);
- config->noinhibitExec = args.hasArg(OPT_noinhibit_exec);
+ ctx.arg.compressRelocations = args.hasArg(OPT_compress_relocations);
+ ctx.arg.demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
+ ctx.arg.disableVerify = args.hasArg(OPT_disable_verify);
+ ctx.arg.emitRelocs = args.hasArg(OPT_emit_relocs);
+ ctx.arg.experimentalPic = args.hasArg(OPT_experimental_pic);
+ ctx.arg.entry = getEntry(args);
+ ctx.arg.exportAll = args.hasArg(OPT_export_all);
+ ctx.arg.exportTable = args.hasArg(OPT_export_table);
+ ctx.arg.growableTable = args.hasArg(OPT_growable_table);
+ ctx.arg.noinhibitExec = args.hasArg(OPT_noinhibit_exec);
if (args.hasArg(OPT_import_memory_with_name)) {
- config->memoryImport =
+ ctx.arg.memoryImport =
args.getLastArgValue(OPT_import_memory_with_name).split(",");
} else if (args.hasArg(OPT_import_memory)) {
- config->memoryImport =
+ ctx.arg.memoryImport =
std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
} else {
- config->memoryImport =
+ ctx.arg.memoryImport =
std::optional<std::pair<llvm::StringRef, llvm::StringRef>>();
}
if (args.hasArg(OPT_export_memory_with_name)) {
- config->memoryExport =
- args.getLastArgValue(OPT_export_memory_with_name);
+ ctx.arg.memoryExport = args.getLastArgValue(OPT_export_memory_with_name);
} else if (args.hasArg(OPT_export_memory)) {
- config->memoryExport = memoryName;
+ ctx.arg.memoryExport = memoryName;
} else {
- config->memoryExport = std::optional<llvm::StringRef>();
+ ctx.arg.memoryExport = std::optional<llvm::StringRef>();
}
- config->sharedMemory = args.hasArg(OPT_shared_memory);
- config->soName = args.getLastArgValue(OPT_soname);
- config->importTable = args.hasArg(OPT_import_table);
- config->importUndefined = args.hasArg(OPT_import_undefined);
- config->ltoo = args::getInteger(args, OPT_lto_O, 2);
- if (config->ltoo > 3)
- error("invalid optimization level for LTO: " + Twine(config->ltoo));
+ ctx.arg.sharedMemory = args.hasArg(OPT_shared_memory);
+ ctx.arg.soName = args.getLastArgValue(OPT_soname);
+ ctx.arg.importTable = args.hasArg(OPT_import_table);
+ ctx.arg.importUndefined = args.hasArg(OPT_import_undefined);
+ ctx.arg.ltoo = args::getInteger(args, OPT_lto_O, 2);
+ if (ctx.arg.ltoo > 3)
+ error("invalid optimization level for LTO: " + Twine(ctx.arg.ltoo));
unsigned ltoCgo =
- args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(config->ltoo));
+ args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(ctx.arg.ltoo));
if (auto level = CodeGenOpt::getLevel(ltoCgo))
- config->ltoCgo = *level;
+ ctx.arg.ltoCgo = *level;
else
error("invalid codegen optimization level for LTO: " + Twine(ltoCgo));
- config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
- config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
- config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
- config->mapFile = args.getLastArgValue(OPT_Map);
- config->optimize = args::getInteger(args, OPT_O, 1);
- config->outputFile = args.getLastArgValue(OPT_o);
- config->relocatable = args.hasArg(OPT_relocatable);
- config->gcSections =
- args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !config->relocatable);
+ ctx.arg.ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
+ 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.outputFile = args.getLastArgValue(OPT_o);
+ ctx.arg.relocatable = args.hasArg(OPT_relocatable);
+ ctx.arg.gcSections =
+ args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !ctx.arg.relocatable);
for (auto *arg : args.filtered(OPT_keep_section))
- config->keepSections.insert(arg->getValue());
- config->mergeDataSegments =
+ ctx.arg.keepSections.insert(arg->getValue());
+ ctx.arg.mergeDataSegments =
args.hasFlag(OPT_merge_data_segments, OPT_no_merge_data_segments,
- !config->relocatable);
- config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
- config->printGcSections =
+ !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);
- config->saveTemps = args.hasArg(OPT_save_temps);
- config->searchPaths = args::getStrings(args, OPT_library_path);
- config->shared = args.hasArg(OPT_shared);
- config->shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
- config->stripAll = args.hasArg(OPT_strip_all);
- config->stripDebug = args.hasArg(OPT_strip_debug);
- config->stackFirst = args.hasArg(OPT_stack_first);
- config->trace = args.hasArg(OPT_trace);
- config->thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
- config->thinLTOCachePolicy = CHECK(
+ 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.hasArg(OPT_stack_first);
+ ctx.arg.trace = args.hasArg(OPT_trace);
+ ctx.arg.thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
+ ctx.arg.thinLTOCachePolicy = CHECK(
parseCachePruningPolicy(args.getLastArgValue(OPT_thinlto_cache_policy)),
"--thinlto-cache-policy: invalid cache policy");
- config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
- config->thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) ||
+ ctx.arg.thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
+ ctx.arg.thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) ||
args.hasArg(OPT_thinlto_index_only) ||
args.hasArg(OPT_thinlto_index_only_eq);
- config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
+ ctx.arg.thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
args.hasArg(OPT_thinlto_index_only_eq);
- config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
- config->thinLTOObjectSuffixReplace =
+ ctx.arg.thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
+ ctx.arg.thinLTOObjectSuffixReplace =
getOldNewOptions(args, OPT_thinlto_object_suffix_replace_eq);
- std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
- config->thinLTOPrefixReplaceNativeObject) =
+ std::tie(ctx.arg.thinLTOPrefixReplaceOld, ctx.arg.thinLTOPrefixReplaceNew,
+ ctx.arg.thinLTOPrefixReplaceNativeObject) =
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace_eq);
- if (config->thinLTOEmitIndexFiles && !config->thinLTOIndexOnly) {
+ if (ctx.arg.thinLTOEmitIndexFiles && !ctx.arg.thinLTOIndexOnly) {
if (args.hasArg(OPT_thinlto_object_suffix_replace_eq))
error("--thinlto-object-suffix-replace is not supported with "
"--thinlto-emit-index-files");
@@ -627,45 +625,45 @@ static void readConfigs(opt::InputArgList &args) {
error("--thinlto-prefix-replace is not supported with "
"--thinlto-emit-index-files");
}
- if (!config->thinLTOPrefixReplaceNativeObject.empty() &&
- config->thinLTOIndexOnlyArg.empty()) {
+ if (!ctx.arg.thinLTOPrefixReplaceNativeObject.empty() &&
+ ctx.arg.thinLTOIndexOnlyArg.empty()) {
error("--thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with "
"--thinlto-index-only=");
}
- config->unresolvedSymbols = getUnresolvedSymbolPolicy(args);
- config->whyExtract = args.getLastArgValue(OPT_why_extract);
+ ctx.arg.unresolvedSymbols = getUnresolvedSymbolPolicy(args);
+ ctx.arg.whyExtract = args.getLastArgValue(OPT_why_extract);
errorHandler().verbose = args.hasArg(OPT_verbose);
LLVM_DEBUG(errorHandler().verbose = true);
- config->tableBase = args::getInteger(args, OPT_table_base, 0);
- config->globalBase = args::getInteger(args, OPT_global_base, 0);
- config->initialHeap = args::getInteger(args, OPT_initial_heap, 0);
- config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
- config->maxMemory = args::getInteger(args, OPT_max_memory, 0);
- config->noGrowableMemory = args.hasArg(OPT_no_growable_memory);
- config->zStackSize =
+ 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.noGrowableMemory = args.hasArg(OPT_no_growable_memory);
+ ctx.arg.zStackSize =
args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);
// -Bdynamic by default if -pie or -shared is specified.
- if (config->pie || config->shared)
- config->isStatic = false;
+ if (ctx.arg.pie || ctx.arg.shared)
+ ctx.arg.isStatic = false;
- if (config->maxMemory != 0 && config->noGrowableMemory) {
+ if (ctx.arg.maxMemory != 0 && ctx.arg.noGrowableMemory) {
// Erroring out here is simpler than defining precedence rules.
error("--max-memory is incompatible with --no-growable-memory");
}
// Default value of exportDynamic depends on `-shared`
- config->exportDynamic =
- args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, config->shared);
+ ctx.arg.exportDynamic =
+ args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, ctx.arg.shared);
// Parse wasm32/64.
if (auto *arg = args.getLastArg(OPT_m)) {
StringRef s = arg->getValue();
if (s == "wasm32")
- config->is64 = false;
+ ctx.arg.is64 = false;
else if (s == "wasm64")
- config->is64 = true;
+ ctx.arg.is64 = true;
else
error("invalid target architecture: " + s);
}
@@ -679,36 +677,36 @@ static void readConfigs(opt::InputArgList &args) {
error(arg->getSpelling() + ": expected a positive integer, but got '" +
arg->getValue() + "'");
parallel::strategy = hardware_concurrency(threads);
- config->thinLTOJobs = v;
+ ctx.arg.thinLTOJobs = v;
}
if (auto *arg = args.getLastArg(OPT_thinlto_jobs))
- config->thinLTOJobs = arg->getValue();
+ ctx.arg.thinLTOJobs = arg->getValue();
if (auto *arg = args.getLastArg(OPT_features)) {
- config->features =
+ ctx.arg.features =
std::optional<std::vector<std::string>>(std::vector<std::string>());
for (StringRef s : arg->getValues())
- config->features->push_back(std::string(s));
+ ctx.arg.features->push_back(std::string(s));
}
if (auto *arg = args.getLastArg(OPT_extra_features)) {
- config->extraFeatures =
+ ctx.arg.extraFeatures =
std::optional<std::vector<std::string>>(std::vector<std::string>());
for (StringRef s : arg->getValues())
- config->extraFeatures->push_back(std::string(s));
+ ctx.arg.extraFeatures->push_back(std::string(s));
}
// Legacy --allow-undefined flag which is equivalent to
// --unresolve-symbols=ignore + --import-undefined
if (args.hasArg(OPT_allow_undefined)) {
- config->importUndefined = true;
- config->unresolvedSymbols = UnresolvedPolicy::Ignore;
+ ctx.arg.importUndefined = true;
+ ctx.arg.unresolvedSymbols = UnresolvedPolicy::Ignore;
}
if (args.hasArg(OPT_print_map))
- config->mapFile = "-";
+ ctx.arg.mapFile = "-";
- std::tie(config->buildId, config->buildIdVector) = getBuildId(args);
+ std::tie(ctx.arg.buildId, ctx.arg.buildIdVector) = getBuildId(args);
}
// Some Config members do not directly correspond to any particular
@@ -716,86 +714,86 @@ static void readConfigs(opt::InputArgList &args) {
// This function initialize such members. See Config.h for the details
// of these values.
static void setConfigs() {
- ctx.isPic = config->pie || config->shared;
+ ctx.isPic = ctx.arg.pie || ctx.arg.shared;
if (ctx.isPic) {
- if (config->exportTable)
+ if (ctx.arg.exportTable)
error("-shared/-pie is incompatible with --export-table");
- config->importTable = true;
+ ctx.arg.importTable = true;
} else {
// Default table base. Defaults to 1, reserving 0 for the NULL function
// pointer.
- if (!config->tableBase)
- config->tableBase = 1;
+ if (!ctx.arg.tableBase)
+ ctx.arg.tableBase = 1;
// The default offset for static/global data, for when --global-base is
// not specified on the command line. The precise value of 1024 is
// somewhat arbitrary, and pre-dates wasm-ld (Its the value that
// emscripten used prior to wasm-ld).
- if (!config->globalBase && !config->relocatable && !config->stackFirst)
- config->globalBase = 1024;
+ if (!ctx.arg.globalBase && !ctx.arg.relocatable && !ctx.arg.stackFirst)
+ ctx.arg.globalBase = 1024;
}
- if (config->relocatable) {
- if (config->exportTable)
+ if (ctx.arg.relocatable) {
+ if (ctx.arg.exportTable)
error("--relocatable is incompatible with --export-table");
- if (config->growableTable)
+ if (ctx.arg.growableTable)
error("--relocatable is incompatible with --growable-table");
// Ignore any --import-table, as it's redundant.
- config->importTable = true;
+ ctx.arg.importTable = true;
}
- if (config->shared) {
- if (config->memoryExport.has_value()) {
+ if (ctx.arg.shared) {
+ if (ctx.arg.memoryExport.has_value()) {
error("--export-memory is incompatible with --shared");
}
- if (!config->memoryImport.has_value()) {
- config->memoryImport =
- std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
+ if (!ctx.arg.memoryImport.has_value()) {
+ ctx.arg.memoryImport = std::pair<llvm::StringRef, llvm::StringRef>(
+ defaultModule, memoryName);
}
}
// If neither export-memory nor import-memory is specified, default to
// exporting memory under its default name.
- if (!config->memoryExport.has_value() && !config->memoryImport.has_value()) {
- config->memoryExport = memoryName;
+ if (!ctx.arg.memoryExport.has_value() && !ctx.arg.memoryImport.has_value()) {
+ ctx.arg.memoryExport = memoryName;
}
}
// Some command line options or some combinations of them are not allowed.
// This function checks for such errors.
static void checkOptions(opt::InputArgList &args) {
- if (!config->stripDebug && !config->stripAll && config->compressRelocations)
+ if (!ctx.arg.stripDebug && !ctx.arg.stripAll && ctx.arg.compressRelocations)
error("--compress-relocations is incompatible with output debug"
" information. Please pass --strip-debug or --strip-all");
- if (config->ltoPartitions == 0)
+ if (ctx.arg.ltoPartitions == 0)
error("--lto-partitions: number of threads must be > 0");
- if (!get_threadpool_strategy(config->thinLTOJobs))
- error("--thinlto-jobs: invalid job count: " + config->thinLTOJobs);
+ if (!get_threadpool_strategy(ctx.arg.thinLTOJobs))
+ error("--thinlto-jobs: invalid job count: " + ctx.arg.thinLTOJobs);
- if (config->pie && config->shared)
+ if (ctx.arg.pie && ctx.arg.shared)
error("-shared and -pie may not be used together");
- if (config->outputFile.empty() && !config->thinLTOIndexOnly)
+ if (ctx.arg.outputFile.empty() && !ctx.arg.thinLTOIndexOnly)
error("no output file specified");
- if (config->importTable && config->exportTable)
+ if (ctx.arg.importTable && ctx.arg.exportTable)
error("--import-table and --export-table may not be used together");
- if (config->relocatable) {
- if (!config->entry.empty())
+ if (ctx.arg.relocatable) {
+ if (!ctx.arg.entry.empty())
error("entry point specified for relocatable output file");
- if (config->gcSections)
+ if (ctx.arg.gcSections)
error("-r and --gc-sections may not be used together");
- if (config->compressRelocations)
+ if (ctx.arg.compressRelocations)
error("-r -and --compress-relocations may not be used together");
if (args.hasArg(OPT_undefined))
error("-r -and --undefined may not be used together");
- if (config->pie)
+ if (ctx.arg.pie)
error("-r and -pie may not be used together");
- if (config->sharedMemory)
+ if (ctx.arg.sharedMemory)
error("-r and --shared-memory may not be used together");
- if (config->globalBase)
+ if (ctx.arg.globalBase)
error("-r and --global-base may not by used together");
}
@@ -804,31 +802,31 @@ static void checkOptions(opt::InputArgList &args) {
// mode, to give anyone using them a heads-up that they will be changing.
//
// Also, warn about flags which request explicit exports.
- if (!config->experimentalPic) {
+ if (!ctx.arg.experimentalPic) {
// -shared will change meaning when Module Linking is implemented.
- if (config->shared) {
+ if (ctx.arg.shared) {
warn("creating shared libraries, with -shared, is not yet stable");
}
// -pie will change meaning when Module Linking is implemented.
- if (config->pie) {
+ if (ctx.arg.pie) {
warn("creating PIEs, with -pie, is not yet stable");
}
- if (config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic) {
+ if (ctx.arg.unresolvedSymbols == UnresolvedPolicy::ImportDynamic) {
warn("dynamic imports are not yet stable "
"(--unresolved-symbols=import-dynamic)");
}
}
- if (config->bsymbolic && !config->shared) {
+ if (ctx.arg.bsymbolic && !ctx.arg.shared) {
warn("-Bsymbolic is only meaningful when combined with -shared");
}
if (ctx.isPic) {
- if (config->globalBase)
+ if (ctx.arg.globalBase)
error("--global-base may not be used with -shared/-pie");
- if (config->tableBase)
+ if (ctx.arg.tableBase)
error("--table-base may not be used with -shared/-pie");
}
}
@@ -851,7 +849,7 @@ static Symbol *handleUndefined(StringRef name, const char *option) {
if (auto *lazySym = dyn_cast<LazySymbol>(sym)) {
lazySym->extract();
- if (!config->whyExtract.empty())
+ if (!ctx.arg.whyExtract.empty())
ctx.whyExtractRecords.emplace_back(option, sym->getFile(), *sym);
}
@@ -861,20 +859,20 @@ static Symbol *handleUndefined(StringRef name, const char *option) {
static void handleLibcall(StringRef name) {
Symbol *sym = symtab->find(name);
if (sym && sym->isLazy() && isa<BitcodeFile>(sym->getFile())) {
- if (!config->whyExtract.empty())
+ if (!ctx.arg.whyExtract.empty())
ctx.whyExtractRecords.emplace_back("<libcall>", sym->getFile(), *sym);
cast<LazySymbol>(sym)->extract();
}
}
static void writeWhyExtract() {
- if (config->whyExtract.empty())
+ if (ctx.arg.whyExtract.empty())
return;
std::error_code ec;
- raw_fd_ostream os(config->whyExtract, ec, sys::fs::OF_None);
+ raw_fd_ostream os(ctx.arg.whyExtract, ec, sys::fs::OF_None);
if (ec) {
- error("cannot open --why-extract= file " + config->whyExtract + ": " +
+ error("cannot open --why-extract= file " + ctx.arg.whyExtract + ": " +
ec.message());
return;
}
@@ -905,14 +903,14 @@ static UndefinedGlobal *
createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
auto *sym = cast<UndefinedGlobal>(symtab->addUndefinedGlobal(
name, std::nullopt, std::nullopt, WASM_SYMBOL_UNDEFINED, nullptr, type));
- config->allowUndefinedSymbols.insert(sym->getName());
+ ctx.arg.allowUndefinedSymbols.insert(sym->getName());
sym->isUsedInRegularObj = true;
return sym;
}
static InputGlobal *createGlobal(StringRef name, bool isMutable) {
llvm::wasm::WasmGlobal wasmGlobal;
- bool is64 = config->is64.value_or(false);
+ bool is64 = ctx.arg.is64.value_or(false);
wasmGlobal.Type = {uint8_t(is64 ? WASM_TYPE_I64 : WASM_TYPE_I32), isMutable};
wasmGlobal.InitExpr = intConst(0, is64);
wasmGlobal.SymbolName = name;
@@ -931,7 +929,7 @@ static GlobalSymbol *createOptionalGlobal(StringRef name, bool isMutable) {
// Create ABI-defined synthetic symbols
static void createSyntheticSymbols() {
- if (config->relocatable)
+ if (ctx.arg.relocatable)
return;
static WasmSignature nullSignature = {{}, {}};
@@ -947,11 +945,11 @@ static void createSyntheticSymbols() {
"__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN,
make<SyntheticFunction>(nullSignature, "__wasm_call_ctors"));
- bool is64 = config->is64.value_or(false);
+ bool is64 = ctx.arg.is64.value_or(false);
if (ctx.isPic) {
WasmSym::stackPointer =
- createUndefinedGlobal("__stack_pointer", config->is64.value_or(false)
+ createUndefinedGlobal("__stack_pointer", ctx.arg.is64.value_or(false)
? &mutableGlobalTypeI64
: &mutableGlobalTypeI32);
// For PIC code, we import two global variables (__memory_base and
@@ -970,7 +968,7 @@ static void createSyntheticSymbols() {
WasmSym::stackPointer->markLive();
}
- if (config->sharedMemory) {
+ if (ctx.arg.sharedMemory) {
WasmSym::tlsBase = createGlobalVariable("__tls_base", true);
WasmSym::tlsSize = createGlobalVariable("__tls_size", false);
WasmSym::tlsAlign = createGlobalVariable("__tls_align", false);
@@ -983,12 +981,12 @@ static void createSyntheticSymbols() {
}
static void createOptionalSymbols() {
- if (config->relocatable)
+ if (ctx.arg.relocatable)
return;
WasmSym::dsoHandle = symtab->addOptionalDataSymbol("__dso_handle");
- if (!config->shared)
+ if (!ctx.arg.shared)
WasmSym::dataEnd = symtab->addOptionalDataSymbol("__data_end");
if (!ctx.isPic) {
@@ -1010,7 +1008,7 @@ static void createOptionalSymbols() {
//
// __tls_size and __tls_align are not needed in this case since they are only
// needed for __wasm_init_tls (which we do not create in this case).
- if (!config->sharedMemory)
+ if (!ctx.arg.sharedMemory)
WasmSym::tlsBase = createOptionalGlobal("__tls_base", false);
}
@@ -1035,7 +1033,7 @@ static void processStubLibrariesPreLTO() {
// extracted during processStubLibraries, which is too late since
// LTO has already being performed at that point.
if (needed->isLazy() && isa<BitcodeFile>(needed->getFile())) {
- if (!config->whyExtract.empty())
+ if (!ctx.arg.whyExtract.empty())
ctx.whyExtractRecords.emplace_back(toString(stub_file),
needed->getFile(), *needed);
cast<LazySymbol>(needed)->extract();
@@ -1079,7 +1077,7 @@ static bool addStubSymbolDeps(const StubFile *stub_file, Symbol *sym,
if (auto *lazy = dyn_cast<LazySymbol>(needed)) {
depsAdded = true;
lazy->extract();
- if (!config->whyExtract.empty())
+ if (!ctx.arg.whyExtract.empty())
ctx.whyExtractRecords.emplace_back(toString(stub_file),
sym->getFile(), *sym);
}