Line data Source code
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 "src/objects-inl.h"
15 : #include "src/ostreams.h"
16 : #include "test/cctest/cctest.h"
17 : #include "test/cctest/compiler/c-signature.h"
18 : #include "test/cctest/compiler/call-tester.h"
19 :
20 : namespace v8 {
21 : namespace internal {
22 : namespace compiler {
23 :
24 : #define __ assm.
25 :
26 : static int32_t DummyStaticFunction(Object* result) { return 1; }
27 :
28 23724 : TEST(WasmRelocationX64ContextReference) {
29 : Isolate* isolate = CcTest::i_isolate();
30 : HandleScope scope(isolate);
31 : v8::internal::byte buffer[4096];
32 6 : Assembler assm(isolate, buffer, sizeof buffer);
33 : DummyStaticFunction(nullptr);
34 : int64_t imm = 1234567;
35 :
36 6 : __ movq(rax, imm, RelocInfo::WASM_CONTEXT_REFERENCE);
37 6 : __ nop();
38 6 : __ ret(0);
39 :
40 : CodeDesc desc;
41 6 : assm.GetCode(isolate, &desc);
42 : Handle<Code> code =
43 6 : isolate->factory()->NewCode(desc, Code::STUB, Handle<Code>());
44 : USE(code);
45 :
46 : CSignature0<int64_t> csig;
47 : CodeRunner<int64_t> runnable(isolate, code, &csig);
48 6 : int64_t ret_value = runnable.Call();
49 6 : CHECK_EQ(ret_value, imm);
50 :
51 : #ifdef OBJECT_PRINT
52 : OFStream os(stdout);
53 : code->Print(os);
54 : byte* begin = code->instruction_start();
55 : byte* end = begin + code->instruction_size();
56 : disasm::Disassembler::Disassemble(stdout, begin, end);
57 : #endif
58 : int offset = 1234;
59 :
60 : // Relocating references by offset
61 : int mode_mask = (1 << RelocInfo::WASM_CONTEXT_REFERENCE);
62 12 : for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
63 : DCHECK(RelocInfo::IsWasmContextReference(it.rinfo()->rmode()));
64 : it.rinfo()->set_wasm_context_reference(
65 6 : isolate, it.rinfo()->wasm_context_reference() + offset,
66 6 : SKIP_ICACHE_FLUSH);
67 : }
68 :
69 : // Check if immediate is updated correctly
70 6 : ret_value = runnable.Call();
71 6 : CHECK_EQ(ret_value, imm + offset);
72 :
73 : #ifdef OBJECT_PRINT
74 : code->Print(os);
75 : begin = code->instruction_start();
76 : end = begin + code->instruction_size();
77 : disasm::Disassembler::Disassemble(stdout, begin, end);
78 : #endif
79 6 : }
80 :
81 : #undef __
82 :
83 : } // namespace compiler
84 : } // namespace internal
85 71154 : } // namespace v8
|