From 9d24fb7ff318d7a88f0fa3e63eb0df4acafd9805 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 16 Jun 2017 23:59:10 +0000 Subject: [WebAssembly] Use __stack_pointer global when writing wasm binary This ensures that symbolic relocations are generated for stack pointer manipulations. These relocations are of type R_WEBASSEMBLY_GLOBAL_INDEX_LEB. This change also adds support for reading relocations of this type in WasmObjectFile.cpp. Since its a globally imported symbol this does mean that the get_global/set_global instruction won't be valid until the objects are linked that global used in no longer an imported global. Differential Revision: https://reviews.llvm.org/D34172 llvm-svn: 305616 --- llvm/test/MC/WebAssembly/func-address.ll | 5 ++--- llvm/test/MC/WebAssembly/stack-ptr.ll | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 llvm/test/MC/WebAssembly/stack-ptr.ll (limited to 'llvm/test/MC/WebAssembly') diff --git a/llvm/test/MC/WebAssembly/func-address.ll b/llvm/test/MC/WebAssembly/func-address.ll index c0a9d9a801f..15c09e0ebd8 100644 --- a/llvm/test/MC/WebAssembly/func-address.ll +++ b/llvm/test/MC/WebAssembly/func-address.ll @@ -25,11 +25,10 @@ entry: ; CHECK: Section { ; CHECK: Type: ELEM (0x9) ; CHECK: Size: 7 -; CHECK: Offset: 165 ; CHECK: } ; CHECK: Relocations [ -; CHECK: Section (9) CODE { +; CHECK: Section (8) CODE { ; CHECK: Relocation { ; CHECK: Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB (0) ; CHECK: Offset: 0x4 @@ -42,7 +41,7 @@ entry: ; CHECK: } ; CHECK: Relocation { ; CHECK: Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1) -; CHECK: Offset: 0x1A +; CHECK: Offset: 0x1E ; CHECK: Index: 0x0 ; CHECK: } ; CHECK: } diff --git a/llvm/test/MC/WebAssembly/stack-ptr.ll b/llvm/test/MC/WebAssembly/stack-ptr.ll new file mode 100644 index 00000000000..98d1311e154 --- /dev/null +++ b/llvm/test/MC/WebAssembly/stack-ptr.ll @@ -0,0 +1,21 @@ +; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s + +; Function that uses explict stack, and should generate a reference to +; __stack_pointer, along with the corresponding reloction entry. +define hidden void @foo() #0 { +entry: + alloca i32, align 4 + ret void +} + +; CHECK: - Type: IMPORT +; CHECK: Imports: +; CHECK: - Module: env +; CHECK: Field: __stack_pointer +; CHECK: Kind: GLOBAL +; CHECK: GlobalType: I32 +; CHECK: GlobalMutable: false +; CHECK: - Type: CODE +; CHECK: Relocations: +; CHECK: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB +; CHECK: Index: 0 -- cgit v1.2.3