[lld] r364367 - [WebAssembly] Fix list of relocations with addends in lld

Keno Fischer via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 17:52:42 PDT 2019


Author: kfischer
Date: Tue Jun 25 17:52:42 2019
New Revision: 364367

URL: http://llvm.org/viewvc/llvm-project?rev=364367&view=rev
Log:
[WebAssembly] Fix list of relocations with addends in lld

Summary:
The list of relocations with addend in lld was missing `R_WASM_MEMORY_ADDR_REL_SLEB`,
causing `wasm-ld` to generate corrupted output. This fixes that problem and while
we're at it pulls the list of such relocations into the Wasm.h header, to avoid
duplicating it in multiple places.

Reviewers: sbc100
Differential Revision: https://reviews.llvm.org/D63696

Added:
    lld/trunk/test/wasm/emit-relocs-fpic.s
Modified:
    lld/trunk/test/wasm/lit.local.cfg
    lld/trunk/wasm/InputChunks.cpp

Added: lld/trunk/test/wasm/emit-relocs-fpic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/emit-relocs-fpic.s?rev=364367&view=auto
==============================================================================
--- lld/trunk/test/wasm/emit-relocs-fpic.s (added)
+++ lld/trunk/test/wasm/emit-relocs-fpic.s Tue Jun 25 17:52:42 2019
@@ -0,0 +1,20 @@
+# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -o %t.o < %s
+# RUN: llc --relocation-model=pic -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
+# RUN: wasm-ld -pie --export-all --no-gc-sections --no-entry --emit-relocs -o %t.wasm %t.o %t.ret32.o
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+load_hidden_data:
+    .functype   load_hidden_data () -> (i32)
+    i32.const   .L.hidden_data at MBREL
+    end_function
+
+.section .rodata.hidden_data,"",@
+.L.hidden_data:
+    .int8 100
+    .size .L.hidden_data, 1
+
+# We just want to make sure that processing this relocation doesn't
+# cause corrupt output. We get most of the way there, by just checking
+# that obj2yaml doesn't fail. Here we just make sure that the relocation
+# survived the trip.
+# CHECK: R_WASM_MEMORY_ADDR_REL_SLEB

Modified: lld/trunk/test/wasm/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/lit.local.cfg?rev=364367&r1=364366&r2=364367&view=diff
==============================================================================
--- lld/trunk/test/wasm/lit.local.cfg (original)
+++ lld/trunk/test/wasm/lit.local.cfg Tue Jun 25 17:52:42 2019
@@ -1,4 +1,4 @@
 if 'wasm' not in config.available_features:
   config.unsupported = True
 
-config.suffixes = ['.test', '.yaml', '.ll']
+config.suffixes = ['.test', '.yaml', '.ll', '.s']

Modified: lld/trunk/wasm/InputChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.cpp?rev=364367&r1=364366&r2=364367&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.cpp (original)
+++ lld/trunk/wasm/InputChunks.cpp Tue Jun 25 17:52:42 2019
@@ -154,15 +154,8 @@ void InputChunk::writeRelocations(raw_os
     writeUleb128(OS, Rel.Offset + Off, "reloc offset");
     writeUleb128(OS, File->calcNewIndex(Rel), "reloc index");
 
-    switch (Rel.Type) {
-    case R_WASM_MEMORY_ADDR_LEB:
-    case R_WASM_MEMORY_ADDR_SLEB:
-    case R_WASM_MEMORY_ADDR_I32:
-    case R_WASM_FUNCTION_OFFSET_I32:
-    case R_WASM_SECTION_OFFSET_I32:
+    if (relocTypeHasAddend(Rel.Type))
       writeSleb128(OS, File->calcNewAddend(Rel), "reloc addend");
-      break;
-    }
   }
 }
 




More information about the llvm-commits mailing list