Skip to content

Commit

Permalink
020 Readd extra sections and extra program headers
Browse files Browse the repository at this point in the history
  • Loading branch information
arakis committed Jan 13, 2019
1 parent 572c694 commit bfeb43c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Source/Mosa.Compiler.Framework/CompilerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ public class CompilerOptions
/// </summary>
public List<string> SourceFiles { get; set; } = new List<string>();

/// <summary>
/// Adds additional sections to the Elf-File.
/// </summary>
public MosaLinker.CreateExtraSectionsDelegate CreateExtraSections { get; set; }

/// <summary>
/// Adds additional program headers to the Elf-File.
/// </summary>
public MosaLinker.CreateExtraProgramHeaderDelegate CreateExtraProgramHeaders { get; set; }

#endregion Properties

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions Source/Mosa.Compiler.Framework/Linker/Elf/ElfLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ private void WriteProgramHeaders()

elfheader.ProgramHeaderNumber++;
}

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

programHeader.Write(linkerFormatType, writer);

elfheader.ProgramHeaderNumber++;
}
}
}

private void CreateSections()
Expand Down Expand Up @@ -282,9 +295,20 @@ private void CreateSections()

CreateRelocationSections();

if (linker.CreateExtraSections != null)
CreateExtraSections();

CreateSectionHeaderStringSection();
}

private void CreateExtraSections()
{
foreach (var section in linker.CreateExtraSections())
{
AddSection(section);
}
}

private void WriteSectionHeaders()
{
elfheader.SectionHeaderOffset = elfheader.ProgramHeaderOffset + (ProgramHeader.GetEntrySize(linkerFormatType) * elfheader.ProgramHeaderNumber);
Expand Down
11 changes: 10 additions & 1 deletion Source/Mosa.Compiler.Framework/Linker/MosaLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace Mosa.Compiler.Framework.Linker
/// </summary>
public sealed class MosaLinker
{

public delegate List<Section> CreateExtraSectionsDelegate();
public delegate List<ProgramHeader> CreateExtraProgramHeaderDelegate();

public List<LinkerSymbol> Symbols { get; } = new List<LinkerSymbol>();

public LinkerSection[] LinkerSections { get; } = new LinkerSection[4];
Expand Down Expand Up @@ -44,14 +48,19 @@ public sealed class MosaLinker

private readonly object _lock = new object();

public MosaLinker(ulong baseAddress, Endianness endianness, MachineType machineType, bool emitAllSymbols, bool emitStaticRelocations, LinkerFormatType linkerFormatType)
public CreateExtraSectionsDelegate CreateExtraSections { get; set; }
public CreateExtraProgramHeaderDelegate CreateExtraProgramHeaders { get; set; }

public MosaLinker(ulong baseAddress, Endianness endianness, MachineType machineType, bool emitAllSymbols, bool emitStaticRelocations, LinkerFormatType linkerFormatType, CreateExtraSectionsDelegate createExtraSections, CreateExtraProgramHeaderDelegate createExtraProgramHeaders)
{
BaseAddress = baseAddress;
Endianness = endianness;
MachineType = machineType;
EmitAllSymbols = emitAllSymbols;
EmitStaticRelocations = emitStaticRelocations;
LinkerFormatType = linkerFormatType;
CreateExtraSections = createExtraSections;
CreateExtraProgramHeaders = createExtraProgramHeaders;

elfLinker = new ElfLinker(this, LinkerFormatType);

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/MosaCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void ExecuteThreaded()

public void Initialize()
{
Linker = new MosaLinker(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.MachineType, CompilerOptions.EmitAllSymbols, CompilerOptions.EmitStaticRelocations, CompilerOptions.LinkerFormatType);
Linker = new MosaLinker(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.MachineType, CompilerOptions.EmitAllSymbols, CompilerOptions.EmitStaticRelocations, CompilerOptions.LinkerFormatType, CompilerOptions.CreateExtraSections, CompilerOptions.CreateExtraProgramHeaders);

Compiler = new Compiler(this);
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Mosa.Utility.Launcher/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public void Compile()
compiler.CompilerOptions.EmitStaticRelocations = Options.EmitStaticRelocations;
compiler.CompilerOptions.SetCustomOption("x86.irq-methods", Options.Emitx86IRQMethods ? "true" : "false");

compiler.CompilerOptions.CreateExtraSections = Options.CreateExtraSections;
compiler.CompilerOptions.CreateExtraProgramHeaders = Options.CreateExtraProgramHeaders;

if (Options.GenerateMapFile)
{
compiler.CompilerOptions.MapFile = Path.Combine(Options.DestinationDirectory, $"{Path.GetFileNameWithoutExtension(Options.SourceFile)}.map");
Expand Down
3 changes: 3 additions & 0 deletions Source/Mosa.Utility.Launcher/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ public string SourceFileHelper
[Option("hunt-corlib")]
public bool HuntForCorLib { get; set; }

public MosaLinker.CreateExtraSectionsDelegate CreateExtraSections { get; set; }
public MosaLinker.CreateExtraProgramHeaderDelegate CreateExtraProgramHeaders { get; set; }

public Options()
{
IncludeFiles = new List<IncludeFile>();
Expand Down

0 comments on commit bfeb43c

Please sign in to comment.