Index: lld/trunk/test/wasm/emit-relocs-fpic.s =================================================================== --- lld/trunk/test/wasm/emit-relocs-fpic.s +++ lld/trunk/test/wasm/emit-relocs-fpic.s @@ -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 Index: lld/trunk/test/wasm/lit.local.cfg =================================================================== --- lld/trunk/test/wasm/lit.local.cfg +++ lld/trunk/test/wasm/lit.local.cfg @@ -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'] Index: lld/trunk/wasm/InputChunks.cpp =================================================================== --- lld/trunk/wasm/InputChunks.cpp +++ lld/trunk/wasm/InputChunks.cpp @@ -154,15 +154,8 @@ 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; - } } } Index: llvm/trunk/include/llvm/BinaryFormat/Wasm.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Wasm.h +++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h @@ -364,6 +364,7 @@ std::string toString(WasmSymbolType type); std::string relocTypetoString(uint32_t type); +bool relocTypeHasAddend(uint32_t type); } // end namespace wasm } // end namespace llvm Index: llvm/trunk/lib/BinaryFormat/Wasm.cpp =================================================================== --- llvm/trunk/lib/BinaryFormat/Wasm.cpp +++ llvm/trunk/lib/BinaryFormat/Wasm.cpp @@ -35,3 +35,17 @@ 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; + } +} Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WasmObjectWriter.cpp +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp @@ -147,19 +147,7 @@ : 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