Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | namespace art { |
| 20 | namespace linker { |
| 21 | |
| 22 | uint32_t X86BaseRelativePatcher::ReserveSpace( |
Vladimir Marko | 4d23c9d | 2015-04-01 23:03:09 +0100 | [diff] [blame] | 23 | uint32_t offset, |
| 24 | const CompiledMethod* compiled_method ATTRIBUTE_UNUSED, |
| 25 | MethodReference method_ref ATTRIBUTE_UNUSED) { |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 26 | return offset; // No space reserved; no limit on relative call distance. |
| 27 | } |
| 28 | |
Vladimir Marko | 71b0ddf | 2015-04-02 19:45:06 +0100 | [diff] [blame] | 29 | uint32_t X86BaseRelativePatcher::ReserveSpaceEnd(uint32_t offset) { |
| 30 | return offset; // No space reserved; no limit on relative call distance. |
| 31 | } |
| 32 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 33 | uint32_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 Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 37 | void X86BaseRelativePatcher::PatchCall(std::vector<uint8_t>* code, |
| 38 | uint32_t literal_offset, |
| 39 | uint32_t patch_offset, |
| 40 | uint32_t target_offset) { |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 41 | 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 |