blob: f8c6802f4699c48c55e82032259dd9e027eb5a44 [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
31 uint32_t ReserveSpace(uint32_t offset, const CompiledMethod* compiled_method) OVERRIDE;
32 uint32_t WriteThunks(OutputStream* out, uint32_t offset) OVERRIDE;
33 void PatchCall(std::vector<uint8_t>* code, uint32_t literal_offset,
34 uint32_t patch_offset, uint32_t target_offset) OVERRIDE;
35 void PatchDexCacheReference(std::vector<uint8_t>* code, const LinkerPatch& patch,
36 uint32_t patch_offset, uint32_t target_offset) OVERRIDE;
37
38 private:
39 static std::vector<uint8_t> CompileThunkCode();
40 static uint32_t PatchAdrp(uint32_t adrp, uint32_t disp);
41
42 static bool NeedsErratum843419Thunk(ArrayRef<const uint8_t> code, uint32_t literal_offset,
43 uint32_t patch_offset);
44 void SetInsn(std::vector<uint8_t>* code, uint32_t offset, uint32_t value);
45 static uint32_t GetInsn(ArrayRef<const uint8_t> code, uint32_t offset);
46
47 template <typename Alloc>
48 static uint32_t GetInsn(std::vector<uint8_t, Alloc>* code, uint32_t offset);
49
50 // Maximum positive and negative displacement measured from the patch location.
51 // (Signed 28 bit displacement with the last bit 0 has range [-2^27, 2^27-4] measured from
52 // the ARM64 PC pointing to the BL.)
53 static constexpr uint32_t kMaxPositiveDisplacement = (1u << 27) - 4u;
54 static constexpr uint32_t kMaxNegativeDisplacement = (1u << 27);
55
56 // The ADRP thunk for erratum 843419 is 2 instructions, i.e. 8 bytes.
57 static constexpr uint32_t kAdrpThunkSize = 8u;
58
59 const bool fix_cortex_a53_843419_;
60 // Map original patch_offset to thunk offset.
61 std::vector<std::pair<uint32_t, uint32_t>> adrp_thunk_locations_;
62 size_t reserved_adrp_thunks_;
63 size_t processed_adrp_thunks_;
64 std::vector<uint8_t> current_method_thunks_;
65
66 DISALLOW_COPY_AND_ASSIGN(Arm64RelativePatcher);
67};
68
69} // namespace linker
70} // namespace art
71
72#endif // ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_