OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
titzer
2016/03/14 15:23:38
Can we rename this file to be closer to what it do
gdeepti1
2016/03/14 20:08:14
Done.
| |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 #include <iostream> // NOLINT(readability/streams) | |
29 | |
30 #include "src/v8.h" | |
31 #include "test/cctest/cctest.h" | |
32 | |
33 #include "src/arm/assembler-arm-inl.h" | |
34 #include "src/arm/simulator-arm.h" | |
35 #include "src/disassembler.h" | |
36 #include "src/factory.h" | |
37 #include "src/ostreams.h" | |
38 #include "test/cctest/compiler/c-signature.h" | |
39 #include "test/cctest/compiler/call-tester.h" | |
40 | |
41 using namespace v8::base; | |
42 using namespace v8::internal; | |
43 using namespace v8::internal::compiler; | |
44 | |
45 #define __ assm. | |
46 | |
47 static int32_t DummyStaticFunction(Object* result) { return 1; } | |
48 | |
49 TEST(WasmRelocationArm) { | |
50 CcTest::InitializeVM(); | |
51 Isolate* isolate = CcTest::i_isolate(); | |
52 HandleScope scope(isolate); | |
53 v8::internal::byte buffer[4096]; | |
54 DummyStaticFunction(NULL); | |
55 int32_t imm = 1234567; | |
56 | |
57 Assembler assm(isolate, buffer, sizeof buffer); | |
58 | |
59 __ mov(r0, Operand(imm, RelocInfo::WASM_MEMORY_REFERENCE)); | |
60 __ mov(pc, Operand(lr)); | |
61 | |
62 CodeDesc desc; | |
63 assm.GetCode(&desc); | |
64 Handle<Code> code = isolate->factory()->NewCode( | |
65 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
66 | |
67 CSignature0<int32_t> csig; | |
68 CodeRunner<int32_t> runnable(isolate, code, &csig); | |
69 int32_t ret_value = runnable.Call(); | |
70 CHECK_EQ(ret_value, imm); | |
71 | |
72 #ifdef DEBUG | |
73 OFStream os(stdout); | |
74 code->Print(os); | |
75 ::printf("f() = %d\n\n", ret_value); | |
76 #endif | |
77 size_t offset = 1234; | |
78 | |
79 // Relocating references by offset | |
80 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); | |
81 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
82 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
83 if (RelocInfo::IsWasmMemoryReference(mode)) { | |
84 // Dummy values of size used here as the objective of the test is to | |
85 // verify that the immediate is patched correctly | |
86 it.rinfo()->update_wasm_memory_reference( | |
87 it.rinfo()->wasm_memory_reference(), | |
88 it.rinfo()->wasm_memory_reference() + offset, 1, 2, | |
89 SKIP_ICACHE_FLUSH); | |
90 } | |
91 } | |
92 | |
93 // Call into relocated code object | |
94 ret_value = runnable.Call(); | |
95 CHECK_EQ((imm + offset), ret_value); | |
96 | |
97 #ifdef DEBUG | |
98 code->Print(os); | |
99 ::printf("f() = %d\n\n", ret_value); | |
100 #endif | |
101 } | |
102 | |
103 #undef __ | |
OLD | NEW |