[lld] [lld][WebAssembly] -r: force -Bstatic (PR #108264)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 11:15:27 PDT 2024


https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/108264

This is a port of a recent ELF linker change: 8cc6a2469.

>From d869c6c1cd44ca12625a616c4b6497168fd33b76 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Wed, 11 Sep 2024 11:13:56 -0700
Subject: [PATCH] [lld][WebAssembly] -r: force -Bstatic

This is a port of a recent ELF linker change: 8cc6a2469.
---
 lld/test/wasm/libsearch.s | 6 ++++++
 lld/wasm/Driver.cpp       | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lld/test/wasm/libsearch.s b/lld/test/wasm/libsearch.s
index 23336510748ce8..5d9b3870a053a3 100644
--- a/lld/test/wasm/libsearch.s
+++ b/lld/test/wasm/libsearch.s
@@ -93,6 +93,12 @@
 // RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls
 // RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
 
+/// -r implies -Bstatic and has precedence over -Bdynamic.
+// RUN: ld.lld -r -Bdynamic %t.o -L%t.dir -lls -o %t3.ro
+// RUN: llvm-readelf -s -h %t3.ro | FileCheck --check-prefix=RELOCATABLE %s
+// RELOCATABLE: Type: REL
+// RELOCATABLE: [[#]] _static
+
 .globl _start, _bar
 _start:
   .functype _start () -> ()
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index cb8fe2534f5fe7..4553c6bf04f230 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -395,7 +395,8 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
       config->isStatic = true;
       break;
     case OPT_Bdynamic:
-      config->isStatic = false;
+      if (!config->relocatable)
+        config->isStatic = false;
       break;
     case OPT_whole_archive:
       inWholeArchive = true;



More information about the llvm-commits mailing list