Skip to content

feat: Decode medium-model TLS static relocations in ppc64le - #2724

Merged
lapla-cogito merged 6 commits into
wild-linker:mainfrom
lapla-cogito:ppc64le_tlsreloc
Oct 15, 2026
Merged

lapla-cogito merged 6 commits into
wild-linker:mainfrom
lapla-cogito:ppc64le_tlsreloc

Conversation

@lapla-cogito

Copy link
Copy Markdown
Member

Accept local-exec, initial-exec, local-dynamic, and general-dynamic sequences. DTPREL is relative to the TLS segment start plus 0x8000, and an executable's TLSLD GOT offset slot stays zero because __tls_get_addr adds that bias.

Comment thread libwild/src/elf_writer.rs Outdated
Comment thread libwild/src/elf_writer.rs Outdated
Comment thread libwild/src/platform.rs Outdated
Comment thread wild/tests/sources/elf/ppc64-tls/ppc64-tls.c Outdated
//#Config:global-dynamic:pie
//#CompArgs:-fPIC -ftls-model=global-dynamic

//#Config:local-exec-no-pie:default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about something that roughly combines this test with the next one. e.g. the following test, which fails:

diff --git a/wild/tests/sources/elf/ppc64-tls/ppc64-tls-dso.c b/wild/tests/sources/elf/ppc64-tls/ppc64-tls-dso.c
index db529ec652..6059c8a00b 100644
--- a/wild/tests/sources/elf/ppc64-tls/ppc64-tls-dso.c
+++ b/wild/tests/sources/elf/ppc64-tls/ppc64-tls-dso.c
@@ -1,4 +1,5 @@
 static __thread long dso_tls = 40;
 static __thread char dso_tls_byte = 2;
+__thread int imported_tls = 42;
 
 int ppc64_tls_dso_value(void) { return (int)dso_tls + dso_tls_byte; }
diff --git a/wild/tests/sources/elf/ppc64-tls/ppc64-tls.c b/wild/tests/sources/elf/ppc64-tls/ppc64-tls.c
index f472679ffc..dbb27c6417 100644
--- a/wild/tests/sources/elf/ppc64-tls/ppc64-tls.c
+++ b/wild/tests/sources/elf/ppc64-tls/ppc64-tls.c
@@ -26,6 +26,13 @@
 //#CompArgs:-fno-pie -ftls-model=local-exec
 //#LinkArgs:-no-pie
 
+//#Config:local-exec-import-no-pie:local-exec-no-pie
+//#CompArgs:-DPPC64_TLS_IMPORT
+//#CompSoArgs:-fPIC
+//#Shared:ppc64-tls-dso.c
+//#ReferenceLinkers:lld
+//#ExpectError:relocation R_PPC64_TPREL16_.*cannot be used against symbol
+
 // A local-exec TLS reference inside the shared object itself. The thread-pointer offset is not
 // known when linking a DSO. GNU ld accepts this with DF_STATIC_TLS and text relocations; wild
 // rejects it.
@@ -49,11 +56,17 @@
 extern int ppc64_tls_dso_value(void);
 #endif
 
+#if defined(PPC64_TLS_IMPORT)
+extern __thread int imported_tls;
+#endif
+
 static __thread long local_tls = 40;
 static __thread char local_tls_byte = 2;
 
 int main(void) {
-#if defined(PPC64_TLS_DSO)
+#if defined(PPC64_TLS_IMPORT)
+  return imported_tls;
+#elif defined(PPC64_TLS_DSO)
   return ppc64_tls_dso_value();
 #else
   return (int)local_tls + local_tls_byte;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks! Fixed it.

@lapla-cogito
lapla-cogito enabled auto-merge (squash) October 15, 2026 06:24
@lapla-cogito
lapla-cogito merged commit 40bdf28 into wild-linker:main Oct 15, 2026
26 checks passed
@lapla-cogito
lapla-cogito deleted the ppc64le_tlsreloc branch October 15, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants