blob: cdd2cef13ab475fa3baccf8290247d007906b1ab [file] [log] [blame]
Vladimir Markob163bb72015-03-31 21:49:49 +01001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "linker/x86/relative_patcher_x86.h"
18
Vladimir Marko1961b602015-04-08 20:51:48 +010019#include "compiled_method.h"
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010020#include "linker/linker_patch.h"
Vladimir Marko1961b602015-04-08 20:51:48 +010021
Vladimir Markob163bb72015-03-31 21:49:49 +010022namespace art {
23namespace linker {
24
Vladimir Markocac5a7e2016-02-22 10:39:50 +000025void X86RelativePatcher::PatchPcRelativeReference(std::vector<uint8_t>* code,
26 const LinkerPatch& patch,
27 uint32_t patch_offset,
28 uint32_t target_offset) {
Vladimir Marko1961b602015-04-08 20:51:48 +010029 uint32_t anchor_literal_offset = patch.PcInsnOffset();
30 uint32_t literal_offset = patch.LiteralOffset();
31
32 // Check that the anchor points to pop in a "call +0; pop <reg>" sequence.
33 DCHECK_GE(anchor_literal_offset, 5u);
34 DCHECK_LT(anchor_literal_offset, code->size());
35 DCHECK_EQ((*code)[anchor_literal_offset - 5u], 0xe8u);
36 DCHECK_EQ((*code)[anchor_literal_offset - 4u], 0x00u);
37 DCHECK_EQ((*code)[anchor_literal_offset - 3u], 0x00u);
38 DCHECK_EQ((*code)[anchor_literal_offset - 2u], 0x00u);
39 DCHECK_EQ((*code)[anchor_literal_offset - 1u], 0x00u);
40 DCHECK_EQ((*code)[anchor_literal_offset] & 0xf8u, 0x58u);
41
42 // Check that the patched data contains kDummy32BitOffset.
Vladimir Marko58155012015-08-19 12:49:41 +000043 // Must match X86Mir2Lir::kDummy32BitOffset and CodeGeneratorX86_64::kDummy32BitOffset.
44 constexpr int kDummy32BitOffset = 256;
Vladimir Marko1961b602015-04-08 20:51:48 +010045 DCHECK_LE(literal_offset, code->size());
46 DCHECK_EQ((*code)[literal_offset + 0u], static_cast<uint8_t>(kDummy32BitOffset >> 0));
47 DCHECK_EQ((*code)[literal_offset + 1u], static_cast<uint8_t>(kDummy32BitOffset >> 8));
48 DCHECK_EQ((*code)[literal_offset + 2u], static_cast<uint8_t>(kDummy32BitOffset >> 16));
49 DCHECK_EQ((*code)[literal_offset + 3u], static_cast<uint8_t>(kDummy32BitOffset >> 24));
50
51 // Apply patch.
52 uint32_t anchor_offset = patch_offset - literal_offset + anchor_literal_offset;
53 uint32_t diff = target_offset - anchor_offset;
54 (*code)[literal_offset + 0u] = static_cast<uint8_t>(diff >> 0);
55 (*code)[literal_offset + 1u] = static_cast<uint8_t>(diff >> 8);
56 (*code)[literal_offset + 2u] = static_cast<uint8_t>(diff >> 16);
57 (*code)[literal_offset + 3u] = static_cast<uint8_t>(diff >> 24);
Vladimir Markob163bb72015-03-31 21:49:49 +010058}
59
Vladimir Markof4f2daa2017-03-20 18:26:59 +000060void X86RelativePatcher::PatchBakerReadBarrierBranch(std::vector<uint8_t>* code ATTRIBUTE_UNUSED,
61 const LinkerPatch& patch ATTRIBUTE_UNUSED,
62 uint32_t patch_offset ATTRIBUTE_UNUSED) {
63 LOG(FATAL) << "UNIMPLEMENTED";
64}
65
Vladimir Markob163bb72015-03-31 21:49:49 +010066} // namespace linker
67} // namespace art