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

YAMAMOTO Takashi via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 00:34:43 PDT 2024


https://github.com/yamt updated https://github.com/llvm/llvm-project/pull/84288

>From 8e9d026741f255c6d010d717de3439669e52dbb2 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 1/3] [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 266348fef4031..c351e1cef1053 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 d5d763b0a4ae1..dbe576b91d2ef 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -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"))
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index 70b5aadc26c2a..7e954822ef642 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">;
 

>From 8eef814861badc8aa8d2918b1433102adf08029c Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Fri, 15 Mar 2024 17:30:25 +0900
Subject: [PATCH 2/3] [lld][WebAssembly] -Bdynamic by default if -pie or
 -shared is specified

---
 lld/wasm/Driver.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index dbe576b91d2ef..f532b6e80f034 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -554,6 +554,11 @@ 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");

>From 6b41b22435e4f9f7884ca4cb729492ea244514db Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Fri, 17 May 2024 16:34:01 +0900
Subject: [PATCH 3/3] [lld][WebAssembly] Add a comment on isStatic default

---
 lld/wasm/Config.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index c351e1cef1053..d0ffa83d111e0 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -72,6 +72,8 @@ struct Configuration {
   bool stripAll;
   bool stripDebug;
   bool stackFirst;
+  // Because dyamanic linking under Wasm is still experimental we default to
+  // static linking
   bool isStatic = true;
   bool trace;
   uint64_t globalBase;



More information about the llvm-commits mailing list