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)); }
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; }
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)); }
private void AddSection(LinkerSection linkerSection) { Sections[(int)linkerSection.SectionKind] = linkerSection; }
private void AddSection(LinkerSection section) { LinkerSections[(int)section.SectionKind] = section; }