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