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_64/relative_patcher_x86_64.h" 18 19 #include "compiled_method.h" 20 21 namespace art { 22 namespace linker { 23 24 void X86_64RelativePatcher::PatchPcRelativeReference(std::vector<uint8_t>* code, 25 const LinkerPatch& patch, 26 uint32_t patch_offset, 27 uint32_t target_offset) { 28 DCHECK_LE(patch.LiteralOffset() + 4u, code->size()); 29 // Unsigned arithmetic with its well-defined overflow behavior is just fine here. 30 uint32_t displacement = target_offset - patch_offset; 31 displacement -= kPcDisplacement; // The base PC is at the end of the 4-byte patch. 32 33 typedef __attribute__((__aligned__(1))) int32_t unaligned_int32_t; 34 reinterpret_cast<unaligned_int32_t*>(&(*code)[patch.LiteralOffset()])[0] = displacement; 35 } 36 37 void X86_64RelativePatcher::PatchBakerReadBarrierBranch(std::vector<uint8_t>* code ATTRIBUTE_UNUSED, 38 const LinkerPatch& patch ATTRIBUTE_UNUSED, 39 uint32_t patch_offset ATTRIBUTE_UNUSED) { 40 LOG(FATAL) << "UNIMPLEMENTED"; 41 } 42 43 } // namespace linker 44 } // namespace art 45