public static uint GetEntrySize(LinkerFormatType elfType)
 {
     if (elfType == LinkerFormatType.Elf32)
         return EntrySize32;
     else // if (elfType == ElfType.Elf64)
         return EntrySize64;
 }
 /// <summary>
 /// Writes the program header
 /// </summary>
 /// <param name="elfType">Type of the elf.</param>
 /// <param name="writer">The writer.</param>
 public void Write(LinkerFormatType elfType, BinaryWriter writer)
 {
     if (elfType == LinkerFormatType.Elf32)
         Write32(writer);
     else // if (elfType == ElfType.Elf64)
         Write64(writer);
 }
Beispiel #3
0
        public ElfLinker(BaseLinker linker, LinkerFormatType linkerFormatType)
        {
            this.linker           = linker;
            this.linkerFormatType = linkerFormatType;

            sectionHeaderStringTable.Add((byte)'\0');
            stringTable.Add((byte)'\0');

            BaseFileOffset   = 0x1000;             // required by ELF
            SectionAlignment = 0x1000;             // default 1K
        }
Beispiel #4
0
 public static int GetEntrySize(LinkerFormatType elfType)
 {
     if (elfType == LinkerFormatType.Elf32)
     {
         return(EntrySize32);
     }
     else // if (elfType == ElfType.Elf64)
     {
         return(EntrySize64);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Writes the program header
 /// </summary>
 /// <param name="elfType">Type of the elf.</param>
 /// <param name="writer">The writer.</param>
 public void Write(LinkerFormatType elfType, BinaryWriter writer)
 {
     if (elfType == LinkerFormatType.Elf32)
     {
         Write32(writer);
     }
     else if (elfType == LinkerFormatType.Elf64)
     {
         Write64(writer);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Writes the elf header
 /// </summary>
 /// <param name="elfType">Type of the elf.</param>
 /// <param name="writer">The writer.</param>
 public void Write(LinkerFormatType elfType, EndianAwareBinaryWriter writer)
 {
     if (elfType == LinkerFormatType.Elf32)
     {
         Write32(writer);
     }
     else             // if (elfType == ElfType.Elf64)
     {
         Write64(writer);
     }
 }
Beispiel #7
0
        public ElfLinker(MosaLinker linker, LinkerFormatType linkerFormatType, MachineType machineType)
        {
            Linker           = linker;
            LinkerFormatType = linkerFormatType;
            MachineType      = machineType;

            sectionHeaderStringTable.Add((byte)'\0');
            stringTable.Add((byte)'\0');

            BaseFileOffset   = 0x1000;             // required by ELF
            SectionAlignment = 0x1000;             // default 1K

            // Cache for faster performance
            EmitShortSymbolName = linker.LinkerSettings.ShortSymbolNames;
        }
Beispiel #8
0
        public void WriteSectionHeader(LinkerFormatType elfType, BinaryWriter writer)
        {
            var header = new SectionHeaderEntry();

            header.Name             = NameIndex;
            header.Address          = Address;
            header.Offset           = Offset;
            header.Size             = Size;
            header.EntrySize        = EntrySize;
            header.AddressAlignment = AddressAlignment;
            header.Type             = Type;
            header.Flags            = Flags;
            header.Link             = Link == null ? 0 : Link.Index;
            header.Info             = Info == null ? 0 : Info.Index;

            header.Write(elfType, writer);
        }
Beispiel #9
0
        public void WriteSectionHeader(LinkerFormatType elfType, BinaryWriter writer)
        {
            var header = new SectionHeaderEntry()
            {
                Name             = NameIndex,
                Address          = Address,
                Offset           = Offset,
                Size             = Size,
                EntrySize        = EntrySize,
                AddressAlignment = AddressAlignment,
                Type             = Type,
                Flags            = Flags,
                Link             = Link?.Index ?? 0,
                Info             = Info?.Index ?? 0
            };

            header.Write(elfType, writer);
        }
        public BaseLinker(ulong baseAddress, Endianness endianness, MachineType machineType, bool emitSymbols, LinkerFormatType linkerFormatType)
        {
            LinkerSections = new LinkerSection[4];

            BaseAddress = baseAddress;
            Endianness = endianness;
            MachineType = machineType;
            EmitSymbols = emitSymbols;

            elfLinker = new ElfLinker(this, LinkerFormatType);

            BaseFileOffset = elfLinker.BaseFileOffset;
            SectionAlignment = elfLinker.SectionAlignment;

            AddSection(new LinkerSection(SectionKind.Text, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.Data, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.ROData, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.BSS, SectionAlignment));
        }
Beispiel #11
0
        public BaseLinker(ulong baseAddress, Endianness endianness, MachineType machineType, bool emitSymbols, LinkerFormatType linkerFormatType)
        {
            LinkerSections = new LinkerSection[4];

            BaseAddress      = baseAddress;
            Endianness       = endianness;
            MachineType      = machineType;
            EmitSymbols      = emitSymbols;
            LinkerFormatType = linkerFormatType;

            elfLinker = new ElfLinker(this, LinkerFormatType);

            BaseFileOffset   = elfLinker.BaseFileOffset;
            SectionAlignment = elfLinker.SectionAlignment;

            AddSection(new LinkerSection(SectionKind.Text, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.Data, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.ROData, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.BSS, SectionAlignment));
        }
Beispiel #12
0
        public MosaLinker(ulong baseAddress, MachineType machineType, bool emitAllSymbols, bool emitStaticRelocations, LinkerFormatType linkerFormatType, CreateExtraSectionsDelegate createExtraSections, CreateExtraProgramHeaderDelegate createExtraProgramHeaders)
        {
            BaseAddress               = baseAddress;
            MachineType               = machineType;
            EmitAllSymbols            = emitAllSymbols;
            EmitStaticRelocations     = emitStaticRelocations;
            LinkerFormatType          = linkerFormatType;
            CreateExtraSections       = createExtraSections;
            CreateExtraProgramHeaders = createExtraProgramHeaders;

            elfLinker = new ElfLinker(this, LinkerFormatType);

            BaseFileOffset   = elfLinker.BaseFileOffset;
            SectionAlignment = elfLinker.SectionAlignment;

            AddSection(new LinkerSection(SectionKind.Text, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.Data, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.ROData, SectionAlignment));
            AddSection(new LinkerSection(SectionKind.BSS, SectionAlignment));
        }
Beispiel #13
0
        public void WriteSectionHeader(LinkerFormatType elfType, BinaryWriter writer)
        {
            var header = new SectionHeaderEntry();

            header.Name = NameIndex;
            header.Address = Address;
            header.Offset = Offset;
            header.Size = Size;
            header.EntrySize = EntrySize;
            header.AddressAlignment = AddressAlignment;
            header.Type = Type;
            header.Flags = Flags;
            header.Link = Link == null ? 0 : Link.Index;
            header.Info = Info == null ? 0 : Info.Index;

            header.Write(elfType, writer);
        }