| 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/ic/ic.h" | |
| 13 #include "src/macro-assembler.h" | |
| 14 #include "test/cctest/cctest.h" | |
| 15 #include "test/cctest/compiler/c-signature.h" | |
| 16 #include "test/cctest/compiler/call-tester.h" | |
| 17 | |
| 18 using namespace v8::internal; | |
| 19 using namespace v8::internal::compiler; | |
| 20 | |
| 21 #define __ assm. | |
| 22 | |
| 23 static int32_t DummyStaticFunction(Object* result) { return 1; } | |
| 24 TEST(WasmRelocationX64movq64) { | |
| 25 CcTest::InitializeVM(); | |
| 26 Isolate* isolate = CcTest::i_isolate(); | |
| 27 HandleScope scope(isolate); | |
| 28 v8::internal::byte buffer[4096]; | |
| 29 Assembler assm(isolate, buffer, sizeof buffer); | |
| 30 DummyStaticFunction(NULL); | |
| 31 int64_t imm = 1234567; | |
| 32 | |
| 33 __ movq(rax, imm, RelocInfo::WASM_MEMORY_REFERENCE); | |
| 34 __ nop(); | |
| 35 __ ret(0); | |
| 36 | |
| 37 CodeDesc desc; | |
| 38 assm.GetCode(&desc); | |
| 39 Handle<Code> code = isolate->factory()->NewCode( | |
| 40 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
| 41 USE(code); | |
| 42 | |
| 43 CSignature0<int64_t> csig; | |
| 44 CodeRunner<int64_t> runnable(isolate, code, &csig); | |
| 45 int64_t ret_value = runnable.Call(); | |
| 46 CHECK_EQ(ret_value, imm); | |
| 47 | |
| 48 #ifdef OBJECT_PRINT | |
| 49 OFStream os(stdout); | |
| 50 code->Print(os); | |
| 51 byte* begin = code->instruction_start(); | |
| 52 byte* end = begin + code->instruction_size(); | |
| 53 disasm::Disassembler::Disassemble(stdout, begin, end); | |
| 54 #endif | |
| 55 size_t offset = 1234; | |
| 56 | |
| 57 // Relocating references by offset | |
| 58 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); | |
| 59 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
| 60 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
| 61 if (RelocInfo::IsWasmMemoryReference(mode)) { | |
| 62 // Dummy values of size used here as the objective of the test is to | |
| 63 // verify that the immediate is patched correctly | |
| 64 it.rinfo()->update_wasm_memory_reference( | |
| 65 it.rinfo()->wasm_memory_reference(), | |
| 66 it.rinfo()->wasm_memory_reference() + offset, 1, 2, | |
| 67 SKIP_ICACHE_FLUSH); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 // Check if immediate is updated correctly | |
| 72 ret_value = runnable.Call(); | |
| 73 printf("\nret_value: %lx", ret_value); | |
| 74 CHECK_EQ(ret_value, imm + offset); | |
| 75 | |
| 76 #ifdef OBJECT_PRINT | |
| 77 code->Print(os); | |
| 78 begin = code->instruction_start(); | |
| 79 end = begin + code->instruction_size(); | |
| 80 disasm::Disassembler::Disassemble(stdout, begin, end); | |
| 81 #endif | |
| 82 } | |
| 83 | |
| 84 #undef __ | |
| OLD | NEW |