Merge changes I28bd3bc4,I6860013d
* changes: Lookup version info when relocating mips got Refactoring: move VersionTracker to link_image
This commit is contained in:
commit
7fbd6355ae
@ -1765,14 +1765,8 @@ static ElfW(Addr) get_addend(ElfW(Rel)* rel, ElfW(Addr) reloc_addr) {
|
||||
#endif
|
||||
|
||||
template<typename ElfRelIteratorT>
|
||||
bool soinfo::relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group) {
|
||||
VersionTracker version_tracker;
|
||||
|
||||
if (!version_tracker.init(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool soinfo::relocate(const VersionTracker& version_tracker, 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();
|
||||
if (rel == nullptr) {
|
||||
@ -2851,6 +2845,12 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
|
||||
local_group_root_ = this;
|
||||
}
|
||||
|
||||
VersionTracker version_tracker;
|
||||
|
||||
if (!version_tracker.init(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !defined(__LP64__)
|
||||
if (has_text_relocations) {
|
||||
// Make segments writable to allow text relocations to work properly. We will later call
|
||||
@ -2879,6 +2879,7 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
|
||||
const size_t packed_relocs_size = android_relocs_size_ - 4;
|
||||
|
||||
relocated = relocate(
|
||||
version_tracker,
|
||||
packed_reloc_iterator<sleb128_decoder>(
|
||||
sleb128_decoder(packed_relocs, packed_relocs_size)),
|
||||
global_group, local_group);
|
||||
@ -2895,33 +2896,37 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
|
||||
#if defined(USE_RELA)
|
||||
if (rela_ != nullptr) {
|
||||
DEBUG("[ relocating %s ]", get_soname());
|
||||
if (!relocate(plain_reloc_iterator(rela_, rela_count_), global_group, local_group)) {
|
||||
if (!relocate(version_tracker,
|
||||
plain_reloc_iterator(rela_, rela_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (plt_rela_ != nullptr) {
|
||||
DEBUG("[ relocating %s plt ]", get_soname());
|
||||
if (!relocate(plain_reloc_iterator(plt_rela_, plt_rela_count_), global_group, local_group)) {
|
||||
if (!relocate(version_tracker,
|
||||
plain_reloc_iterator(plt_rela_, plt_rela_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (rel_ != nullptr) {
|
||||
DEBUG("[ relocating %s ]", get_soname());
|
||||
if (!relocate(plain_reloc_iterator(rel_, rel_count_), global_group, local_group)) {
|
||||
if (!relocate(version_tracker,
|
||||
plain_reloc_iterator(rel_, rel_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (plt_rel_ != nullptr) {
|
||||
DEBUG("[ relocating %s plt ]", get_soname());
|
||||
if (!relocate(plain_reloc_iterator(plt_rel_, plt_rel_count_), global_group, local_group)) {
|
||||
if (!relocate(version_tracker,
|
||||
plain_reloc_iterator(plt_rel_, plt_rel_count_), global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__mips__)
|
||||
if (!mips_relocate_got(global_group, local_group)) {
|
||||
if (!mips_relocate_got(version_tracker, global_group, local_group)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@ -247,7 +247,9 @@ struct soinfo {
|
||||
uint32_t mips_symtabno_;
|
||||
uint32_t mips_local_gotno_;
|
||||
uint32_t mips_gotsym_;
|
||||
bool mips_relocate_got(const soinfo_list_t& global_group, const soinfo_list_t& local_group);
|
||||
bool mips_relocate_got(const VersionTracker& version_tracker,
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group);
|
||||
|
||||
#endif
|
||||
size_t ref_count_;
|
||||
@ -344,8 +346,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 ElfRelIteratorT>
|
||||
bool relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group);
|
||||
bool relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
|
||||
const soinfo_list_t& global_group, const soinfo_list_t& local_group);
|
||||
|
||||
private:
|
||||
// This part of the structure is only available
|
||||
|
@ -32,25 +32,22 @@
|
||||
#include "linker_reloc_iterators.h"
|
||||
#include "linker_sleb128.h"
|
||||
|
||||
template bool soinfo::relocate<plain_reloc_iterator>(plain_reloc_iterator&& rel_iterator,
|
||||
template bool soinfo::relocate<plain_reloc_iterator>(const VersionTracker& version_tracker,
|
||||
plain_reloc_iterator&& rel_iterator,
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group);
|
||||
|
||||
template bool soinfo::relocate<packed_reloc_iterator<sleb128_decoder>>(
|
||||
const VersionTracker& version_tracker,
|
||||
packed_reloc_iterator<sleb128_decoder>&& rel_iterator,
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group);
|
||||
|
||||
template <typename ElfRelIteratorT>
|
||||
bool soinfo::relocate(ElfRelIteratorT&& rel_iterator,
|
||||
bool soinfo::relocate(const VersionTracker& version_tracker,
|
||||
ElfRelIteratorT&& rel_iterator,
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group) {
|
||||
VersionTracker version_tracker;
|
||||
|
||||
if (!version_tracker.init(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t idx = 0; rel_iterator.has_next(); ++idx) {
|
||||
const auto rel = rel_iterator.next();
|
||||
|
||||
@ -127,7 +124,8 @@ bool soinfo::relocate(ElfRelIteratorT&& rel_iterator,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool soinfo::mips_relocate_got(const soinfo_list_t& global_group,
|
||||
bool soinfo::mips_relocate_got(const VersionTracker& version_tracker,
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group) {
|
||||
ElfW(Addr)** got = plt_got_;
|
||||
if (got == nullptr) {
|
||||
@ -151,21 +149,27 @@ bool soinfo::mips_relocate_got(const soinfo_list_t& global_group,
|
||||
}
|
||||
|
||||
// Now for the global GOT entries...
|
||||
ElfW(Sym)* sym = symtab_ + mips_gotsym_;
|
||||
got = plt_got_ + mips_local_gotno_;
|
||||
for (size_t g = mips_gotsym_; g < mips_symtabno_; g++, sym++, got++) {
|
||||
for (ElfW(Word) sym = mips_gotsym_; sym < mips_symtabno_; sym++, got++) {
|
||||
// This is an undefined reference... try to locate it.
|
||||
const char* sym_name = get_string(sym->st_name);
|
||||
const ElfW(Sym)* local_sym = symtab_ + sym;
|
||||
const char* sym_name = get_string(local_sym->st_name);
|
||||
soinfo* lsi = nullptr;
|
||||
const ElfW(Sym)* s = nullptr;
|
||||
if (!soinfo_do_lookup(this, sym_name, nullptr, &lsi, global_group, local_group, &s)) {
|
||||
|
||||
const version_info* vi = nullptr;
|
||||
|
||||
if (!lookup_version_info(version_tracker, sym, sym_name, &vi)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!soinfo_do_lookup(this, sym_name, vi, &lsi, global_group, local_group, &s)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (s == nullptr) {
|
||||
// We only allow an undefined symbol if this is a weak reference.
|
||||
s = &symtab_[g];
|
||||
if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
|
||||
if (ELF_ST_BIND(local_sym->st_info) != STB_WEAK) {
|
||||
DL_ERR("cannot locate \"%s\"...", sym_name);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user