blob: f9b76e62505c52f6b5889a91ae2426c5a5ff02e0 [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
17#ifndef ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
18#define ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
19
20#include "linker/arm/relative_patcher_arm_base.h"
21#include "utils/array_ref.h"
22
23namespace art {
24namespace linker {
25
26class Arm64RelativePatcher FINAL : public ArmBaseRelativePatcher {
27 public:
28 Arm64RelativePatcher(RelativePatcherTargetProvider* provider,
29 const Arm64InstructionSetFeatures* features);
30
Vladimir Marko944da602016-02-19 12:27:55 +000031 uint32_t ReserveSpace(uint32_t offset,
32 const CompiledMethod* compiled_method,
Vladimir Marko4d23c9d2015-04-01 23:03:09 +010033 MethodReference method_ref) OVERRIDE;
Vladimir Marko71b0ddf2015-04-02 19:45:06 +010034 uint32_t ReserveSpaceEnd(uint32_t offset) OVERRIDE;
Vladimir Markob163bb72015-03-31 21:49:49 +010035 uint32_t WriteThunks(OutputStream* out, uint32_t offset) OVERRIDE;
Vladimir Marko944da602016-02-19 12:27:55 +000036 void PatchCall(std::vector<uint8_t>* code,
37 uint32_t literal_offset,
38 uint32_t patch_offset,
39 uint32_t target_offset) OVERRIDE;
40 void PatchDexCacheReference(std::vector<uint8_t>* code,
41 const LinkerPatch& patch,
42 uint32_t patch_offset,
43 uint32_t target_offset) OVERRIDE;
Vladimir Markob163bb72015-03-31 21:49:49 +010044
45 private:
46 static std::vector<uint8_t> CompileThunkCode();
47 static uint32_t PatchAdrp(uint32_t adrp, uint32_t disp);
48
49 static bool NeedsErratum843419Thunk(ArrayRef<const uint8_t> code, uint32_t literal_offset,
50 uint32_t patch_offset);
51 void SetInsn(std::vector<uint8_t>* code, uint32_t offset, uint32_t value);
52 static uint32_t GetInsn(ArrayRef<const uint8_t> code, uint32_t offset);
53
54 template <typename Alloc>
55 static uint32_t GetInsn(std::vector<uint8_t, Alloc>* code, uint32_t offset);
56
57 // Maximum positive and negative displacement measured from the patch location.
58 // (Signed 28 bit displacement with the last bit 0 has range [-2^27, 2^27-4] measured from
59 // the ARM64 PC pointing to the BL.)
60 static constexpr uint32_t kMaxPositiveDisplacement = (1u << 27) - 4u;
61 static constexpr uint32_t kMaxNegativeDisplacement = (1u << 27);
62
63 // The ADRP thunk for erratum 843419 is 2 instructions, i.e. 8 bytes.
64 static constexpr uint32_t kAdrpThunkSize = 8u;
65
66 const bool fix_cortex_a53_843419_;
67 // Map original patch_offset to thunk offset.
68 std::vector<std::pair<uint32_t, uint32_t>> adrp_thunk_locations_;
69 size_t reserved_adrp_thunks_;
70 size_t processed_adrp_thunks_;
71 std::vector<uint8_t> current_method_thunks_;
72
73 DISALLOW_COPY_AND_ASSIGN(Arm64RelativePatcher);
74};
75
76} // namespace linker
77} // namespace art
78
79#endif // ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_