xref: /aosp_15_r20/art/dex2oat/linker/x86_64/relative_patcher_x86_64.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
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 "linker/linker_patch.h"
20 
21 namespace art {
22 namespace linker {
23 
PatchPcRelativeReference(std::vector<uint8_t> * code,const LinkerPatch & patch,uint32_t patch_offset,uint32_t target_offset)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   using unaligned_int32_t __attribute__((__aligned__(1))) = int32_t;
34   reinterpret_cast<unaligned_int32_t*>(&(*code)[patch.LiteralOffset()])[0] = displacement;
35 }
36 
PatchEntrypointCall(std::vector<uint8_t> * code,const LinkerPatch & patch,uint32_t patch_offset)37 void X86_64RelativePatcher::PatchEntrypointCall([[maybe_unused]] std::vector<uint8_t>* code,
38                                                 [[maybe_unused]] const LinkerPatch& patch,
39                                                 [[maybe_unused]] uint32_t patch_offset) {
40   LOG(FATAL) << "UNIMPLEMENTED";
41 }
42 
PatchBakerReadBarrierBranch(std::vector<uint8_t> * code,const LinkerPatch & patch,uint32_t patch_offset)43 void X86_64RelativePatcher::PatchBakerReadBarrierBranch([[maybe_unused]] std::vector<uint8_t>* code,
44                                                         [[maybe_unused]] const LinkerPatch& patch,
45                                                         [[maybe_unused]] uint32_t patch_offset) {
46   LOG(FATAL) << "UNIMPLEMENTED";
47 }
48 
49 }  // namespace linker
50 }  // namespace art
51