Skip to content

Commit 2b6c6bb

Browse files
authored
[lld][WebAssembly] Always search *.so for -Bdynamic (#84288)
Search *.so libraries regardless of -pie to make it a bit more straightforward to build non-pie dynamic-linked executables. Flip the default to -Bstatic (unless -pie or -shared is specified) as I think it's what most users expect for the default as of today. The assumption here is that, because dynamic-linking is not widely used for WebAssembly, the most users do not specify -Bdynamic or -Bstatic, expecting static link. Although the recent wasi-sdk ships *.so files, there are not many wasm runtimes providing the support of dynamic-linking. (only emscripten and toywasm as far as i know.)
1 parent 3d86eeb commit 2b6c6bb

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lld/wasm/Config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ struct Configuration {
7272
bool stripAll;
7373
bool stripDebug;
7474
bool stackFirst;
75-
bool isStatic = false;
75+
// Because dyamanic linking under Wasm is still experimental we default to
76+
// static linking
77+
bool isStatic = true;
7678
bool trace;
7779
uint64_t globalBase;
7880
uint64_t initialHeap;

lld/wasm/Driver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ static std::optional<std::string> findFromSearchPaths(StringRef path) {
341341
// search paths.
342342
static std::optional<std::string> searchLibraryBaseName(StringRef name) {
343343
for (StringRef dir : config->searchPaths) {
344-
// Currently we don't enable dynamic linking at all unless -shared or -pie
345-
// are used, so don't even look for .so files in that case..
346-
if (ctx.isPic && !config->isStatic)
344+
if (!config->isStatic)
347345
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".so"))
348346
return s;
349347
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a"))
@@ -556,6 +554,10 @@ static void readConfigs(opt::InputArgList &args) {
556554
config->zStackSize =
557555
args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);
558556

557+
// -Bdynamic by default if -pie or -shared is specified.
558+
if (config->pie || config->shared)
559+
config->isStatic = false;
560+
559561
if (config->maxMemory != 0 && config->noGrowableMemory) {
560562
// Erroring out here is simpler than defining precedence rules.
561563
error("--max-memory is incompatible with --no-growable-memory");

lld/wasm/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ multiclass B<string name, string help1, string help2> {
3838
// The following flags are shared with the ELF linker
3939
def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind defined symbols locally">;
4040

41-
def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries (default)">;
41+
def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries">;
4242

43-
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
43+
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries (default)">;
4444

4545
def build_id: F<"build-id">, HelpText<"Alias for --build-id=fast">;
4646

0 commit comments

Comments
 (0)