llvm.org GIT mirror llvm / d420e40
[WebAssembly] Allow for signed relocation addends Summary: Addends are used as offsets to addresses of globals and can be both positive and negative. This change prints libObject in line with the spec and the MC layer. Subscribers: jfb, dschuff Differential Revision: https://reviews.llvm.org/D32507 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301369 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Clegg 2 years ago
5 changed file(s) with 30 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
8787 RelocType Type;
8888 uint32_t Index;
8989 yaml::Hex32 Offset;
90 yaml::Hex32 Addend;
90 int32_t Addend;
9191 };
9292
9393 struct DataSegment {
315315 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
316316 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
317317 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
318 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
318319 break;
319320 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
320321 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
321322 case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
322 Reloc.Addend = readVaruint32(Ptr);
323 Reloc.Addend = readVarint32(Ptr);
323324 break;
324325 default:
325 return make_error("Bad relocation type",
326 return make_error("Bad relocation type: " + Twine(Reloc.Type),
326327 object_error::parse_failed);
327328 }
328329 Section->Relocations.push_back(Reloc);
222222 IO.mapRequired("Type", Relocation.Type);
223223 IO.mapRequired("Index", Relocation.Index);
224224 IO.mapRequired("Offset", Relocation.Offset);
225 IO.mapRequired("Addend", Relocation.Addend);
225 IO.mapOptional("Addend", Relocation.Addend, 0);
226226 }
227227
228228 void MappingTraits::mapping(
2020 - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
2121 Index: 0
2222 Offset: 0x00000006
23 Addend: 0x00000000
2423 - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
2524 Index: 1
2625 Offset: 0x00000025
27 Addend: 0x00000000
2826 Functions:
2927 - Locals:
3028 - Type: I32
5553 # CHECK: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
5654 # CHECK: Index: 0
5755 # CHECK: Offset: 0x00000006
58 # CHECK: Addend: 0x00000000
5956 # CHECK: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
6057 # CHECK: Index: 1
6158 # CHECK: Offset: 0x00000025
62 # CHECK: Addend: 0x00000000
6359 # CHECK: Functions:
6460 # CHECK: - Locals:
6561 # CHECK: - Type: I32
1212 Opcode: I32_CONST
1313 Value: 4
1414 Content: '10001000'
15 Relocations:
16 - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
17 Index: 0
18 Offset: 0x00000006
19 Addend: 8
20 - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
21 Index: 0
22 Offset: 0x00000006
23 Addend: -6
1524 ...
1625 # CHECK: --- !WASM
1726 # CHECK: FileHeader:
1827 # CHECK: Version: 0x00000001
1928 # CHECK: Sections:
2029 # CHECK: - Type: DATA
21 # CHECK: Segments:
22 # CHECK: - Index: 0
23 # CHECK: Offset:
24 # CHECK: Opcode: I32_CONST
25 # CHECK: Value: 4
26 # CHECK: Content: '10001000'
27 # CHECK: ...
30 # CHECK-NEXT: Relocations:
31 # CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
32 # CHECK-NEXT: Index: 0
33 # CHECK-NEXT: Offset: 0x00000006
34 # CHECK-NEXT: Addend: 8
35 # CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
36 # CHECK-NEXT: Index: 0
37 # CHECK-NEXT: Offset: 0x00000006
38 # CHECK-NEXT: Addend: -6
39 # CHECK-NEXT: Segments:
40 # CHECK-NEXT: - Index: 0
41 # CHECK-NEXT: Offset:
42 # CHECK-NEXT: Opcode: I32_CONST
43 # CHECK-NEXT: Value: 4
44 # CHECK-NEXT: Content: '10001000'
45 # CHECK-NEXT: ...