blob: 1449d478f994072f6dca4135e4daaa8c798a6fc0 [file] [log] [blame]
Vladimir Marko944da602016-02-19 12:27:55 +00001/*
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
Andreas Gampe57943812017-12-06 21:39:13 -080019#include <android-base/logging.h>
20
Vladimir Marko944da602016-02-19 12:27:55 +000021#include "base/bit_utils.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070022#include "globals.h"
Vladimir Markoca1e0382018-04-11 09:58:41 +000023#include "driver/compiled_method_storage.h"
Vladimir Marko944da602016-02-19 12:27:55 +000024
25namespace art {
26namespace linker {
27
Vladimir Markoca1e0382018-04-11 09:58:41 +000028void 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
Vladimir Marko944da602016-02-19 12:27:55 +000036MultiOatRelativePatcher::MultiOatRelativePatcher(InstructionSet instruction_set,
Vladimir Markoca1e0382018-04-11 09:58:41 +000037 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_)),
Vladimir Marko944da602016-02-19 12:27:55 +000045 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
52void MultiOatRelativePatcher::StartOatFile(uint32_t adjustment) {
53 DCHECK_ALIGNED(adjustment, kPageSize);
54 adjustment_ = adjustment;
55
56 start_size_code_alignment_ = relative_patcher_->CodeAlignmentSize();
57 start_size_relative_call_thunks_ = relative_patcher_->RelativeCallThunksSize();
58 start_size_misc_thunks_ = relative_patcher_->MiscThunksSize();
59}
60
61uint32_t MultiOatRelativePatcher::CodeAlignmentSize() const {
62 DCHECK_GE(relative_patcher_->CodeAlignmentSize(), start_size_code_alignment_);
63 return relative_patcher_->CodeAlignmentSize() - start_size_code_alignment_;
64}
65
66uint32_t MultiOatRelativePatcher::RelativeCallThunksSize() const {
67 DCHECK_GE(relative_patcher_->RelativeCallThunksSize(), start_size_relative_call_thunks_);
68 return relative_patcher_->RelativeCallThunksSize() - start_size_relative_call_thunks_;
69}
70
71uint32_t MultiOatRelativePatcher::MiscThunksSize() const {
72 DCHECK_GE(relative_patcher_->MiscThunksSize(), start_size_misc_thunks_);
73 return relative_patcher_->MiscThunksSize() - start_size_misc_thunks_;
74}
75
76std::pair<bool, uint32_t> MultiOatRelativePatcher::MethodOffsetMap::FindMethodOffset(
77 MethodReference ref) {
78 auto it = map.find(ref);
79 if (it == map.end()) {
80 return std::pair<bool, uint32_t>(false, 0u);
81 } else {
82 return std::pair<bool, uint32_t>(true, it->second);
83 }
84}
85} // namespace linker
86} // namespace art