[llvm] r322978 - [WebAssembly] MC: Start table at offset 1 rather than 0
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 10:57:01 PST 2018
Author: sbc
Date: Fri Jan 19 10:57:01 2018
New Revision: 322978
URL: http://llvm.org/viewvc/llvm-project?rev=322978&view=rev
Log:
[WebAssembly] MC: Start table at offset 1 rather than 0
Summary:
For consistency with the output of lld.
This is useful in runnable binaries as can them be sure the
null function pointer will never be a valid argument
call_indirect.
Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D42284
Modified:
llvm/trunk/lib/MC/WasmObjectWriter.cpp
llvm/trunk/test/MC/WebAssembly/external-func-address.ll
llvm/trunk/test/MC/WebAssembly/func-address.ll
llvm/trunk/test/MC/WebAssembly/global-ctor-dtor.ll
llvm/trunk/test/MC/WebAssembly/weak-alias.ll
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=322978&r1=322977&r2=322978&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Fri Jan 19 10:57:01 2018
@@ -38,6 +38,10 @@ using namespace llvm;
namespace {
+// Went we ceate the indirect function table we start at 1, so that there is
+// and emtpy slot at 0 and therefore calling a null function pointer will trap.
+static const uint32_t kInitialTableOffset = 1;
+
// For patching purposes, we need to remember where each section starts, both
// for patching up the section size field, and for patching up references to
// locations within the section.
@@ -789,7 +793,7 @@ void WasmObjectWriter::writeElemSection(
// init expr for starting offset
write8(wasm::WASM_OPCODE_I32_CONST);
- encodeSLEB128(0, getStream());
+ encodeSLEB128(kInitialTableOffset, getStream());
write8(wasm::WASM_OPCODE_END);
encodeULEB128(TableElems.size(), getStream());
@@ -1326,7 +1330,7 @@ void WasmObjectWriter::writeObject(MCAss
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: {
uint32_t Index = SymbolIndices.find(&WS)->second;
- IndirectSymbolIndices[&WS] = TableElems.size();
+ IndirectSymbolIndices[&WS] = TableElems.size() + kInitialTableOffset;
DEBUG(dbgs() << " -> adding to table: " << TableElems.size() << "\n");
TableElems.push_back(Index);
registerFunctionType(WS);
Modified: llvm/trunk/test/MC/WebAssembly/external-func-address.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/external-func-address.ll?rev=322978&r1=322977&r2=322978&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/external-func-address.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/external-func-address.ll Fri Jan 19 10:57:01 2018
@@ -29,10 +29,10 @@ declare void @f1(i32) #1
; CHECK-NEXT: Segments:
; CHECK-NEXT: - Offset:
; CHECK-NEXT: Opcode: I32_CONST
-; CHECK-NEXT: Value: 0
+; CHECK-NEXT: Value: 1
; CHECK-NEXT: Functions: [ 0 ]
; CHECK: - Type: DATA
; CHECK-NEXT: Relocations:
; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32
-; CHECK-NEXT: Index: 0
+; CHECK-NEXT: Index: 1
; CHECK-NEXT: Offset: 0x00000006
Modified: llvm/trunk/test/MC/WebAssembly/func-address.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/func-address.ll?rev=322978&r1=322977&r2=322978&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/func-address.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/func-address.ll Fri Jan 19 10:57:01 2018
@@ -42,6 +42,6 @@ entry:
; CHECK: Relocation {
; CHECK: Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1)
; CHECK: Offset: 0x1E
-; CHECK: Index: 0x0
+; CHECK: Index: 0x1
; CHECK: }
; CHECK: }
Modified: llvm/trunk/test/MC/WebAssembly/global-ctor-dtor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/global-ctor-dtor.ll?rev=322978&r1=322977&r2=322978&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/global-ctor-dtor.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/global-ctor-dtor.ll Fri Jan 19 10:57:01 2018
@@ -87,7 +87,7 @@ declare void @func3()
; CHECK-NEXT: Segments:
; CHECK-NEXT: - Offset:
; CHECK-NEXT: Opcode: I32_CONST
-; CHECK-NEXT: Value: 0
+; CHECK-NEXT: Value: 1
; CHECK-NEXT: Functions: [ 5, 7 ]
; CHECK-NEXT: - Type: CODE
; CHECK-NEXT: Relocations:
@@ -95,7 +95,7 @@ declare void @func3()
; CHECK-NEXT: Index: 0
; CHECK-NEXT: Offset: 0x00000004
; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; CHECK-NEXT: Index: 0
+; CHECK-NEXT: Index: 1
; CHECK-NEXT: Offset: 0x0000000F
; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; CHECK-NEXT: Index: 0
@@ -107,7 +107,7 @@ declare void @func3()
; CHECK-NEXT: Index: 2
; CHECK-NEXT: Offset: 0x0000002C
; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; CHECK-NEXT: Index: 1
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: Offset: 0x00000037
; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB
; CHECK-NEXT: Index: 0
@@ -121,13 +121,13 @@ declare void @func3()
; CHECK-NEXT: Body: 1080808080000B
; CHECK-NEXT: - Index: 6
; CHECK-NEXT: Locals:
-; CHECK-NEXT: Body: 024041808080800041004180808080001081808080000D000F0B00000B
+; CHECK-NEXT: Body: 024041818080800041004180808080001081808080000D000F0B00000B
; CHECK-NEXT: - Index: 7
; CHECK-NEXT: Locals:
; CHECK-NEXT: Body: 1082808080000B
; CHECK-NEXT: - Index: 8
; CHECK-NEXT: Locals:
-; CHECK-NEXT: Body: 024041818080800041004180808080001081808080000D000F0B00000B
+; CHECK-NEXT: Body: 024041828080800041004180808080001081808080000D000F0B00000B
; CHECK-NEXT: - Type: DATA
; CHECK-NEXT: Segments:
; CHECK-NEXT: - SectionOffset: 6
Modified: llvm/trunk/test/MC/WebAssembly/weak-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/weak-alias.ll?rev=322978&r1=322977&r2=322978&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/weak-alias.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/weak-alias.ll Fri Jan 19 10:57:01 2018
@@ -130,7 +130,7 @@ entry:
; CHECK-NEXT: Segments:
; CHECK-NEXT: - Offset:
; CHECK-NEXT: Opcode: I32_CONST
-; CHECK-NEXT: Value: 0
+; CHECK-NEXT: Value: 1
; CHECK-NEXT: Functions: [ 1, 0 ]
; CHECK-NEXT: - Type: CODE
; CHECK-NEXT: Relocations:
@@ -171,10 +171,10 @@ entry:
; CHECK-NEXT: - Type: DATA
; CHECK-NEXT: Relocations:
; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32
-; CHECK-NEXT: Index: 0
+; CHECK-NEXT: Index: 1
; CHECK-NEXT: Offset: 0x0000000F
; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32
-; CHECK-NEXT: Index: 1
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: Offset: 0x00000018
; CHECK-NEXT: Segments:
; CHECK-NEXT: - SectionOffset: 6
@@ -188,7 +188,7 @@ entry:
; CHECK-NEXT: Offset:
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 8
-; CHECK-NEXT: Content: '00000000'
+; CHECK-NEXT: Content: '01000000'
; CHECK: - Type: CUSTOM
; CHECK-NEXT: Name: name
More information about the llvm-commits
mailing list