llvm.org GIT mirror llvm / 8b020d7
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312342 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Clegg 3 years ago
14 changed file(s) with 40 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
55 WASM_RELOC(R_WEBASSEMBLY_FUNCTION_INDEX_LEB, 0)
66 WASM_RELOC(R_WEBASSEMBLY_TABLE_INDEX_SLEB, 1)
77 WASM_RELOC(R_WEBASSEMBLY_TABLE_INDEX_I32, 2)
8 WASM_RELOC(R_WEBASSEMBLY_GLOBAL_ADDR_LEB, 3)
9 WASM_RELOC(R_WEBASSEMBLY_GLOBAL_ADDR_SLEB, 4)
10 WASM_RELOC(R_WEBASSEMBLY_GLOBAL_ADDR_I32, 5)
8 WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_LEB, 3)
9 WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_SLEB, 4)
10 WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_I32, 5)
1111 WASM_RELOC(R_WEBASSEMBLY_TYPE_INDEX_LEB, 6)
1212 WASM_RELOC(R_WEBASSEMBLY_GLOBAL_INDEX_LEB, 7)
141141
142142 bool hasAddend() const {
143143 switch (Type) {
144 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
145 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
146 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
144 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
145 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
146 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
147147 return true;
148148 default:
149149 return false;
494494 return IndirectSymbolIndices[RelEntry.Symbol];
495495 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
496496 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
497 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
498 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
499 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
497 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
498 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
499 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
500500 if (!SymbolIndices.count(RelEntry.Symbol))
501501 report_fatal_error("symbol not found function/global index space: " +
502502 RelEntry.Symbol->getName());
536536 WriteI32(Stream, Index, Offset);
537537 break;
538538 }
539 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: {
539 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: {
540540 uint32_t Value = ProvisionalValue(RelEntry);
541541 WritePatchableSLEB(Stream, Value, Offset);
542542 break;
543543 }
544 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: {
544 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: {
545545 uint32_t Value = ProvisionalValue(RelEntry);
546546 WritePatchableLEB(Stream, Value, Offset);
547547 break;
548548 }
549 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: {
549 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: {
550550 uint32_t Value = ProvisionalValue(RelEntry);
551551 WriteI32(Stream, Value, Offset);
552552 break;
966966 for (const WasmRelocationEntry &RelEntry : CodeRelocations) {
967967 switch (RelEntry.Type) {
968968 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
969 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
969 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
970970 IsAddressTaken.insert(RelEntry.Symbol);
971971 break;
972972 default:
976976 for (const WasmRelocationEntry &RelEntry : DataRelocations) {
977977 switch (RelEntry.Type) {
978978 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
979 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
979 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
980980 IsAddressTaken.insert(RelEntry.Symbol);
981981 break;
982982 default:
394394 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
395395 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
396396 break;
397 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
398 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
399 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
397 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
398 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
399 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
400400 Reloc.Addend = readVarint32(Ptr);
401401 break;
402402 default:
7272 case WebAssembly::fixup_code_sleb128_i32:
7373 if (IsFunction)
7474 return wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB;
75 return wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB;
75 return wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB;
7676 case WebAssembly::fixup_code_sleb128_i64:
7777 llvm_unreachable("fixup_sleb128_i64 not implemented yet");
7878 case WebAssembly::fixup_code_uleb128_i32:
8080 return wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB;
8181 if (IsFunction)
8282 return wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB;
83 return wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB;
83 return wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB;
8484 case FK_Data_4:
8585 if (IsFunction)
8686 return wasm::R_WEBASSEMBLY_TABLE_INDEX_I32;
87 return wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32;
87 return wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32;
8888 case FK_Data_8:
8989 llvm_unreachable("FK_Data_8 not implemented yet");
9090 default:
88
99 ; CHECK: - Type: DATA
1010 ; CHECK: Relocations:
11 ; CHECK: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
11 ; CHECK: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
1212 ; CHECK: Index: 0
1313 ; CHECK: Offset: 0x0000000E
1414 ; CHECK: Segments:
2323 ; CHECK: Relocations [
2424 ; CHECK-NEXT: Section (8) CODE {
2525 ; CHECK-NEXT: Relocation {
26 ; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3)
26 ; CHECK-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB (3)
2727 ; CHECK-NEXT: Offset: 0x9
2828 ; CHECK-NEXT: Index: 0x0
2929 ; CHECK-NEXT: Addend: 0
3030 ; CHECK-NEXT: }
3131 ; CHECK-NEXT: Relocation {
32 ; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3)
32 ; CHECK-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB (3)
3333 ; CHECK-NEXT: Offset: 0x14
3434 ; CHECK-NEXT: Index: 0x1
3535 ; CHECK-NEXT: Addend: 0
1010 ; CHECK: Relocations [
1111 ; CHECK: Section (6) DATA {
1212 ; CHECK: Relocation {
13 ; CHECK: Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 (5)
13 ; CHECK: Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 (5)
1414 ; CHECK: Offset: 0xE
1515 ; CHECK: Index: 0x0
1616 ; CHECK: Addend: 8
1717 ; CHECK: }
1818 ; CHECK: Relocation {
19 ; CHECK: Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32 (5)
19 ; CHECK: Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 (5)
2020 ; CHECK: Offset: 0x16
2121 ; CHECK: Index: 0x1
2222 ; CHECK: Addend: -16
3838 ; CHECK-NEXT: Index: 3
3939 ; CHECK-NEXT: - Type: DATA
4040 ; CHECK-NEXT: Relocations:
41 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
41 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
4242 ; CHECK-NEXT: Index: 0
4343 ; CHECK-NEXT: Offset: 0x00000016
44 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
44 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
4545 ; CHECK-NEXT: Index: 1
4646 ; CHECK-NEXT: Offset: 0x0000001E
4747 ; CHECK-NEXT: Segments:
5959 ELF-MIPSEL: R_MIPS_CALL16 SomeOtherFunction
6060
6161 WASM: CODE
62 WASM-NEXT: R_WEBASSEMBLY_GLOBAL_ADDR_SLEB 0+0
62 WASM-NEXT: R_WEBASSEMBLY_MEMORY_ADDR_SLEB 0+0
6363 WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 0+0
6464 WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 1+0
6565
1313 Value: 4
1414 Content: '10001000'
1515 Relocations:
16 - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
16 - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
1717 Index: 0
1818 Offset: 0x00000006
1919 Addend: 8
20 - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
20 - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
2121 Index: 0
2222 Offset: 0x00000006
2323 Addend: -6
2828 # CHECK: Sections:
2929 # CHECK: - Type: DATA
3030 # CHECK-NEXT: Relocations:
31 # CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
31 # CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
3232 # CHECK-NEXT: Index: 0
3333 # CHECK-NEXT: Offset: 0x00000006
3434 # CHECK-NEXT: Addend: 8
35 # CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
35 # CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32
3636 # CHECK-NEXT: Index: 0
3737 # CHECK-NEXT: Offset: 0x00000006
3838 # CHECK-NEXT: Addend: -6
44 @bar = hidden global i32* @foo2, align 4
55
66 ; CHECK: RELOCATION RECORDS FOR [DATA]:
7 ; CHECK-NEXT: 0000000e R_WEBASSEMBLY_GLOBAL_ADDR_I32 1+0
7 ; CHECK-NEXT: 0000000e R_WEBASSEMBLY_MEMORY_ADDR_I32 1+0
288288 WASM: Relocations [
289289 WASM-NEXT: Section (8) CODE {
290290 WASM-NEXT: Relocation {
291 WASM-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_SLEB (4)
291 WASM-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB (4)
292292 WASM-NEXT: Offset: 0x4
293293 WASM-NEXT: Index: 0x0
294294 WASM-NEXT: Addend: 0
8282
8383 bool HasAddend = false;
8484 switch (RelocType) {
85 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
86 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
87 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
85 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
86 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
87 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
8888 HasAddend = true;
8989 break;
9090 default:
369369 encodeULEB128(Reloc.Offset, OS);
370370 encodeULEB128(Reloc.Index, OS);
371371 switch (Reloc.Type) {
372 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
373 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
374 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
372 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
373 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
374 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
375375 encodeULEB128(Reloc.Addend, OS);
376376 }
377377 }