[lld] r330374 - [WebAssembly] Fix bug where reloc addends were written as unsigned

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 19 15:48:03 PDT 2018


Author: sbc
Date: Thu Apr 19 15:48:03 2018
New Revision: 330374

URL: http://llvm.org/viewvc/llvm-project?rev=330374&view=rev
Log:
[WebAssembly] Fix bug where reloc addends were written as unsigned

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.

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

Added:
    lld/trunk/test/wasm/reloc-addend.ll
Modified:
    lld/trunk/wasm/InputChunks.cpp

Added: lld/trunk/test/wasm/reloc-addend.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/reloc-addend.ll?rev=330374&view=auto
==============================================================================
--- lld/trunk/test/wasm/reloc-addend.ll (added)
+++ lld/trunk/test/wasm/reloc-addend.ll Thu Apr 19 15:48:03 2018
@@ -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

Modified: lld/trunk/wasm/InputChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.cpp?rev=330374&r1=330373&r2=330374&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.cpp (original)
+++ lld/trunk/wasm/InputChunks.cpp Thu Apr 19 15:48:03 2018
@@ -124,7 +124,7 @@ void InputChunk::writeRelocations(raw_os
     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;
     }
   }




More information about the llvm-commits mailing list