Refactoring: move VersionTracker to link_image
Use one instance of VersionTracker per link (instead of 2).
Change-Id: I6860013df65f5969975c82ebdae8bd90a82e0a82
(cherry picked from commit 7e4bbbae4a)
			
			
This commit is contained in:
		@@ -1780,14 +1780,8 @@ static ElfW(Addr) get_addend(ElfW(Rel)* rel, ElfW(Addr) reloc_addr) {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename ElfRelIteratorT>
 | 
					template<typename ElfRelIteratorT>
 | 
				
			||||||
bool soinfo::relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group,
 | 
					bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
 | 
				
			||||||
                      const soinfo_list_t& local_group) {
 | 
					                      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) {
 | 
					  for (size_t idx = 0; rel_iterator.has_next(); ++idx) {
 | 
				
			||||||
    const auto rel = rel_iterator.next();
 | 
					    const auto rel = rel_iterator.next();
 | 
				
			||||||
    if (rel == nullptr) {
 | 
					    if (rel == nullptr) {
 | 
				
			||||||
@@ -2866,6 +2860,12 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
 | 
				
			|||||||
    local_group_root_ = this;
 | 
					    local_group_root_ = this;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  VersionTracker version_tracker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!version_tracker.init(this)) {
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(__LP64__)
 | 
					#if !defined(__LP64__)
 | 
				
			||||||
  if (has_text_relocations) {
 | 
					  if (has_text_relocations) {
 | 
				
			||||||
    // Make segments writable to allow text relocations to work properly. We will later call
 | 
					    // Make segments writable to allow text relocations to work properly. We will later call
 | 
				
			||||||
@@ -2894,6 +2894,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;
 | 
					      const size_t packed_relocs_size = android_relocs_size_ - 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      relocated = relocate(
 | 
					      relocated = relocate(
 | 
				
			||||||
 | 
					          version_tracker,
 | 
				
			||||||
          packed_reloc_iterator<sleb128_decoder>(
 | 
					          packed_reloc_iterator<sleb128_decoder>(
 | 
				
			||||||
            sleb128_decoder(packed_relocs, packed_relocs_size)),
 | 
					            sleb128_decoder(packed_relocs, packed_relocs_size)),
 | 
				
			||||||
          global_group, local_group);
 | 
					          global_group, local_group);
 | 
				
			||||||
@@ -2910,26 +2911,30 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
 | 
				
			|||||||
#if defined(USE_RELA)
 | 
					#if defined(USE_RELA)
 | 
				
			||||||
  if (rela_ != nullptr) {
 | 
					  if (rela_ != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s ]", get_soname());
 | 
					    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;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (plt_rela_ != nullptr) {
 | 
					  if (plt_rela_ != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s plt ]", get_soname());
 | 
					    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;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  if (rel_ != nullptr) {
 | 
					  if (rel_ != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s ]", get_soname());
 | 
					    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;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (plt_rel_ != nullptr) {
 | 
					  if (plt_rel_ != nullptr) {
 | 
				
			||||||
    DEBUG("[ relocating %s plt ]", get_soname());
 | 
					    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;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -344,8 +344,8 @@ struct soinfo {
 | 
				
			|||||||
  void call_array(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
 | 
					  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);
 | 
					  void call_function(const char* function_name, linker_function_t function);
 | 
				
			||||||
  template<typename ElfRelIteratorT>
 | 
					  template<typename ElfRelIteratorT>
 | 
				
			||||||
  bool relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group,
 | 
					  bool relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
 | 
				
			||||||
                const soinfo_list_t& local_group);
 | 
					                const soinfo_list_t& global_group, const soinfo_list_t& local_group);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
  // This part of the structure is only available
 | 
					  // This part of the structure is only available
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,25 +32,22 @@
 | 
				
			|||||||
#include "linker_reloc_iterators.h"
 | 
					#include "linker_reloc_iterators.h"
 | 
				
			||||||
#include "linker_sleb128.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& global_group,
 | 
				
			||||||
                                                     const soinfo_list_t& local_group);
 | 
					                                                     const soinfo_list_t& local_group);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template bool soinfo::relocate<packed_reloc_iterator<sleb128_decoder>>(
 | 
					template bool soinfo::relocate<packed_reloc_iterator<sleb128_decoder>>(
 | 
				
			||||||
 | 
					    const VersionTracker& version_tracker,
 | 
				
			||||||
    packed_reloc_iterator<sleb128_decoder>&& rel_iterator,
 | 
					    packed_reloc_iterator<sleb128_decoder>&& rel_iterator,
 | 
				
			||||||
    const soinfo_list_t& global_group,
 | 
					    const soinfo_list_t& global_group,
 | 
				
			||||||
    const soinfo_list_t& local_group);
 | 
					    const soinfo_list_t& local_group);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename ElfRelIteratorT>
 | 
					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& global_group,
 | 
				
			||||||
                      const soinfo_list_t& local_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) {
 | 
					  for (size_t idx = 0; rel_iterator.has_next(); ++idx) {
 | 
				
			||||||
    const auto rel = rel_iterator.next();
 | 
					    const auto rel = rel_iterator.next();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user