From 53e9be1b70a83f0af0d10e56ffcbc0f2811ca7c2 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 23 Jul 2013 07:26:08 +0900 Subject: [PATCH] Bug 894829 - Avoid symbol resolution for relocations for the same symbol in faulty.lib. r=nfroyd --- mozglue/linker/CustomElf.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mozglue/linker/CustomElf.cpp b/mozglue/linker/CustomElf.cpp index 8df6c596c65..b9e83d955d5 100644 --- a/mozglue/linker/CustomElf.cpp +++ b/mozglue/linker/CustomElf.cpp @@ -637,6 +637,8 @@ bool CustomElf::Relocate() { DEBUG_LOG("Relocate %s @%p", GetPath(), static_cast(base)); + uint32_t symtab_index = (uint32_t) -1; + void *symptr = NULL; for (Array::iterator rel = relocations.begin(); rel < relocations.end(); ++rel) { /* Location of the relocation */ @@ -648,15 +650,16 @@ CustomElf::Relocate() continue; } /* Other relocation types need a symbol resolution */ - const Sym sym = symtab[ELF_R_SYM(rel->r_info)]; - void *symptr; - if (sym.st_shndx != SHN_UNDEF) { - symptr = GetPtr(sym.st_value); - } else { - /* TODO: avoid symbol resolution when it's the same symbol as last - * iteration */ - /* TODO: handle symbol resolving to NULL vs. being undefined. */ - symptr = GetSymbolPtrInDeps(strtab.GetStringAt(sym.st_name)); + /* Avoid symbol resolution when it's the same symbol as last iteration */ + if (symtab_index != ELF_R_SYM(rel->r_info)) { + symtab_index = ELF_R_SYM(rel->r_info); + const Sym sym = symtab[symtab_index]; + if (sym.st_shndx != SHN_UNDEF) { + symptr = GetPtr(sym.st_value); + } else { + /* TODO: handle symbol resolving to NULL vs. being undefined. */ + symptr = GetSymbolPtrInDeps(strtab.GetStringAt(sym.st_name)); + } } if (symptr == NULL)