public void RemoveRelocLineTable()
 {
     if (RelocLineTable != null)
     {
         Elf.RemoveSection(RelocLineTable);
         RelocLineTable = null;
     }
 }
        private ElfRelocationTable GetOrCreateRelocationTable(ElfBinarySection section)
        {
            var newSection = new ElfRelocationTable()
            {
                Name      = $".rela{section.Name}",
                Alignment = (ulong)AddressSize,
                Flags     = ElfSectionFlags.InfoLink,
                Type      = ElfSectionType.RelocationAddends,
                Info      = section,
                Link      = _symbolTable,
            };

            Elf.AddSection(newSection);
            return(newSection);
        }
Exemple #3
0
        private static void CopyRelocationsX86_64(DwarfRelocatableSection dwarfRelocSection, DwarfElfContext elfContext, ElfRelocationTable relocTable)
        {
            relocTable.Entries.Clear();
            foreach (var reloc in dwarfRelocSection.Relocations)
            {
                var relocType = reloc.Size == DwarfAddressSize.Bit64 ? ElfRelocationType.R_X86_64_64 : ElfRelocationType.R_X86_64_32;
                switch (reloc.Target)
                {
                case DwarfRelocationTarget.Code:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.CodeSectionSymbolIndex, (long)reloc.Addend));
                    break;

                case DwarfRelocationTarget.DebugString:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.StringTableSymbolIndex, (long)reloc.Addend));
                    break;

                case DwarfRelocationTarget.DebugAbbrev:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.AbbreviationTableSymbolIndex, (long)reloc.Addend));
                    break;

                case DwarfRelocationTarget.DebugInfo:
                    relocTable.Entries.Add(new ElfRelocation(reloc.Offset, relocType, (uint)elfContext.InfoSectionSymbolIndex, (long)reloc.Addend));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Exemple #4
0
        public static void CopyRelocationsTo(this DwarfRelocatableSection dwarfRelocSection, DwarfElfContext elfContext, ElfRelocationTable relocTable)
        {
            if (elfContext == null)
            {
                throw new ArgumentNullException(nameof(elfContext));
            }
            if (relocTable == null)
            {
                throw new ArgumentNullException(nameof(relocTable));
            }

            switch (elfContext.Elf.Arch.Value)
            {
            case ElfArch.X86_64:
                CopyRelocationsX86_64(dwarfRelocSection, elfContext, relocTable);
                break;

            default:
                throw new NotImplementedException($"The relocation for architecture {relocTable.Parent.Arch} is not supported/implemented.");
            }
        }