From 13a2e899265be4ddf72e77ea697f451c580a09e2 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 1 Sep 2017 17:32:01 +0000 Subject: [PATCH] [WebAssembly] Update relocation names to match spec Summary: See https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md Differential Revision: https://reviews.llvm.org/D37385 llvm-svn: 312342 --- .../BinaryFormat/WasmRelocs/WebAssembly.def | 6 ++--- llvm/lib/MC/WasmObjectWriter.cpp | 22 +++++++++---------- llvm/lib/Object/WasmObjectFile.cpp | 6 ++--- .../WebAssemblyWasmObjectWriter.cpp | 6 ++--- llvm/test/MC/WebAssembly/external-data.ll | 2 +- llvm/test/MC/WebAssembly/reloc-code.ll | 4 ++-- llvm/test/MC/WebAssembly/reloc-data.ll | 4 ++-- llvm/test/MC/WebAssembly/unnamed-data.ll | 4 ++-- llvm/test/Object/objdump-relocations.test | 2 +- llvm/test/ObjectYAML/wasm/data_section.yaml | 8 +++---- .../llvm-objdump/WebAssembly/relocations.test | 2 +- llvm/test/tools/llvm-readobj/relocations.test | 2 +- llvm/tools/llvm-readobj/WasmDumper.cpp | 6 ++--- llvm/tools/yaml2obj/yaml2wasm.cpp | 6 ++--- 14 files changed, 40 insertions(+), 40 deletions(-) diff --git a/llvm/include/llvm/BinaryFormat/WasmRelocs/WebAssembly.def b/llvm/include/llvm/BinaryFormat/WasmRelocs/WebAssembly.def index da64e025478d..d6f0e42b33bf 100644 --- a/llvm/include/llvm/BinaryFormat/WasmRelocs/WebAssembly.def +++ b/llvm/include/llvm/BinaryFormat/WasmRelocs/WebAssembly.def @@ -6,8 +6,8 @@ WASM_RELOC(R_WEBASSEMBLY_FUNCTION_INDEX_LEB, 0) WASM_RELOC(R_WEBASSEMBLY_TABLE_INDEX_SLEB, 1) WASM_RELOC(R_WEBASSEMBLY_TABLE_INDEX_I32, 2) -WASM_RELOC(R_WEBASSEMBLY_GLOBAL_ADDR_LEB, 3) -WASM_RELOC(R_WEBASSEMBLY_GLOBAL_ADDR_SLEB, 4) -WASM_RELOC(R_WEBASSEMBLY_GLOBAL_ADDR_I32, 5) +WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_LEB, 3) +WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_SLEB, 4) +WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_I32, 5) WASM_RELOC(R_WEBASSEMBLY_TYPE_INDEX_LEB, 6) WASM_RELOC(R_WEBASSEMBLY_GLOBAL_INDEX_LEB, 7) diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 0d31f65c49d9..35d9a58f6d36 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -142,9 +142,9 @@ struct WasmRelocationEntry { bool hasAddend() const { switch (Type) { - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: return true; default: return false; @@ -495,9 +495,9 @@ uint32_t WasmObjectWriter::getRelocationIndexValue( return IndirectSymbolIndices[RelEntry.Symbol]; case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: if (!SymbolIndices.count(RelEntry.Symbol)) report_fatal_error("symbol not found function/global index space: " + RelEntry.Symbol->getName()); @@ -537,17 +537,17 @@ void WasmObjectWriter::applyRelocations( WriteI32(Stream, Index, Offset); break; } - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: { + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: { uint32_t Value = ProvisionalValue(RelEntry); WritePatchableSLEB(Stream, Value, Offset); break; } - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: { + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: { uint32_t Value = ProvisionalValue(RelEntry); WritePatchableLEB(Stream, Value, Offset); break; } - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: { + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: { uint32_t Value = ProvisionalValue(RelEntry); WriteI32(Stream, Value, Offset); break; @@ -967,7 +967,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, for (const WasmRelocationEntry &RelEntry : CodeRelocations) { switch (RelEntry.Type) { case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: IsAddressTaken.insert(RelEntry.Symbol); break; default: @@ -977,7 +977,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, for (const WasmRelocationEntry &RelEntry : DataRelocations) { switch (RelEntry.Type) { case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: IsAddressTaken.insert(RelEntry.Symbol); break; default: diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index e1bab727f176..93097518d607 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -395,9 +395,9 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, const uint8_t *Ptr, case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: break; - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: Reloc.Addend = readVarint32(Ptr); break; default: diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp index 9cf77829f3bc..995984b03616 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -73,7 +73,7 @@ WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, case WebAssembly::fixup_code_sleb128_i32: if (IsFunction) return wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB; - return wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB; + return wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB; case WebAssembly::fixup_code_sleb128_i64: llvm_unreachable("fixup_sleb128_i64 not implemented yet"); case WebAssembly::fixup_code_uleb128_i32: @@ -81,11 +81,11 @@ WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, return wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB; if (IsFunction) return wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB; - return wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB; + return wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB; case FK_Data_4: if (IsFunction) return wasm::R_WEBASSEMBLY_TABLE_INDEX_I32; - return wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32; + return wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32; case FK_Data_8: llvm_unreachable("FK_Data_8 not implemented yet"); default: diff --git a/llvm/test/MC/WebAssembly/external-data.ll b/llvm/test/MC/WebAssembly/external-data.ll index b8c97453413e..6d0d3d12aba1 100644 --- a/llvm/test/MC/WebAssembly/external-data.ll +++ b/llvm/test/MC/WebAssembly/external-data.ll @@ -9,7 +9,7 @@ ; CHECK: - Type: DATA ; CHECK: Relocations: -; CHECK: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 +; CHECK: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 ; CHECK: Index: 0 ; CHECK: Offset: 0x0000000E ; CHECK: Segments: diff --git a/llvm/test/MC/WebAssembly/reloc-code.ll b/llvm/test/MC/WebAssembly/reloc-code.ll index 5fcd9b403811..f007b63ca83e 100644 --- a/llvm/test/MC/WebAssembly/reloc-code.ll +++ b/llvm/test/MC/WebAssembly/reloc-code.ll @@ -24,13 +24,13 @@ entry: ; CHECK: Relocations [ ; CHECK-NEXT: Section (8) CODE { ; CHECK-NEXT: Relocation { -; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3) +; CHECK-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB (3) ; CHECK-NEXT: Offset: 0x9 ; CHECK-NEXT: Index: 0x0 ; CHECK-NEXT: Addend: 0 ; CHECK-NEXT: } ; CHECK-NEXT: Relocation { -; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3) +; CHECK-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB (3) ; CHECK-NEXT: Offset: 0x14 ; CHECK-NEXT: Index: 0x1 ; CHECK-NEXT: Addend: 0 diff --git a/llvm/test/MC/WebAssembly/reloc-data.ll b/llvm/test/MC/WebAssembly/reloc-data.ll index 5bd18fa82e8e..aa97b65a6841 100644 --- a/llvm/test/MC/WebAssembly/reloc-data.ll +++ b/llvm/test/MC/WebAssembly/reloc-data.ll @@ -11,13 +11,13 @@ ; CHECK: Relocations [ ; CHECK: Section (6) DATA { ; CHECK: Relocation { -; CHECK: Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 (5) +; CHECK: Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 (5) ; CHECK: Offset: 0xE ; CHECK: Index: 0x0 ; CHECK: Addend: 8 ; CHECK: } ; CHECK: Relocation { -; CHECK: Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 (5) +; CHECK: Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 (5) ; CHECK: Offset: 0x16 ; CHECK: Index: 0x1 ; CHECK: Addend: -16 diff --git a/llvm/test/MC/WebAssembly/unnamed-data.ll b/llvm/test/MC/WebAssembly/unnamed-data.ll index fa0ff966a79f..21ac823e9579 100644 --- a/llvm/test/MC/WebAssembly/unnamed-data.ll +++ b/llvm/test/MC/WebAssembly/unnamed-data.ll @@ -39,10 +39,10 @@ ; CHECK-NEXT: Index: 3 ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Relocations: -; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 +; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 ; CHECK-NEXT: Index: 0 ; CHECK-NEXT: Offset: 0x00000016 -; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 +; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 ; CHECK-NEXT: Index: 1 ; CHECK-NEXT: Offset: 0x0000001E ; CHECK-NEXT: Segments: diff --git a/llvm/test/Object/objdump-relocations.test b/llvm/test/Object/objdump-relocations.test index 29f001962875..b461f561db42 100644 --- a/llvm/test/Object/objdump-relocations.test +++ b/llvm/test/Object/objdump-relocations.test @@ -60,7 +60,7 @@ ELF-MIPSEL: R_MIPS_CALL16 puts ELF-MIPSEL: R_MIPS_CALL16 SomeOtherFunction WASM: CODE -WASM-NEXT: R_WEBASSEMBLY_GLOBAL_ADDR_SLEB 0+0 +WASM-NEXT: R_WEBASSEMBLY_MEMORY_ADDR_SLEB 0+0 WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 0+0 WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 1+0 diff --git a/llvm/test/ObjectYAML/wasm/data_section.yaml b/llvm/test/ObjectYAML/wasm/data_section.yaml index 521aa5402784..d2595ddedb2a 100644 --- a/llvm/test/ObjectYAML/wasm/data_section.yaml +++ b/llvm/test/ObjectYAML/wasm/data_section.yaml @@ -14,11 +14,11 @@ Sections: Value: 4 Content: '10001000' Relocations: - - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 + - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 Index: 0 Offset: 0x00000006 Addend: 8 - - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 + - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 Index: 0 Offset: 0x00000006 Addend: -6 @@ -29,11 +29,11 @@ Sections: # CHECK: Sections: # CHECK: - Type: DATA # CHECK-NEXT: Relocations: -# CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 +# CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 # CHECK-NEXT: Index: 0 # CHECK-NEXT: Offset: 0x00000006 # CHECK-NEXT: Addend: 8 -# CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 +# CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 # CHECK-NEXT: Index: 0 # CHECK-NEXT: Offset: 0x00000006 # CHECK-NEXT: Addend: -6 diff --git a/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test b/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test index 07a167c550f9..78a987bb3185 100644 --- a/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test +++ b/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test @@ -5,4 +5,4 @@ @bar = hidden global i32* @foo2, align 4 ; CHECK: RELOCATION RECORDS FOR [DATA]: -; CHECK-NEXT: 0000000e R_WEBASSEMBLY_GLOBAL_ADDR_I32 1+0 +; CHECK-NEXT: 0000000e R_WEBASSEMBLY_MEMORY_ADDR_I32 1+0 diff --git a/llvm/test/tools/llvm-readobj/relocations.test b/llvm/test/tools/llvm-readobj/relocations.test index 85ccd3cefa1b..400aeeaa7043 100644 --- a/llvm/test/tools/llvm-readobj/relocations.test +++ b/llvm/test/tools/llvm-readobj/relocations.test @@ -289,7 +289,7 @@ MACHO-ARM-NEXT: ] WASM: Relocations [ WASM-NEXT: Section (8) CODE { WASM-NEXT: Relocation { -WASM-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_SLEB (4) +WASM-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB (4) WASM-NEXT: Offset: 0x4 WASM-NEXT: Index: 0x0 WASM-NEXT: Addend: 0 diff --git a/llvm/tools/llvm-readobj/WasmDumper.cpp b/llvm/tools/llvm-readobj/WasmDumper.cpp index 266226d59ee8..88fcbf61a6a7 100644 --- a/llvm/tools/llvm-readobj/WasmDumper.cpp +++ b/llvm/tools/llvm-readobj/WasmDumper.cpp @@ -83,9 +83,9 @@ void WasmDumper::printRelocation(const SectionRef &Section, bool HasAddend = false; switch (RelocType) { - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: HasAddend = true; break; default: diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp index 059ec5f9edcd..0bd882911f9c 100644 --- a/llvm/tools/yaml2obj/yaml2wasm.cpp +++ b/llvm/tools/yaml2obj/yaml2wasm.cpp @@ -370,9 +370,9 @@ int WasmWriter::writeRelocSection(raw_ostream &OS, encodeULEB128(Reloc.Offset, OS); encodeULEB128(Reloc.Index, OS); switch (Reloc.Type) { - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: - case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: encodeULEB128(Reloc.Addend, OS); } }