OLD | NEW |
| (Empty) |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stdlib.h> | |
6 | |
7 #include "src/v8.h" | |
8 | |
9 #include "src/debug/debug.h" | |
10 #include "src/disasm.h" | |
11 #include "src/disassembler.h" | |
12 #include "src/ia32/frames-ia32.h" | |
13 #include "src/ic/ic.h" | |
14 #include "src/macro-assembler.h" | |
15 #include "test/cctest/cctest.h" | |
16 #include "test/cctest/compiler/c-signature.h" | |
17 #include "test/cctest/compiler/call-tester.h" | |
18 | |
19 using namespace v8::internal; | |
20 using namespace v8::internal::compiler; | |
21 | |
22 #define __ assm. | |
23 | |
24 static int32_t DummyStaticFunction(Object* result) { return 1; } | |
25 | |
26 TEST(WasmRelocationIa32) { | |
27 CcTest::InitializeVM(); | |
28 Zone zone; | |
29 Isolate* isolate = CcTest::i_isolate(); | |
30 HandleScope scope(isolate); | |
31 v8::internal::byte buffer[4096]; | |
32 Assembler assm(isolate, buffer, sizeof buffer); | |
33 DummyStaticFunction(NULL); | |
34 int32_t imm = 1234567; | |
35 | |
36 __ mov(eax, Immediate(reinterpret_cast<Address>(imm), | |
37 RelocInfo::WASM_MEMORY_REFERENCE)); | |
38 __ nop(); | |
39 __ ret(0); | |
40 | |
41 CSignature0<int32_t> csig; | |
42 CodeDesc desc; | |
43 assm.GetCode(&desc); | |
44 Handle<Code> code = isolate->factory()->NewCode( | |
45 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
46 USE(code); | |
47 | |
48 CodeRunner<int32_t> runnable(isolate, code, &csig); | |
49 int32_t ret_value = runnable.Call(); | |
50 CHECK_EQ(ret_value, imm); | |
51 | |
52 #ifdef OBJECT_PRINT | |
53 OFStream os(stdout); | |
54 code->Print(os); | |
55 byte* begin = code->instruction_start(); | |
56 byte* end = begin + code->instruction_size(); | |
57 disasm::Disassembler::Disassemble(stdout, begin, end); | |
58 #endif | |
59 | |
60 size_t offset = 1234; | |
61 | |
62 // Relocating references by offset | |
63 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); | |
64 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
65 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
66 if (RelocInfo::IsWasmMemoryReference(mode)) { | |
67 // Dummy values of size used here as the objective of the test is to | |
68 // verify that the immediate is patched correctly | |
69 it.rinfo()->update_wasm_memory_reference( | |
70 it.rinfo()->wasm_memory_reference(), | |
71 it.rinfo()->wasm_memory_reference() + offset, 1, 2, | |
72 SKIP_ICACHE_FLUSH); | |
73 } | |
74 } | |
75 | |
76 // Check if immediate is updated correctly | |
77 ret_value = runnable.Call(); | |
78 CHECK_EQ(ret_value, imm + offset); | |
79 | |
80 #ifdef OBJECT_PRINT | |
81 // OFStream os(stdout); | |
82 code->Print(os); | |
83 begin = code->instruction_start(); | |
84 end = begin + code->instruction_size(); | |
85 disasm::Disassembler::Disassemble(stdout, begin, end); | |
86 #endif | |
87 } | |
88 | |
89 #undef __ | |
OLD | NEW |