[PATCH] D45825: [WebAssembly] Fix bug where reloc addends were written as unsigned

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 19 10:10:44 PDT 2018


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.
sbc100 updated this revision to Diff 143117.
sbc100 added a comment.
sbc100 added a reviewer: jgravelle-google.

whitespace


relocation addends can be negative so should be written as
signed LEBs. This bug meant that writing value between 64
and 128 would be incorrectly interpreted as negative by the
object file readers.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D45825

Files:
  test/wasm/reloc-addend.ll
  wasm/InputChunks.cpp


Index: wasm/InputChunks.cpp
===================================================================
--- wasm/InputChunks.cpp
+++ wasm/InputChunks.cpp
@@ -124,7 +124,7 @@
     case R_WEBASSEMBLY_MEMORY_ADDR_LEB:
     case R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
     case R_WEBASSEMBLY_MEMORY_ADDR_I32:
-      writeUleb128(OS, Rel.Addend, "reloc addend");
+      writeSleb128(OS, Rel.Addend, "reloc addend");
       break;
     }
   }
Index: test/wasm/reloc-addend.ll
===================================================================
--- /dev/null
+++ test/wasm/reloc-addend.ll
@@ -0,0 +1,19 @@
+; RUN: llc -filetype=obj %s -o %t.o
+; RUN: wasm-ld --check-signatures -r -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target triple = "wasm32-unknown-unknown-wasm"
+
+ at foo = hidden global [76 x i32] zeroinitializer, align 16
+
+; bar points to the 16th element, which happens to be 64 bytes
+; This generates an addend of 64 which, is the value at which
+; signed and unsigned LEB encodes will differ.
+ at bar = hidden local_unnamed_addr global i32* getelementptr inbounds ([76 x i32], [76 x i32]* @foo, i32 0, i32 16), align 4
+
+; CHECK:        - Type:            DATA
+; CHECK-NEXT:     Relocations:     
+; CHECK-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_I32
+; CHECK-NEXT:         Index:           0
+; CHECK-NEXT:         Offset:          0x0000013D
+; CHECK-NEXT:         Addend:          64


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45825.143117.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180419/fbfbb3e0/attachment.bin>


More information about the llvm-commits mailing list