mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[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:
19
lld/test/wasm/reloc-addend.ll
Normal file
19
lld/test/wasm/reloc-addend.ll
Normal 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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user