diff options
| author | Sam Clegg <sbc@chromium.org> | 2018-01-19 18:57:01 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2018-01-19 18:57:01 +0000 |
| commit | 30e1bbc10672808320876797afc45a0d8f2767bf (patch) | |
| tree | b769147e0c0079b75f77593505254f7a3227aa39 | |
| parent | 976f05166f619f005440af583c261e4013695cd7 (diff) | |
| download | bcm5719-llvm-30e1bbc10672808320876797afc45a0d8f2767bf.tar.gz bcm5719-llvm-30e1bbc10672808320876797afc45a0d8f2767bf.zip | |
[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
llvm-svn: 322978
| -rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 8 | ||||
| -rw-r--r-- | llvm/test/MC/WebAssembly/external-func-address.ll | 4 | ||||
| -rw-r--r-- | llvm/test/MC/WebAssembly/func-address.ll | 2 | ||||
| -rw-r--r-- | llvm/test/MC/WebAssembly/global-ctor-dtor.ll | 10 | ||||
| -rw-r--r-- | llvm/test/MC/WebAssembly/weak-alias.ll | 8 |
5 files changed, 18 insertions, 14 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 0fe04f188d7..473f9fe7ede 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -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(ArrayRef<uint32_t> TableElems) { // 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(MCAssembler &Asm, 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); diff --git a/llvm/test/MC/WebAssembly/external-func-address.ll b/llvm/test/MC/WebAssembly/external-func-address.ll index 9386d945ccd..c8dff4036d3 100644 --- a/llvm/test/MC/WebAssembly/external-func-address.ll +++ b/llvm/test/MC/WebAssembly/external-func-address.ll @@ -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 diff --git a/llvm/test/MC/WebAssembly/func-address.ll b/llvm/test/MC/WebAssembly/func-address.ll index 16d38e1ebf2..8532aa9a9c7 100644 --- a/llvm/test/MC/WebAssembly/func-address.ll +++ b/llvm/test/MC/WebAssembly/func-address.ll @@ -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: } diff --git a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll index 759c72772bc..75f00445691 100644 --- a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll +++ b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll @@ -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 diff --git a/llvm/test/MC/WebAssembly/weak-alias.ll b/llvm/test/MC/WebAssembly/weak-alias.ll index 1698913564f..83f2eebbe37 100644 --- a/llvm/test/MC/WebAssembly/weak-alias.ll +++ b/llvm/test/MC/WebAssembly/weak-alias.ll @@ -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 |

