Ejemplo n.º 1
0
        internal void WriteTo(Stream stream, LinkerSection section)
        {
            foreach (var symbol in Symbols)
            {
                if (symbol.IsReplaced)
                {
                    continue;
                }

                if (symbol.SectionKind != section.SectionKind)
                {
                    continue;
                }

                if (!symbol.IsResolved)
                {
                    continue;
                }

                stream.Seek(section.FileOffset + symbol.SectionOffset, SeekOrigin.Begin);

                if (symbol.IsDataAvailable)
                {
                    symbol.Stream.Position = 0;
                    symbol.Stream.WriteTo(stream);
                }
            }

            stream.WriteZeroBytes((int)(section.FileOffset + section.AlignedSize - stream.Position));
        }
Ejemplo n.º 2
0
        private void ResolveSectionLayout(LinkerSection section, uint fileOffset, ulong virtualAddress)
        {
            section.VirtualAddress = virtualAddress;
            section.FileOffset     = fileOffset;
            section.Size           = 0;

            foreach (var symbol in Symbols)
            {
                if (symbol.IsReplaced)
                {
                    continue;
                }

                if (symbol.SectionKind != section.SectionKind)
                {
                    continue;
                }

                if (symbol.IsResolved)
                {
                    continue;
                }

                //if (symbol.IsExternalSymbol)
                //	continue;

                symbol.SectionOffset  = section.Size;
                symbol.VirtualAddress = section.VirtualAddress + section.Size;
                section.Size         += symbol.Size;
            }

            section.Size       = Alignment.AlignUp(section.Size, SectionAlignment);
            section.IsResolved = true;
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 private void AddSection(LinkerSection linkerSection)
 {
     Sections[(int)linkerSection.SectionKind] = linkerSection;
 }
Ejemplo n.º 5
0
 private void AddSection(LinkerSection section)
 {
     LinkerSections[(int)section.SectionKind] = section;
 }