[llvm] r301606 - [WebAssembly] Add some tests for wasm MC layer
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 17:36:37 PDT 2017
Author: sbc
Date: Thu Apr 27 19:36:36 2017
New Revision: 301606
URL: http://llvm.org/viewvc/llvm-project?rev=301606&view=rev
Log:
[WebAssembly] Add some tests for wasm MC layer
Subscribers: jfb, dschuff
Differential Revision: https://reviews.llvm.org/D32558
Added:
llvm/trunk/test/MC/WebAssembly/reloc-code.ll
llvm/trunk/test/MC/WebAssembly/sections.ll
Modified:
llvm/trunk/test/tools/llvm-readobj/relocations.test
llvm/trunk/tools/llvm-readobj/WasmDumper.cpp
Added: llvm/trunk/test/MC/WebAssembly/reloc-code.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/reloc-code.ll?rev=301606&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/reloc-code.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/reloc-code.ll Thu Apr 27 19:36:36 2017
@@ -0,0 +1,59 @@
+; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s
+
+; Pointers to functions of two different types
+ at a = global i64 ()* inttoptr (i64 5 to i64 ()*), align 8
+ at b = global i32 ()* inttoptr (i32 7 to i32 ()*), align 8
+
+; External functions
+declare i32 @c()
+declare i32 @d()
+
+define i32 @f1() {
+entry:
+ %aa = load i64 ()*, i64 ()** @a, align 8
+ %bb = load i32 ()*, i32 ()** @b, align 8
+ %tmp1 = call i64 %aa()
+ %tmp2 = call i32 %bb()
+ %tmp3 = call i32 @c()
+ %tmp4 = call i32 @d()
+ ret i32 %tmp2
+}
+
+
+; CHECK: Format: WASM
+; CHECK: Relocations [
+; CHECK-NEXT: Section (8) CODE {
+; CHECK-NEXT: Relocation {
+; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3)
+; CHECK-NEXT: Offset: 0x9
+; CHECK-NEXT: Index: 0x0
+; CHECK-NEXT: Addend: 0
+; CHECK-NEXT: }
+; CHECK-NEXT: Relocation {
+; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3)
+; CHECK-NEXT: Offset: 0x14
+; CHECK-NEXT: Index: 0x1
+; CHECK-NEXT: Addend: 0
+; CHECK-NEXT: }
+; CHECK-NEXT: Relocation {
+; CHECK-NEXT: Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB (0)
+; CHECK-NEXT: Offset: 0x2D
+; CHECK-NEXT: Index: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: Relocation {
+; CHECK-NEXT: Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB (0)
+; CHECK-NEXT: Offset: 0x34
+; CHECK-NEXT: Index: 0x1
+; CHECK-NEXT: }
+; CHECK-NEXT: Relocation {
+; CHECK-NEXT: Type: R_WEBASSEMBLY_TYPE_INDEX_LEB (6)
+; CHECK-NEXT: Offset: 0x1A
+; CHECK-NEXT: Index: 0x1
+; CHECK-NEXT: }
+; CHECK-NEXT: Relocation {
+; CHECK-NEXT: Type: R_WEBASSEMBLY_TYPE_INDEX_LEB (6)
+; CHECK-NEXT: Offset: 0x24
+; CHECK-NEXT: Index: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
+; CHECK-NEXT: ]
Added: llvm/trunk/test/MC/WebAssembly/sections.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/sections.ll?rev=301606&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/sections.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/sections.ll Thu Apr 27 19:36:36 2017
@@ -0,0 +1,57 @@
+; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | llvm-readobj -s | FileCheck %s
+
+; external function
+declare i32 @a()
+
+; global data
+ at b = global i32 3, align 4
+
+; local function
+define i32 @f1() {
+entry:
+ %tmp1 = call i32 @a()
+ ret i32 %tmp1
+}
+
+
+; CHECK: Format: WASM
+; CHECK: Arch: wasm32
+; CHECK: AddressSize: 32bit
+; CHECK: Sections [
+; CHECK: Section {
+; CHECK: Type: TYPE (0x1)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: IMPORT (0x2)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: FUNCTION (0x3)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: TABLE (0x4)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: MEMORY (0x5)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: GLOBAL (0x6)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: EXPORT (0x7)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: CODE (0xA)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: DATA (0xB)
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: CUSTOM (0x0)
+; CHECK: Name: name
+; CHECK: }
+; CHECK: Section {
+; CHECK: Type: CUSTOM (0x0)
+; CHECK: Name: reloc.CODE
+; CHECK: }
+; CHECK:]
+
Modified: llvm/trunk/test/tools/llvm-readobj/relocations.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/relocations.test?rev=301606&r1=301605&r2=301606&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/relocations.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/relocations.test Thu Apr 27 19:36:36 2017
@@ -292,19 +292,18 @@ WASM-NEXT: Relocation {
WASM-NEXT: Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1)
WASM-NEXT: Offset: 0x6
WASM-NEXT: Index: 0x0
-WASM-NEXT: Addend: 0x0
WASM-NEXT: }
WASM-NEXT: Relocation {
WASM-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3)
WASM-NEXT: Offset: 0x15
WASM-NEXT: Index: 0x0
-WASM-NEXT: Addend: 0x0
+WASM-NEXT: Addend: 0
WASM-NEXT: }
WASM-NEXT: Relocation {
WASM-NEXT: Type: R_WEBASSEMBLY_GLOBAL_ADDR_LEB (3)
WASM-NEXT: Offset: 0x24
WASM-NEXT: Index: 0x1
-WASM-NEXT: Addend: 0x0
+WASM-NEXT: Addend: 0
WASM-NEXT: }
WASM-NEXT: }
WASM-NEXT: ]
Modified: llvm/trunk/tools/llvm-readobj/WasmDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/WasmDumper.cpp?rev=301606&r1=301605&r2=301606&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/WasmDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/WasmDumper.cpp Thu Apr 27 19:36:36 2017
@@ -81,17 +81,30 @@ void WasmDumper::printRelocation(const S
Reloc.getTypeName(RelocTypeName);
const wasm::WasmRelocation &WasmReloc = Obj->getWasmRelocation(Reloc);
+ bool HasAddend = false;
+ switch (RelocType) {
+ case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
+ case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
+ case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
+ HasAddend = true;
+ break;
+ default:
+ break;
+ }
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printNumber("Type", RelocTypeName, RelocType);
W.printHex("Offset", Reloc.getOffset());
W.printHex("Index", WasmReloc.Index);
- W.printHex("Addend", WasmReloc.Addend);
+ if (HasAddend)
+ W.printNumber("Addend", WasmReloc.Addend);
} else {
raw_ostream& OS = W.startLine();
OS << W.hex(Reloc.getOffset())
- << " " << RelocTypeName << "[" << WasmReloc.Index << "]"
- << " " << W.hex(WasmReloc.Addend) << "\n";
+ << " " << RelocTypeName << "[" << WasmReloc.Index << "]";
+ if (HasAddend)
+ OS << " " << WasmReloc.Addend;
+ OS << "\n";
}
}
More information about the llvm-commits
mailing list