• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #include "multi_oat_relative_patcher.h"
18 
19 #include <android-base/logging.h>
20 
21 #include "base/bit_utils.h"
22 #include "base/globals.h"
23 #include "driver/compiled_method_storage.h"
24 
25 namespace art {
26 namespace linker {
27 
GetThunkCode(const LinkerPatch & patch,ArrayRef<const uint8_t> * code,std::string * debug_name)28 void MultiOatRelativePatcher::ThunkProvider::GetThunkCode(const LinkerPatch& patch,
29                                                           /*out*/ ArrayRef<const uint8_t>* code,
30                                                           /*out*/ std::string* debug_name) {
31   *code = storage_->GetThunkCode(patch, debug_name);
32   DCHECK(!code->empty());
33 }
34 
35 
MultiOatRelativePatcher(InstructionSet instruction_set,const InstructionSetFeatures * features,CompiledMethodStorage * storage)36 MultiOatRelativePatcher::MultiOatRelativePatcher(InstructionSet instruction_set,
37                                                  const InstructionSetFeatures* features,
38                                                  CompiledMethodStorage* storage)
39     : thunk_provider_(storage),
40       method_offset_map_(),
41       relative_patcher_(RelativePatcher::Create(instruction_set,
42                                                 features,
43                                                 &thunk_provider_,
44                                                 &method_offset_map_)),
45       adjustment_(0u),
46       instruction_set_(instruction_set),
47       start_size_code_alignment_(0u),
48       start_size_relative_call_thunks_(0u),
49       start_size_misc_thunks_(0u) {
50 }
51 
StartOatFile(uint32_t adjustment)52 void MultiOatRelativePatcher::StartOatFile(uint32_t adjustment) {
53   adjustment_ = adjustment;
54 
55   start_size_code_alignment_ = relative_patcher_->CodeAlignmentSize();
56   start_size_relative_call_thunks_ = relative_patcher_->RelativeCallThunksSize();
57   start_size_misc_thunks_ = relative_patcher_->MiscThunksSize();
58 }
59 
CodeAlignmentSize() const60 uint32_t MultiOatRelativePatcher::CodeAlignmentSize() const {
61   DCHECK_GE(relative_patcher_->CodeAlignmentSize(), start_size_code_alignment_);
62   return relative_patcher_->CodeAlignmentSize() - start_size_code_alignment_;
63 }
64 
RelativeCallThunksSize() const65 uint32_t MultiOatRelativePatcher::RelativeCallThunksSize() const {
66   DCHECK_GE(relative_patcher_->RelativeCallThunksSize(), start_size_relative_call_thunks_);
67   return relative_patcher_->RelativeCallThunksSize() - start_size_relative_call_thunks_;
68 }
69 
MiscThunksSize() const70 uint32_t MultiOatRelativePatcher::MiscThunksSize() const {
71   DCHECK_GE(relative_patcher_->MiscThunksSize(), start_size_misc_thunks_);
72   return relative_patcher_->MiscThunksSize() - start_size_misc_thunks_;
73 }
74 
FindMethodOffset(MethodReference ref)75 std::pair<bool, uint32_t> MultiOatRelativePatcher::MethodOffsetMap::FindMethodOffset(
76     MethodReference ref) {
77   auto it = map.find(ref);
78   if (it == map.end()) {
79     return std::pair<bool, uint32_t>(false, 0u);
80   } else {
81     return std::pair<bool, uint32_t>(true, it->second);
82   }
83 }
84 }  // namespace linker
85 }  // namespace art
86