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 <iostream> // NOLINT(readability/streams) |
| 6 |
| 7 #include "src/v8.h" |
| 8 #include "test/cctest/cctest.h" |
| 9 |
| 10 #include "src/arm/assembler-arm-inl.h" |
| 11 #include "src/arm/simulator-arm.h" |
| 12 #include "src/disassembler.h" |
| 13 #include "src/factory.h" |
| 14 #include "src/ostreams.h" |
| 15 #include "test/cctest/compiler/c-signature.h" |
| 16 #include "test/cctest/compiler/call-tester.h" |
| 17 |
| 18 using namespace v8::base; |
| 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(WasmRelocationArm) { |
| 27 CcTest::InitializeVM(); |
| 28 Isolate* isolate = CcTest::i_isolate(); |
| 29 HandleScope scope(isolate); |
| 30 v8::internal::byte buffer[4096]; |
| 31 DummyStaticFunction(NULL); |
| 32 int32_t imm = 1234567; |
| 33 |
| 34 Assembler assm(isolate, buffer, sizeof buffer); |
| 35 |
| 36 __ mov(r0, Operand(imm, RelocInfo::WASM_MEMORY_REFERENCE)); |
| 37 __ mov(pc, Operand(lr)); |
| 38 |
| 39 CodeDesc desc; |
| 40 assm.GetCode(&desc); |
| 41 Handle<Code> code = isolate->factory()->NewCode( |
| 42 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 43 |
| 44 CSignature0<int32_t> csig; |
| 45 CodeRunner<int32_t> runnable(isolate, code, &csig); |
| 46 int32_t ret_value = runnable.Call(); |
| 47 CHECK_EQ(ret_value, imm); |
| 48 |
| 49 #ifdef DEBUG |
| 50 OFStream os(stdout); |
| 51 code->Print(os); |
| 52 ::printf("f() = %d\n\n", ret_value); |
| 53 #endif |
| 54 size_t offset = 1234; |
| 55 |
| 56 // Relocating references by offset |
| 57 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); |
| 58 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 59 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 60 if (RelocInfo::IsWasmMemoryReference(mode)) { |
| 61 // Dummy values of size used here as the objective of the test is to |
| 62 // verify that the immediate is patched correctly |
| 63 it.rinfo()->update_wasm_memory_reference( |
| 64 it.rinfo()->wasm_memory_reference(), |
| 65 it.rinfo()->wasm_memory_reference() + offset, 1, 2, |
| 66 SKIP_ICACHE_FLUSH); |
| 67 } |
| 68 } |
| 69 |
| 70 // Call into relocated code object |
| 71 ret_value = runnable.Call(); |
| 72 CHECK_EQ((imm + offset), ret_value); |
| 73 |
| 74 #ifdef DEBUG |
| 75 code->Print(os); |
| 76 ::printf("f() = %d\n\n", ret_value); |
| 77 #endif |
| 78 } |
| 79 |
| 80 #undef __ |
OLD | NEW |