[llvm] r301369 - [WebAssembly] Allow for signed relocation addends
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 17:02:32 PDT 2017
Author: sbc
Date: Tue Apr 25 19:02:31 2017
New Revision: 301369
URL: http://llvm.org/viewvc/llvm-project?rev=301369&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h
llvm/trunk/lib/Object/WasmObjectFile.cpp
llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
llvm/trunk/test/ObjectYAML/wasm/code_section.yaml
llvm/trunk/test/ObjectYAML/wasm/data_section.yaml
Modified: llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h?rev=301369&r1=301368&r2=301369&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h Tue Apr 25 19:02:31 2017
@@ -88,7 +88,7 @@ struct Relocation {
RelocType Type;
uint32_t Index;
yaml::Hex32 Offset;
- yaml::Hex32 Addend;
+ int32_t Addend;
};
struct DataSegment {
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=301369&r1=301368&r2=301369&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Tue Apr 25 19:02:31 2017
@@ -316,14 +316,15 @@ Error WasmObjectFile::parseRelocSection(
case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
+ case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
break;
case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
- Reloc.Addend = readVaruint32(Ptr);
+ Reloc.Addend = readVarint32(Ptr);
break;
default:
- return make_error<GenericBinaryError>("Bad relocation type",
+ return make_error<GenericBinaryError>("Bad relocation type: " + Twine(Reloc.Type),
object_error::parse_failed);
}
Section->Relocations.push_back(Reloc);
Modified: llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/WasmYAML.cpp?rev=301369&r1=301368&r2=301369&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/WasmYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/WasmYAML.cpp Tue Apr 25 19:02:31 2017
@@ -223,7 +223,7 @@ void MappingTraits<WasmYAML::Relocation>
IO.mapRequired("Type", Relocation.Type);
IO.mapRequired("Index", Relocation.Index);
IO.mapRequired("Offset", Relocation.Offset);
- IO.mapRequired("Addend", Relocation.Addend);
+ IO.mapOptional("Addend", Relocation.Addend, 0);
}
void MappingTraits<WasmYAML::LocalDecl>::mapping(
Modified: llvm/trunk/test/ObjectYAML/wasm/code_section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/wasm/code_section.yaml?rev=301369&r1=301368&r2=301369&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/wasm/code_section.yaml (original)
+++ llvm/trunk/test/ObjectYAML/wasm/code_section.yaml Tue Apr 25 19:02:31 2017
@@ -21,11 +21,9 @@ Sections:
- Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
Index: 0
Offset: 0x00000006
- Addend: 0x00000000
- Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
Index: 1
Offset: 0x00000025
- Addend: 0x00000000
Functions:
- Locals:
- Type: I32
@@ -56,11 +54,9 @@ Sections:
# CHECK: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
# CHECK: Index: 0
# CHECK: Offset: 0x00000006
-# CHECK: Addend: 0x00000000
# CHECK: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
# CHECK: Index: 1
# CHECK: Offset: 0x00000025
-# CHECK: Addend: 0x00000000
# CHECK: Functions:
# CHECK: - Locals:
# CHECK: - Type: I32
Modified: llvm/trunk/test/ObjectYAML/wasm/data_section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/wasm/data_section.yaml?rev=301369&r1=301368&r2=301369&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/wasm/data_section.yaml (original)
+++ llvm/trunk/test/ObjectYAML/wasm/data_section.yaml Tue Apr 25 19:02:31 2017
@@ -13,16 +13,34 @@ Sections:
Opcode: I32_CONST
Value: 4
Content: '10001000'
+ Relocations:
+ - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
+ Index: 0
+ Offset: 0x00000006
+ Addend: 8
+ - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
+ Index: 0
+ Offset: 0x00000006
+ Addend: -6
...
# CHECK: --- !WASM
# CHECK: FileHeader:
# CHECK: Version: 0x00000001
# CHECK: Sections:
# CHECK: - Type: DATA
-# CHECK: Segments:
-# CHECK: - Index: 0
-# CHECK: Offset:
-# CHECK: Opcode: I32_CONST
-# CHECK: Value: 4
-# CHECK: Content: '10001000'
-# CHECK: ...
+# CHECK-NEXT: Relocations:
+# CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
+# CHECK-NEXT: Index: 0
+# CHECK-NEXT: Offset: 0x00000006
+# CHECK-NEXT: Addend: 8
+# CHECK-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_ADDR_I32
+# CHECK-NEXT: Index: 0
+# CHECK-NEXT: Offset: 0x00000006
+# CHECK-NEXT: Addend: -6
+# CHECK-NEXT: Segments:
+# CHECK-NEXT: - Index: 0
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Opcode: I32_CONST
+# CHECK-NEXT: Value: 4
+# CHECK-NEXT: Content: '10001000'
+# CHECK-NEXT: ...
More information about the llvm-commits
mailing list