Ejemplo n.º 1
0
        private void WriteProgramHeaders()
        {
            elfheader.ProgramHeaderOffset = ElfHeader.GetEntrySize(linkerFormatType);

            writer.SetPosition(elfheader.ProgramHeaderOffset);

            elfheader.ProgramHeaderNumber = 0;

            foreach (var linkerSection in linker.Sections)
            {
                if (linkerSection.Size == 0 && linkerSection.SectionKind != SectionKind.BSS)
                {
                    continue;
                }

                var programHeader = new ProgramHeader
                {
                    Alignment       = linkerSection.SectionAlignment,
                    FileSize        = linkerSection.AlignedSize,
                    MemorySize      = linkerSection.AlignedSize,
                    Offset          = linkerSection.FileOffset,
                    VirtualAddress  = linkerSection.VirtualAddress,
                    PhysicalAddress = linkerSection.VirtualAddress,
                    Type            = ProgramHeaderType.Load,
                    Flags           =
                        (linkerSection.SectionKind == SectionKind.Text) ? ProgramHeaderFlags.Read | ProgramHeaderFlags.Execute :
                        (linkerSection.SectionKind == SectionKind.ROData) ? ProgramHeaderFlags.Read : ProgramHeaderFlags.Read | ProgramHeaderFlags.Write
                };

                programHeader.Write(linkerFormatType, writer);

                elfheader.ProgramHeaderNumber++;
            }

            if (linker.CreateExtraProgramHeaders != null)
            {
                foreach (var programHeader in linker.CreateExtraProgramHeaders())
                {
                    if (programHeader.FileSize == 0)
                    {
                        continue;
                    }

                    programHeader.Write(linkerFormatType, writer);

                    elfheader.ProgramHeaderNumber++;
                }
            }
        }
Ejemplo n.º 2
0
        private void WriteProgramHeader(BinaryWriter writer)
        {
            elfheader.ProgramHeaderOffset = ElfHeader.GetEntrySize(LinkerFormatType);

            writer.SetPosition(elfheader.ProgramHeaderOffset);

            elfheader.ProgramHeaderNumber = 0;

            foreach (var section in sections)
            {
                if (section.SectionKind == SectionKind.Unknown)
                {
                    continue;
                }

                if (section.Size == 0 && section.SectionKind != SectionKind.BSS)
                {
                    continue;
                }

                if (section.Address == 0)
                {
                    continue;
                }

                var programHeader = new ProgramHeader
                {
                    Alignment       = SectionAlignment,
                    FileSize        = Alignment.AlignUp(section.Size, SectionAlignment),
                    MemorySize      = Alignment.AlignUp(section.Size, SectionAlignment),
                    Offset          = section.Offset,
                    VirtualAddress  = section.Address,
                    PhysicalAddress = section.Address,
                    Type            = ProgramHeaderType.Load,
                    Flags           =
                        (section.SectionKind == SectionKind.Text) ? ProgramHeaderFlags.Read | ProgramHeaderFlags.Execute :
                        (section.SectionKind == SectionKind.ROData) ? ProgramHeaderFlags.Read : ProgramHeaderFlags.Read | ProgramHeaderFlags.Write
                };

                programHeader.Write(LinkerFormatType, writer);

                elfheader.ProgramHeaderNumber++;
            }
        }