mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[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 llvm-svn: 364367
This commit is contained in:
20
lld/test/wasm/emit-relocs-fpic.s
Normal file
20
lld/test/wasm/emit-relocs-fpic.s
Normal file
@@ -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@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
|
||||
@@ -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']
|
||||
|
||||
@@ -154,15 +154,8 @@ void InputChunk::writeRelocations(raw_ostream &OS) const {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -364,6 +364,7 @@ inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) {
|
||||
|
||||
std::string toString(WasmSymbolType type);
|
||||
std::string relocTypetoString(uint32_t type);
|
||||
bool relocTypeHasAddend(uint32_t type);
|
||||
|
||||
} // end namespace wasm
|
||||
} // end namespace llvm
|
||||
|
||||
@@ -35,3 +35,17 @@ std::string llvm::wasm::relocTypetoString(uint32_t Type) {
|
||||
llvm_unreachable("unknown reloc type");
|
||||
}
|
||||
}
|
||||
|
||||
bool llvm::wasm::relocTypeHasAddend(uint32_t Type) {
|
||||
switch (Type) {
|
||||
case R_WASM_MEMORY_ADDR_LEB:
|
||||
case R_WASM_MEMORY_ADDR_SLEB:
|
||||
case R_WASM_MEMORY_ADDR_REL_SLEB:
|
||||
case R_WASM_MEMORY_ADDR_I32:
|
||||
case R_WASM_FUNCTION_OFFSET_I32:
|
||||
case R_WASM_SECTION_OFFSET_I32:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,19 +147,7 @@ struct WasmRelocationEntry {
|
||||
: Offset(Offset), Symbol(Symbol), Addend(Addend), Type(Type),
|
||||
FixupSection(FixupSection) {}
|
||||
|
||||
bool hasAddend() const {
|
||||
switch (Type) {
|
||||
case wasm::R_WASM_MEMORY_ADDR_LEB:
|
||||
case wasm::R_WASM_MEMORY_ADDR_SLEB:
|
||||
case wasm::R_WASM_MEMORY_ADDR_REL_SLEB:
|
||||
case wasm::R_WASM_MEMORY_ADDR_I32:
|
||||
case wasm::R_WASM_FUNCTION_OFFSET_I32:
|
||||
case wasm::R_WASM_SECTION_OFFSET_I32:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool hasAddend() const { return wasm::relocTypeHasAddend(Type); }
|
||||
|
||||
void print(raw_ostream &Out) const {
|
||||
Out << wasm::relocTypetoString(Type) << " Off=" << Offset
|
||||
|
||||
Reference in New Issue
Block a user