Refactoring: introduce reloc_iterators
Replace rel/rela array with reloc_iterators. Change-Id: I6165d062e0390b6bc60da2e8279aabbedf828ec9
This commit is contained in:
parent
f8ff6b103b
commit
fa26eee776
@ -50,11 +50,12 @@
|
||||
#include "private/UniquePtr.h"
|
||||
|
||||
#include "linker.h"
|
||||
#include "linker_allocator.h"
|
||||
#include "linker_debug.h"
|
||||
#include "linker_environ.h"
|
||||
#include "linker_phdr.h"
|
||||
#include "linker_relocs.h"
|
||||
#include "linker_allocator.h"
|
||||
#include "linker_reloc_iterators.h"
|
||||
|
||||
/* >>> IMPORTANT NOTE - READ ME BEFORE MODIFYING <<<
|
||||
*
|
||||
@ -1297,9 +1298,10 @@ static ElfW(Addr) get_addend(ElfW(Rel)* rel, ElfW(Addr) reloc_addr) {
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename ElfRelT>
|
||||
bool soinfo::relocate(ElfRelT* rel, unsigned count, const soinfo_list_t& global_group, const soinfo_list_t& local_group) {
|
||||
for (size_t idx = 0; idx < count; ++idx, ++rel) {
|
||||
template<typename ElfRelIteratorT>
|
||||
bool soinfo::relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group, const soinfo_list_t& local_group) {
|
||||
for (size_t idx = 0; rel_iterator.has_next(); ++idx) {
|
||||
const auto rel = rel_iterator.next();
|
||||
ElfW(Word) type = ELFW(R_TYPE)(rel->r_info);
|
||||
ElfW(Word) sym = ELFW(R_SYM)(rel->r_info);
|
||||
|
||||
@ -2273,26 +2275,26 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
|
||||
#if defined(USE_RELA)
|
||||
if (rela_ != nullptr) {
|
||||
DEBUG("[ relocating %s ]", name);
|
||||
if (!relocate(rela_, rela_count_, global_group, local_group)) {
|
||||
if (!relocate(plain_reloc_iterator(rela_, rela_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (plt_rela_ != nullptr) {
|
||||
DEBUG("[ relocating %s plt ]", name);
|
||||
if (!relocate(plt_rela_, plt_rela_count_, global_group, local_group)) {
|
||||
if (!relocate(plain_reloc_iterator(plt_rela_, plt_rela_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (rel_ != nullptr) {
|
||||
DEBUG("[ relocating %s ]", name);
|
||||
if (!relocate(rel_, rel_count_, global_group, local_group)) {
|
||||
if (!relocate(plain_reloc_iterator(rel_, rel_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (plt_rel_ != nullptr) {
|
||||
DEBUG("[ relocating %s plt ]", name);
|
||||
if (!relocate(plt_rel_, plt_rel_count_, global_group, local_group)) {
|
||||
if (!relocate(plain_reloc_iterator(plt_rel_, plt_rel_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -286,8 +286,8 @@ struct soinfo {
|
||||
|
||||
void call_array(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
|
||||
void call_function(const char* function_name, linker_function_t function);
|
||||
template<typename ElfRelT>
|
||||
bool relocate(ElfRelT* rel, unsigned count, const soinfo_list_t& global_group, const soinfo_list_t& local_group);
|
||||
template<typename ElfRelIteratorT>
|
||||
bool relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group, const soinfo_list_t& local_group);
|
||||
|
||||
private:
|
||||
// This part of the structure is only available
|
||||
|
@ -29,10 +29,15 @@
|
||||
#include "linker.h"
|
||||
#include "linker_debug.h"
|
||||
#include "linker_relocs.h"
|
||||
#include "linker_reloc_iterators.h"
|
||||
|
||||
template bool soinfo::relocate<plain_reloc_iterator>(plain_reloc_iterator&& rel_iterator, const soinfo_list_t& global_group, const soinfo_list_t& local_group);
|
||||
|
||||
template <typename ElfRelIteratorT>
|
||||
bool soinfo::relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group, const soinfo_list_t& local_group) {
|
||||
for (size_t idx = 0; rel_iterator.has_next(); ++idx) {
|
||||
const auto rel = rel_iterator.next();
|
||||
|
||||
template<>
|
||||
bool soinfo::relocate(ElfW(Rel)* rel, unsigned count, const soinfo_list_t& global_group, const soinfo_list_t& local_group) {
|
||||
for (size_t idx = 0; idx < count; ++idx, ++rel) {
|
||||
ElfW(Word) type = ELFW(R_TYPE)(rel->r_info);
|
||||
ElfW(Word) sym = ELFW(R_SYM)(rel->r_info);
|
||||
|
||||
|
47
linker/linker_reloc_iterators.h
Normal file
47
linker/linker_reloc_iterators.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __LINKER_RELOC_ITERATORS_H
|
||||
#define __LINKER_RELOC_ITERATORS_H
|
||||
|
||||
#include "linker.h"
|
||||
|
||||
class plain_reloc_iterator {
|
||||
#if defined(USE_RELA)
|
||||
typedef ElfW(Rela) rel_t;
|
||||
#else
|
||||
typedef ElfW(Rel) rel_t;
|
||||
#endif
|
||||
public:
|
||||
plain_reloc_iterator(rel_t* rel_array, size_t count)
|
||||
: begin_(rel_array), end_(begin_ + count), current_(begin_) {}
|
||||
|
||||
bool has_next() {
|
||||
return current_ < end_;
|
||||
}
|
||||
|
||||
rel_t* next() {
|
||||
return current_++;
|
||||
}
|
||||
private:
|
||||
rel_t* const begin_;
|
||||
rel_t* const end_;
|
||||
rel_t* current_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(plain_reloc_iterator);
|
||||
};
|
||||
|
||||
#endif // __LINKER_RELOC_ITERATORS_H
|
Loading…
Reference in New Issue
Block a user