[lld] 356b85e - [lld][WebAssembly] Fix for string tail merging and -r/--relocatable

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed May 19 15:26:07 PDT 2021


Author: Sam Clegg
Date: 2021-05-19T15:25:58-07:00
New Revision: 356b85edd78311ae7376f4b271c48b9f0156aeea

URL: https://github.com/llvm/llvm-project/commit/356b85edd78311ae7376f4b271c48b9f0156aeea
DIFF: https://github.com/llvm/llvm-project/commit/356b85edd78311ae7376f4b271c48b9f0156aeea.diff

LOG: [lld][WebAssembly] Fix for string tail merging and -r/--relocatable

Ensure that both SyntheticMergedChunk and all MergeInfoChunks that it
comprises are assigned the correct output section.  Without this we
would crash when outputting relocations in --relocatable mode.

Fixes: https://github.com/emscripten-core/emscripten/issues/14220

Differential Revision: https://reviews.llvm.org/D102806

Added: 
    

Modified: 
    lld/test/wasm/merge-string-debug.s
    lld/wasm/OutputSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/merge-string-debug.s b/lld/test/wasm/merge-string-debug.s
index 4a663501959fe..961cdabb0c850 100644
--- a/lld/test/wasm/merge-string-debug.s
+++ b/lld/test/wasm/merge-string-debug.s
@@ -4,13 +4,23 @@
 # RUN: wasm-ld %t.o %t2.o -o %t.wasm --no-entry
 # RUN: llvm-readobj -x .debug_str %t.wasm | FileCheck %s --check-prefixes CHECK,CHECK-O1
 
+# Check that we -r/--reclocatable can handle string merging too
+# RUN: wasm-ld --relocatable %t.o %t2.o -o %t3.o
+# RUN: wasm-ld -O1 %t3.o -o %t.wasm --no-entry
+# RUN: llvm-readobj -x .debug_str %t.wasm | FileCheck %s --check-prefixes CHECK,CHECK-O1
+
 # RUN: wasm-ld -O0 %t.o %t2.o -o %tO0.wasm --no-entry
 # RUN: llvm-readobj -x .debug_str %tO0.wasm | FileCheck %s --check-prefixes CHECK,CHECK-O0
 
 .section .debug_str,"S",@
+.Linfo_string0:
   .asciz "clang version 13.0.0"
+.Linfo_string1:
   .asciz "foobar"
 
+.section .debug_other,"",@
+  .int32 .Linfo_string0
+
 # CHECK: Hex dump of section '.debug_str':
 
 # CHECK-O0: 0x00000000 636c616e 67207665 7273696f 6e203133 clang version 13

diff  --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp
index e39c3331641a9..28f611712536e 100644
--- a/lld/wasm/OutputSections.cpp
+++ b/lld/wasm/OutputSections.cpp
@@ -241,6 +241,7 @@ void CustomSection::finalizeInputSections() {
   std::vector<InputChunk *> newSections;
 
   for (InputChunk *s : inputSections) {
+    s->outputSec = this;
     MergeInputChunk *ms = dyn_cast<MergeInputChunk>(s);
     if (!ms) {
       newSections.push_back(s);
@@ -251,6 +252,7 @@ void CustomSection::finalizeInputSections() {
       mergedSection =
           make<SyntheticMergedChunk>(name, 0, WASM_SEG_FLAG_STRINGS);
       newSections.push_back(mergedSection);
+      mergedSection->outputSec = this;
     }
     mergedSection->addMergeChunk(ms);
   }
@@ -272,7 +274,6 @@ void CustomSection::finalizeContents() {
 
   for (InputChunk *section : inputSections) {
     assert(!section->discarded);
-    section->outputSec = this;
     section->outSecOff = payloadSize;
     payloadSize += section->getSize();
   }


        


More information about the llvm-commits mailing list