Home | History | Annotate | Download | only in linker
      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 "globals.h"
     20 #include "base/bit_utils.h"
     21 #include "base/logging.h"
     22 
     23 namespace art {
     24 namespace linker {
     25 
     26 MultiOatRelativePatcher::MultiOatRelativePatcher(InstructionSet instruction_set,
     27                                                  const InstructionSetFeatures* features)
     28     : method_offset_map_(),
     29       relative_patcher_(
     30           linker::RelativePatcher::Create(instruction_set, features, &method_offset_map_)),
     31       adjustment_(0u),
     32       instruction_set_(instruction_set),
     33       start_size_code_alignment_(0u),
     34       start_size_relative_call_thunks_(0u),
     35       start_size_misc_thunks_(0u) {
     36 }
     37 
     38 void MultiOatRelativePatcher::StartOatFile(uint32_t adjustment) {
     39   DCHECK_ALIGNED(adjustment, kPageSize);
     40   adjustment_ = adjustment;
     41 
     42   start_size_code_alignment_ = relative_patcher_->CodeAlignmentSize();
     43   start_size_relative_call_thunks_ = relative_patcher_->RelativeCallThunksSize();
     44   start_size_misc_thunks_ = relative_patcher_->MiscThunksSize();
     45 }
     46 
     47 uint32_t MultiOatRelativePatcher::CodeAlignmentSize() const {
     48   DCHECK_GE(relative_patcher_->CodeAlignmentSize(), start_size_code_alignment_);
     49   return relative_patcher_->CodeAlignmentSize() - start_size_code_alignment_;
     50 }
     51 
     52 uint32_t MultiOatRelativePatcher::RelativeCallThunksSize() const {
     53   DCHECK_GE(relative_patcher_->RelativeCallThunksSize(), start_size_relative_call_thunks_);
     54   return relative_patcher_->RelativeCallThunksSize() - start_size_relative_call_thunks_;
     55 }
     56 
     57 uint32_t MultiOatRelativePatcher::MiscThunksSize() const {
     58   DCHECK_GE(relative_patcher_->MiscThunksSize(), start_size_misc_thunks_);
     59   return relative_patcher_->MiscThunksSize() - start_size_misc_thunks_;
     60 }
     61 
     62 std::pair<bool, uint32_t> MultiOatRelativePatcher::MethodOffsetMap::FindMethodOffset(
     63     MethodReference ref) {
     64   auto it = map.find(ref);
     65   if (it == map.end()) {
     66     return std::pair<bool, uint32_t>(false, 0u);
     67   } else {
     68     return std::pair<bool, uint32_t>(true, it->second);
     69   }
     70 }
     71 }  // namespace linker
     72 }  // namespace art
     73