OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 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/arm64/simulator-arm64.h" |
| 34 #include "src/arm64/utils-arm64.h" |
| 35 #include "src/disassembler.h" |
| 36 #include "src/factory.h" |
| 37 #include "src/macro-assembler.h" |
| 38 #include "src/ostreams.h" |
| 39 #include "test/cctest/compiler/c-signature.h" |
| 40 #include "test/cctest/compiler/call-tester.h" |
| 41 |
| 42 using namespace v8::base; |
| 43 using namespace v8::internal; |
| 44 using namespace v8::internal::compiler; |
| 45 |
| 46 #define __ masm. |
| 47 |
| 48 static int64_t DummyStaticFunction(Object* result) { return 1; } |
| 49 |
| 50 TEST(WasmRelocationArm64) { |
| 51 CcTest::InitializeVM(); |
| 52 Isolate* isolate = CcTest::i_isolate(); |
| 53 HandleScope scope(isolate); |
| 54 v8::internal::byte buffer[4096]; |
| 55 DummyStaticFunction(NULL); |
| 56 int64_t imm = 1234567; |
| 57 |
| 58 MacroAssembler masm(isolate, buffer, sizeof buffer, |
| 59 v8::internal::CodeObjectRequired::kYes); |
| 60 |
| 61 __ Mov(x0, Immediate(imm, RelocInfo::WASM_HEAP_OBJECT)); |
| 62 __ Ret(); |
| 63 |
| 64 CodeDesc desc; |
| 65 masm.GetCode(&desc); |
| 66 Handle<Code> code = isolate->factory()->NewCode( |
| 67 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 68 |
| 69 CSignature0<int64_t> csig; |
| 70 CodeRunner<int64_t> runnable(isolate, code, &csig); |
| 71 int64_t ret_value = runnable.Call(); |
| 72 CHECK_EQ(ret_value, imm); |
| 73 |
| 74 #ifdef DEBUG |
| 75 OFStream os(stdout); |
| 76 code->Print(os); |
| 77 ::printf("f() = %ld\n\n", ret_value); |
| 78 #endif |
| 79 |
| 80 // Initialize new buffer |
| 81 v8::internal::byte new_buffer[4096]; |
| 82 size_t offset = |
| 83 reinterpret_cast<byte*>(new_buffer) - reinterpret_cast<byte*>(buffer); |
| 84 |
| 85 // Relocating code object |
| 86 int mode_mask = (1 << RelocInfo::WASM_HEAP_OBJECT); |
| 87 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 88 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 89 if (RelocInfo::IsWasmCodeEntry(mode)) { |
| 90 it.rinfo()->set_target_address(it.rinfo()->target_address() + offset, |
| 91 SKIP_WRITE_BARRIER, SKIP_ICACHE_FLUSH); |
| 92 } |
| 93 } |
| 94 |
| 95 // Call into relocated code object |
| 96 ret_value = runnable.Call(); |
| 97 CHECK_EQ((imm + offset), ret_value); |
| 98 |
| 99 #ifdef DEBUG |
| 100 code->Print(os); |
| 101 ::printf("f() = %ld\n\n", ret_value); |
| 102 #endif |
| 103 } |
| 104 |
| 105 #undef __ |
OLD | NEW |