blob: bf3a6482189de05e991c3c768d87b965f1b3092c [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_base.h"
18
19namespace art {
20namespace linker {
21
22uint32_t X86BaseRelativePatcher::ReserveSpace(
Vladimir Marko4d23c9d2015-04-01 23:03:09 +010023 uint32_t offset,
24 const CompiledMethod* compiled_method ATTRIBUTE_UNUSED,
25 MethodReference method_ref ATTRIBUTE_UNUSED) {
Vladimir Markob163bb72015-03-31 21:49:49 +010026 return offset; // No space reserved; no limit on relative call distance.
27}
28
Vladimir Marko71b0ddf2015-04-02 19:45:06 +010029uint32_t X86BaseRelativePatcher::ReserveSpaceEnd(uint32_t offset) {
30 return offset; // No space reserved; no limit on relative call distance.
31}
32
Vladimir Markob163bb72015-03-31 21:49:49 +010033uint32_t X86BaseRelativePatcher::WriteThunks(OutputStream* out ATTRIBUTE_UNUSED, uint32_t offset) {
34 return offset; // No thunks added; no limit on relative call distance.
35}
36
Vladimir Marko944da602016-02-19 12:27:55 +000037void X86BaseRelativePatcher::PatchCall(std::vector<uint8_t>* code,
38 uint32_t literal_offset,
39 uint32_t patch_offset,
40 uint32_t target_offset) {
Vladimir Markob163bb72015-03-31 21:49:49 +010041 DCHECK_LE(literal_offset + 4u, code->size());
42 // Unsigned arithmetic with its well-defined overflow behavior is just fine here.
43 uint32_t displacement = target_offset - patch_offset;
44 displacement -= kPcDisplacement; // The base PC is at the end of the 4-byte patch.
45
46 typedef __attribute__((__aligned__(1))) int32_t unaligned_int32_t;
47 reinterpret_cast<unaligned_int32_t*>(&(*code)[literal_offset])[0] = displacement;
48}
49
50} // namespace linker
51} // namespace art