From 78cd2834807c0fbf5788b68ba96675ef79dd5920 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Fri, 25 Oct 2019 17:46:43 -0700 Subject: [PATCH] linker: remove COUNT_PAGES COUNT_PAGES tries to count the pages dirtied by relocations, but this implementation is broken because it's merging rel->r_offset values from multiple DSOs. The functionality is hard to use, because it requires rebuilding the linker, and it's not obvious to me that it should belong in the linker. If we do want it, we should make it work without rebuilding the linker. Similar information can currently be collected by parsing the result of `readelf -r` on a binary (or a set of binaries). Bug: none Test: m linker libc com.android.runtime ; adb sync ; run something Change-Id: I760fb6ea4ea3d1927eb5145cdf4ca133851d69b4 --- linker/linker.cpp | 15 --------------- linker/linker_debug.h | 20 -------------------- linker/linker_main.cpp | 26 +------------------------- 3 files changed, 1 insertion(+), 60 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index dec575baf..e231de78c 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -300,10 +300,6 @@ void count_relocation(RelocationKind) { } #endif -#if COUNT_PAGES -uint32_t bitmask[4096]; -#endif - static void notify_gdb_of_load(soinfo* info) { if (info->is_linker() || info->is_main_executable()) { // gdb already knows about the linker and the main executable. @@ -3141,7 +3137,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r switch (type) { case R_GENERIC_JUMP_SLOT: count_relocation(kRelocAbsolute); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO JMP_SLOT %16p <- %16p %s\n", reinterpret_cast(reloc), reinterpret_cast(sym_addr + addend), sym_name); @@ -3151,7 +3146,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r case R_GENERIC_ABSOLUTE: case R_GENERIC_GLOB_DAT: count_relocation(kRelocAbsolute); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO ABSOLUTE/GLOB_DAT %16p <- %16p %s\n", reinterpret_cast(reloc), reinterpret_cast(sym_addr + addend), sym_name); @@ -3159,7 +3153,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r break; case R_GENERIC_RELATIVE: count_relocation(kRelocRelative); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO RELATIVE %16p <- %16p\n", reinterpret_cast(reloc), reinterpret_cast(load_bias + addend)); @@ -3167,7 +3160,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r break; case R_GENERIC_IRELATIVE: count_relocation(kRelocRelative); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO IRELATIVE %16p <- %16p\n", reinterpret_cast(reloc), reinterpret_cast(load_bias + addend)); @@ -3211,7 +3203,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r return false; case R_GENERIC_TLS_TPREL: count_relocation(kRelocRelative); - MARK(rel->r_offset); { ElfW(Addr) tpoff = 0; if (lsi == nullptr) { @@ -3237,7 +3228,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r break; case R_GENERIC_TLS_DTPMOD: count_relocation(kRelocRelative); - MARK(rel->r_offset); { size_t module_id = 0; if (lsi == nullptr) { @@ -3253,7 +3243,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r break; case R_GENERIC_TLS_DTPREL: count_relocation(kRelocRelative); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO TLS_DTPREL %16p <- %16p %s\n", reinterpret_cast(reloc), reinterpret_cast(sym_addr + addend), sym_name); @@ -3265,7 +3254,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r // other architectures, as long as the resolver functions are implemented. case R_GENERIC_TLSDESC: count_relocation(kRelocRelative); - MARK(rel->r_offset); { TlsDescriptor* desc = reinterpret_cast(reloc); if (lsi == nullptr) { @@ -3306,14 +3294,12 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r #if defined(__x86_64__) case R_X86_64_32: count_relocation(kRelocAbsolute); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO R_X86_64_32 %08zx <- +%08zx %s", static_cast(reloc), static_cast(sym_addr), sym_name); *reinterpret_cast(reloc) = sym_addr + addend; break; case R_X86_64_PC32: count_relocation(kRelocRelative); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO R_X86_64_PC32 %08zx <- +%08zx (%08zx - %08zx) %s", static_cast(reloc), static_cast(sym_addr - reloc), static_cast(sym_addr), static_cast(reloc), sym_name); @@ -3322,7 +3308,6 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r #elif defined(__i386__) case R_386_PC32: count_relocation(kRelocRelative); - MARK(rel->r_offset); TRACE_TYPE(RELO, "RELO R_386_PC32 %08x <- +%08x (%08x - %08x) %s", reloc, (sym_addr - reloc), sym_addr, reloc, sym_name); *reinterpret_cast(reloc) += (sym_addr - reloc); diff --git a/linker/linker_debug.h b/linker/linker_debug.h index 7a1cb3cbe..6031850a4 100644 --- a/linker/linker_debug.h +++ b/linker/linker_debug.h @@ -44,7 +44,6 @@ #define DO_TRACE_IFUNC 1 #define TIMING 0 #define STATS 0 -#define COUNT_PAGES 0 /********************************************************************* * You shouldn't need to modify anything below unless you are adding @@ -83,22 +82,3 @@ __LIBC_HIDDEN__ extern int g_ld_debug_verbosity; #endif /* TRACE_DEBUG */ #define TRACE_TYPE(t, x...) do { if (DO_TRACE_##t) { TRACE(x); } } while (0) - -#if COUNT_PAGES -extern uint32_t bitmask[]; -#if defined(__LP64__) -#define MARK(offset) \ - do { \ - if ((((offset) >> 12) >> 5) < 4096) \ - bitmask[((offset) >> 12) >> 5] |= (1 << (((offset) >> 12) & 31)); \ - } while (0) -#else -#define MARK(offset) \ - do { \ - bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \ - } while (0) -#endif -#else -#define MARK(x) do {} while (0) - -#endif diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp index fd1592d33..bea2e3c82 100644 --- a/linker/linker_main.cpp +++ b/linker/linker_main.cpp @@ -496,31 +496,7 @@ static ElfW(Addr) linker_main(KernelArgumentBlock& args, const char* exe_to_load #if STATS print_linker_stats(); #endif -#if COUNT_PAGES - { - unsigned n; - unsigned i; - unsigned count = 0; - for (n = 0; n < 4096; n++) { - if (bitmask[n]) { - unsigned x = bitmask[n]; -#if defined(__LP64__) - for (i = 0; i < 32; i++) { -#else - for (i = 0; i < 8; i++) { -#endif - if (x & 1) { - count++; - } - x >>= 1; - } - } - } - PRINT("PAGES MODIFIED: %s: %d (%dKB)", g_argv[0], count, count * 4); - } -#endif - -#if TIMING || STATS || COUNT_PAGES +#if TIMING || STATS fflush(stdout); #endif