[lld] [lld][WebAssembly] Always search *.so for -Bdynamic (PR #84288)

YAMAMOTO Takashi via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 00:42:01 PST 2024


https://github.com/yamt created https://github.com/llvm/llvm-project/pull/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 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.

>From 83c1f91b30a0987d91357fe88de38da7dacfbe56 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Thu, 7 Mar 2024 17:33:24 +0900
Subject: [PATCH] [lld][WebAssembly] Always search *.so for -Bdynamic

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 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.
---
 lld/wasm/Config.h   | 2 +-
 lld/wasm/Driver.cpp | 4 +---
 lld/wasm/Options.td | 4 ++--
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 266348fef40316..c351e1cef10532 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -72,7 +72,7 @@ struct Configuration {
   bool stripAll;
   bool stripDebug;
   bool stackFirst;
-  bool isStatic = false;
+  bool isStatic = true;
   bool trace;
   uint64_t globalBase;
   uint64_t initialHeap;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index df7d4d1cc3d679..2599eca9389348 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -331,9 +331,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"))
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index 70b5aadc26c2a0..7e954822ef6425 100644
--- a/lld/wasm/Options.td
+++ b/lld/wasm/Options.td
@@ -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">;
 



More information about the llvm-commits mailing list