Skip to content

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Sep 11, 2024

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

@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2024

@llvm/pr-subscribers-lld

Author: Sam Clegg (sbc100)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/108264.diff

2 Files Affected:

  • (modified) lld/test/wasm/libsearch.s (+6)
  • (modified) lld/wasm/Driver.cpp (+2-1)
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;

@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2024

@llvm/pr-subscribers-lld-wasm

Author: Sam Clegg (sbc100)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/108264.diff

2 Files Affected:

  • (modified) lld/test/wasm/libsearch.s (+6)
  • (modified) lld/wasm/Driver.cpp (+2-1)
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;

// 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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I didn't mean to send this for review until I'd finished porting this test fragment.

@sbc100 sbc100 marked this pull request as draft September 11, 2024 18:16
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(On vacation and slow/inconvenient to respond). Happy when the other reviewer is happy.

Prefer llvm-readobj to llvm-readelf for wasm.

@sbc100 sbc100 force-pushed the relocatable_static branch 2 times, most recently from 87adf89 to e952ae3 Compare August 27, 2025 01:00
This is a port of a recent ELF linker change: 8cc6a24.
@sbc100 sbc100 force-pushed the relocatable_static branch from e952ae3 to cfa0857 Compare August 27, 2025 01:09
@sbc100 sbc100 marked this pull request as ready for review August 27, 2025 01:09
@sbc100 sbc100 enabled auto-merge (squash) August 27, 2025 01:09
@sbc100 sbc100 merged commit e3823a6 into llvm:main Aug 27, 2025
11 checks passed
@sbc100 sbc100 deleted the relocatable_static branch August 27, 2025 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants