blob: 9ad2c961bd934bf0fae48caaaba084b2baf155f7 [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
Vladimir Marko6d66fcf2018-04-12 13:15:27 +010017#ifndef ART_DEX2OAT_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
18#define ART_DEX2OAT_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
Vladimir Markob163bb72015-03-31 21:49:49 +010019
David Brazdild9c90372016-09-14 16:53:55 +010020#include "base/array_ref.h"
Vladimir Markob163bb72015-03-31 21:49:49 +010021#include "linker/arm/relative_patcher_arm_base.h"
Vladimir Markob163bb72015-03-31 21:49:49 +010022
23namespace art {
Vladimir Marko0a51fc32017-05-02 13:12:02 +010024
25namespace arm64 {
26class Arm64Assembler;
27} // namespace arm64
28
Vladimir Markob163bb72015-03-31 21:49:49 +010029namespace linker {
30
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010031class Arm64RelativePatcher final : public ArmBaseRelativePatcher {
Vladimir Markob163bb72015-03-31 21:49:49 +010032 public:
Vladimir Markoca1e0382018-04-11 09:58:41 +000033 Arm64RelativePatcher(RelativePatcherThunkProvider* thunk_provider,
34 RelativePatcherTargetProvider* target_provider,
Vladimir Markob163bb72015-03-31 21:49:49 +010035 const Arm64InstructionSetFeatures* features);
36
Vladimir Marko944da602016-02-19 12:27:55 +000037 uint32_t ReserveSpace(uint32_t offset,
38 const CompiledMethod* compiled_method,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010039 MethodReference method_ref) override;
40 uint32_t ReserveSpaceEnd(uint32_t offset) override;
41 uint32_t WriteThunks(OutputStream* out, uint32_t offset) override;
Vladimir Marko944da602016-02-19 12:27:55 +000042 void PatchCall(std::vector<uint8_t>* code,
43 uint32_t literal_offset,
44 uint32_t patch_offset,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010045 uint32_t target_offset) override;
Vladimir Markocac5a7e2016-02-22 10:39:50 +000046 void PatchPcRelativeReference(std::vector<uint8_t>* code,
47 const LinkerPatch& patch,
48 uint32_t patch_offset,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010049 uint32_t target_offset) override;
Vladimir Markof6675082019-05-17 12:05:28 +010050 void PatchEntrypointCall(std::vector<uint8_t>* code,
51 const LinkerPatch& patch,
52 uint32_t patch_offset) override;
Vladimir Markof4f2daa2017-03-20 18:26:59 +000053 void PatchBakerReadBarrierBranch(std::vector<uint8_t>* code,
54 const LinkerPatch& patch,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010055 uint32_t patch_offset) override;
Vladimir Markof4f2daa2017-03-20 18:26:59 +000056
57 protected:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010058 uint32_t MaxPositiveDisplacement(const ThunkKey& key) override;
59 uint32_t MaxNegativeDisplacement(const ThunkKey& key) override;
Vladimir Markob163bb72015-03-31 21:49:49 +010060
61 private:
Vladimir Markob163bb72015-03-31 21:49:49 +010062 static uint32_t PatchAdrp(uint32_t adrp, uint32_t disp);
Vladimir Markof6675082019-05-17 12:05:28 +010063 static void PatchBl(std::vector<uint8_t>* code, uint32_t literal_offset, uint32_t displacement);
Vladimir Markob163bb72015-03-31 21:49:49 +010064
65 static bool NeedsErratum843419Thunk(ArrayRef<const uint8_t> code, uint32_t literal_offset,
66 uint32_t patch_offset);
Vladimir Markof6675082019-05-17 12:05:28 +010067 static void SetInsn(std::vector<uint8_t>* code, uint32_t offset, uint32_t value);
Vladimir Markob163bb72015-03-31 21:49:49 +010068 static uint32_t GetInsn(ArrayRef<const uint8_t> code, uint32_t offset);
69
70 template <typename Alloc>
71 static uint32_t GetInsn(std::vector<uint8_t, Alloc>* code, uint32_t offset);
72
Vladimir Markob163bb72015-03-31 21:49:49 +010073 const bool fix_cortex_a53_843419_;
74 // Map original patch_offset to thunk offset.
75 std::vector<std::pair<uint32_t, uint32_t>> adrp_thunk_locations_;
76 size_t reserved_adrp_thunks_;
77 size_t processed_adrp_thunks_;
78 std::vector<uint8_t> current_method_thunks_;
79
Vladimir Markof4f2daa2017-03-20 18:26:59 +000080 friend class Arm64RelativePatcherTest;
81
Vladimir Markob163bb72015-03-31 21:49:49 +010082 DISALLOW_COPY_AND_ASSIGN(Arm64RelativePatcher);
83};
84
85} // namespace linker
86} // namespace art
87
Vladimir Marko6d66fcf2018-04-12 13:15:27 +010088#endif // ART_DEX2OAT_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_