[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

llvm-svn: 330374
This commit is contained in:
Sam Clegg
2018-04-19 22:48:03 +00:00
parent 1eca23bdd8
commit 0dbe57e752
2 changed files with 20 additions and 1 deletions

View File

@@ -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"
@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.
@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

View File

@@ -124,7 +124,7 @@ void InputChunk::writeRelocations(raw_ostream &OS) const {
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;
}
}