[lld] [WebAssembly] Fix __init_tls_base global in coop threading (PR #208597)

Alex Crichton via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 18:11:55 PDT 2026


================
@@ -1092,16 +1092,20 @@ void Writer::createOutputSegments() {
     }
   }
 
-  // Sort segments by type, placing .bss last
+  // Sort segments by type, placing .bss last. Note that one requirement of
+  // this sort is that all eventually-active segments must come first in
+  // case `combineActiveOutputSegments` is used. When combined the relative
+  // address of the data segment must be 0 (to be compatible with PIC and a
+  // lack of extended-const).
   llvm::stable_sort(segments,
                     [](const OutputSegment *a, const OutputSegment *b) {
                       auto order = [](StringRef name) {
                         return StringSwitch<int>(name)
-                            .StartsWith(".tdata", 0)
-                            .StartsWith(".rodata", 1)
-                            .StartsWith(".data", 2)
+                            .StartsWith(".rodata", 0)
+                            .StartsWith(".data", 1)
+                            .StartsWith(".tdata", 3)
                             .StartsWith(".bss", 4)
----------------
alexcrichton wrote:

Indeed yeah, and that's split out as https://github.com/llvm/llvm-project/pull/208332. Sorry I wasn't sure if it was premature to make a stacked PR in LLVM (and github in general doesn't handle stacked PRs well) so this Pr may have been jumping the gun

https://github.com/llvm/llvm-project/pull/208597


More information about the llvm-commits mailing list