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