1 /* 2 * Copyright (C) 2023 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_DEX2OAT_LINKER_RISCV64_RELATIVE_PATCHER_RISCV64_H_ 18 #define ART_DEX2OAT_LINKER_RISCV64_RELATIVE_PATCHER_RISCV64_H_ 19 20 #include "base/array_ref.h" 21 #include "linker/relative_patcher.h" 22 23 namespace art { 24 25 namespace linker { 26 27 class Riscv64RelativePatcher final : public RelativePatcher { 28 public: 29 Riscv64RelativePatcher(RelativePatcherThunkProvider* thunk_provider, 30 RelativePatcherTargetProvider* target_provider, 31 const Riscv64InstructionSetFeatures* features); 32 33 uint32_t ReserveSpace(uint32_t offset, 34 const CompiledMethod* compiled_method, 35 MethodReference method_ref) override; 36 uint32_t ReserveSpaceEnd(uint32_t offset) override; 37 uint32_t WriteThunks(OutputStream* out, uint32_t offset) override; 38 void PatchCall(std::vector<uint8_t>* code, 39 uint32_t literal_offset, 40 uint32_t patch_offset, 41 uint32_t target_offset) override; 42 void PatchPcRelativeReference(std::vector<uint8_t>* code, 43 const LinkerPatch& patch, 44 uint32_t patch_offset, 45 uint32_t target_offset) override; 46 void PatchEntrypointCall(std::vector<uint8_t>* code, 47 const LinkerPatch& patch, 48 uint32_t patch_offset) override; 49 void PatchBakerReadBarrierBranch(std::vector<uint8_t>* code, 50 const LinkerPatch& patch, 51 uint32_t patch_offset) override; 52 std::vector<debug::MethodDebugInfo> GenerateThunkDebugInfo( 53 uint32_t executable_offset) override; 54 55 private: 56 static uint32_t PatchAuipc(uint32_t auipc, int32_t offset); 57 58 static void SetInsn(std::vector<uint8_t>* code, uint32_t offset, uint32_t value); 59 static uint32_t GetInsn(ArrayRef<const uint8_t> code, uint32_t offset); 60 template <typename Alloc> 61 uint32_t GetInsn(std::vector<uint8_t, Alloc>* code, uint32_t offset); 62 63 DISALLOW_COPY_AND_ASSIGN(Riscv64RelativePatcher); 64 }; 65 66 } // namespace linker 67 } // namespace art 68 69 #endif // ART_DEX2OAT_LINKER_RISCV64_RELATIVE_PATCHER_RISCV64_H_ 70