[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.)
This commit is contained in:
YAMAMOTO Takashi 2024-06-12 08:45:53 +09:00 committed by GitHub
parent 3d86eebdf8
commit 2b6c6bb498
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -72,7 +72,9 @@ struct Configuration {
bool stripAll;
bool stripDebug;
bool stackFirst;
bool isStatic = false;
// Because dyamanic linking under Wasm is still experimental we default to
// static linking
bool isStatic = true;
bool trace;
uint64_t globalBase;
uint64_t initialHeap;

View File

@ -341,9 +341,7 @@ static std::optional<std::string> findFromSearchPaths(StringRef path) {
// search paths.
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 (ctx.isPic && !config->isStatic)
if (!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"))
@ -556,6 +554,10 @@ static void readConfigs(opt::InputArgList &args) {
config->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 (config->maxMemory != 0 && config->noGrowableMemory) {
// Erroring out here is simpler than defining precedence rules.
error("--max-memory is incompatible with --no-growable-memory");

View File

@ -38,9 +38,9 @@ multiclass B<string name, string help1, string help2> {
// The following flags are shared with the ELF linker
def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind defined symbols locally">;
def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries (default)">;
def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries">;
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries (default)">;
def build_id: F<"build-id">, HelpText<"Alias for --build-id=fast">;