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 <android-base/logging.h>
     20 
     21 #include "base/bit_utils.h"
     22 #include "globals.h"
     23 
     24 namespace art {
     25 namespace linker {
     26 
     27 MultiOatRelativePatcher::MultiOatRelativePatcher(InstructionSet instruction_set,
     28                                                  const InstructionSetFeatures* features)
     29     : method_offset_map_(),
     30       relative_patcher_(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