protected void DumpRela32(ElfLoader32 loader) { foreach (var section in loader.Sections.Where(s => s.Type == SectionHeaderType.SHT_RELA)) { ElfImageLoader.trace.Inform( "RELA: offset {0:X} symbol section {1}, relocating in section {2}", section.FileOffset, section.LinkedSection.Name, section.RelocatedSection.Name); var symbols = loader.Symbols[section.LinkedSection.FileOffset]; var rdr = loader.CreateReader(section.FileOffset); for (uint i = 0; i < section.EntryCount(); ++i) { var rela = Elf32_Rela.Read(rdr); ElfImageLoader.trace.Verbose( " off:{0:X8} type:{1,-16} add:{3,-20} {4,3} {2}", rela.r_offset, RelocationTypeToString(rela.r_info & 0xFF), symbols[(int)(rela.r_info >> 8)].Name, rela.r_addend, (int)(rela.r_info >> 8)); } } }
public override void Relocate(Program program) { DumpRel32(loader); DumpRela32(loader); foreach (var relSection in loader.Sections) { if (relSection.Type == SectionHeaderType.SHT_REL) { var sectionSymbols = loader.Symbols[relSection.LinkedSection]; var referringSection = relSection.RelocatedSection; var rdr = loader.CreateReader(relSection.FileOffset); for (uint i = 0; i < relSection.EntryCount(); ++i) { var rel = Elf32_Rel.Read(rdr); var sym = sectionSymbols[(int)(rel.r_info >> 8)]; RelocateEntry(program, sym, referringSection, rel); } } else if (relSection.Type == SectionHeaderType.SHT_RELA) { var sectionSymbols = loader.Symbols[relSection.LinkedSection]; var referringSection = relSection.RelocatedSection; var rdr = loader.CreateReader(relSection.FileOffset); for (uint i = 0; i < relSection.EntryCount(); ++i) { var rela = Elf32_Rela.Read(rdr); var sym = sectionSymbols[(int)(rela.r_info >> 8)]; RelocateEntry(program, sym, referringSection, rela); } } } }