Пример #1
0
bool ElfRelocations::ApplyRelaRelocs(const ELF::Rela* rela,
                                     size_t rela_count,
                                     const ElfSymbols* symbols,
                                     SymbolResolver* resolver,
                                     Error* error) {
    RLOG("%s: rela=%p rela_count=%d\n", __FUNCTION__, rela, rela_count);

    if (!rela)
        return true;

    for (size_t rel_n = 0; rel_n < rela_count; rela++, rel_n++) {
        const ELF::Word rel_type = ELF_R_TYPE(rela->r_info);
        const ELF::Word rel_symbol = ELF_R_SYM(rela->r_info);

        ELF::Addr sym_addr = 0;
        ELF::Addr reloc = static_cast<ELF::Addr>(rela->r_offset + load_bias_);
        RLOG("  %d/%d reloc=%p offset=%p type=%d symbol=%d\n",
             rel_n + 1,
             rela_count,
             reloc,
             rela->r_offset,
             rel_type,
             rel_symbol);

        if (rel_type == 0)
            continue;

        bool resolved = false;

        // If this is a symbolic relocation, compute the symbol's address.
        if (__builtin_expect(rel_symbol != 0, 0)) {
            resolved = ResolveSymbol(rel_type,
                                     rel_symbol,
                                     symbols,
                                     resolver,
                                     reloc,
                                     &sym_addr,
                                     error);
        }

        if (!ApplyRelaReloc(rela, sym_addr, resolved, error))
            return false;
    }

    return true;
}
bool ElfRelocations::ApplyRelaRelocs(const ELF::Rela* rela,
                                     size_t rela_count,
                                     const ElfSymbols* symbols,
                                     SymbolResolver* resolver,
                                     Error* error) {
  RLOG("%s: rela=%p rela_count=%d\n", __FUNCTION__, rela, rela_count);

  if (!rela)
    return true;

  for (size_t rel_n = 0; rel_n < rela_count; rela++, rel_n++) {
    RLOG("  Relocation %d of %d:\n", rel_n + 1, rela_count);

    if (!ApplyRelaReloc(rela, symbols, resolver, error))
      return false;
  }

  return true;
}