Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
ab2e067
Move ObjectWriter and ObjectWritingOptions into its own namespace
filipnavara Oct 18, 2022
ebef200
Add external sources for Melanzana.MachO and LibObjectFile
filipnavara Oct 18, 2022
f1bccfd
Disable versioning NuGets in external projects (MinVer, Nerdbank.GitV…
filipnavara Oct 18, 2022
eae83de
Add first draft of MachO and ELF object writers
filipnavara Oct 10, 2022
04a4c34
Generate relocatable DWARF info in ELF, fix X64 register mapping
filipnavara Oct 19, 2022
a889ee7
Fix writing base address with relocations
filipnavara Oct 19, 2022
e1733e7
Emit information about static variables, minor DWARF fixes
filipnavara Oct 19, 2022
ce591f7
Fix generated section layout in symbol table for Mach-O after EmitSym…
filipnavara Oct 19, 2022
2f52a06
Add support for ARM64 ELF
filipnavara Oct 19, 2022
bd94741
Add ObjectWriter class and derive UnixObjectWriter from it
filipnavara Oct 20, 2022
e8e3ef3
Add initial take on CoffObjectWriter
filipnavara Oct 21, 2022
212d4c2
Emit control flow guard information
filipnavara Oct 21, 2022
8fec3ff
Add win-arm64 support
filipnavara Oct 23, 2022
0b1a508
Misc cleanups of the COFF object writer
filipnavara Oct 24, 2022
5e96cd2
Remove GetSection
filipnavara Oct 24, 2022
4fde393
Add COFF COMDAT support
filipnavara Oct 25, 2022
1f71dc5
Add support for writing extended COFF object files (> 65279 sections)
filipnavara Oct 25, 2022
88ce825
Wrap some logic in SectionWriter struct; clean up code
filipnavara Oct 25, 2022
c27cb58
Emit GNU-stack note in ELF
filipnavara Oct 25, 2022
dbee5e1
Propagate DWARF5 option
filipnavara Oct 25, 2022
101e8c0
Initial take on CodeView type section builder
filipnavara Oct 26, 2022
d1f7644
Move SectionWriter out of ObjectWriter so it can be used by other bui…
filipnavara Oct 27, 2022
51f143c
Switch DwarfEhFrame to use UnixObjectWriter
filipnavara Oct 27, 2022
8f7384b
WIP: CodeView debugging information
filipnavara Oct 27, 2022
5f034a1
WIP: CodeView line mapping
filipnavara Oct 28, 2022
1958033
WIP: CodeView restructuring
filipnavara Oct 29, 2022
718a936
CodeView cleanup
filipnavara Oct 31, 2022
711c987
CodeView: Handle continuation records in lists
filipnavara Nov 1, 2022
3a78e7a
Add comments and asserts
filipnavara Nov 1, 2022
6540fd5
Emit CodeView symbols correctly when COMDAT is used
filipnavara Nov 1, 2022
b5390a0
Minor cleanup in CodeView, add ARM64 register mapping
filipnavara Nov 2, 2022
43416ce
Optimize memory usage when writing section content
filipnavara Nov 2, 2022
cbe9608
CodeView: Fix emitting size of big structures
filipnavara Nov 3, 2022
a028b32
Fix too aggressive zeroing of buffer
filipnavara Nov 3, 2022
868b8e2
Make sure not to dereference null returned from _debugInfo.GetLocalVa…
filipnavara Nov 3, 2022
6a6bda8
HACK: Do not emit debug information where LLVM ObjWriter would not.
filipnavara Nov 3, 2022
c06c030
Avoid some unnecessary name mangling calls
filipnavara Nov 3, 2022
5fdb1c1
Cache mangled names
filipnavara Nov 3, 2022
822d513
Fix ArgumentOutOfRangeException when writing DWARF debug info
filipnavara Nov 4, 2022
b6b8c93
Fix build after rebase
filipnavara Sep 10, 2023
90e652c
Add support for SectionType.Uninitialized
filipnavara Sep 10, 2023
eb14514
Add support for iOS-like platforms
filipnavara Sep 10, 2023
d96c8e1
Invoke object dumper from shared ObjectWriter
filipnavara Sep 10, 2023
12ed8d0
macOS/iOS: Emit simple compact unwinding information
filipnavara Sep 10, 2023
039c87c
Add support for new TLS relocations in ELF
filipnavara Sep 11, 2023
78fd4ef
Generate debug info even if managed debug info not present
filipnavara Sep 11, 2023
716c282
Fix counting the DwarfLineProgramTable layout (backport of https://gi…
filipnavara Sep 11, 2023
fd65a27
Remove incorrect assert in MachObjectWriter (text section starts at v…
filipnavara Sep 11, 2023
afafc76
Temporarily disable optimization that results in incorrect LSDA point…
filipnavara Sep 11, 2023
9428098
Fix emitting unwind tables in Mach-O
filipnavara Sep 11, 2023
ab5f878
Emit the MH_SUBSECTIONS_VIA_SYMBOLS header flag for Mach-O
filipnavara Sep 21, 2023
44a9057
Fix seeking in ObjectWriterStream
filipnavara Sep 21, 2023
9048667
Avoid excessive seeks by implementing SliceStream.CopyTo
filipnavara Sep 21, 2023
cc1975e
Use ObjectWriterStream in ElfObjectWriter
filipnavara Sep 21, 2023
52d5584
Use ObjectWriterStream for Mach-O
filipnavara Sep 21, 2023
789cda4
Fix setting the UNWIND_HAS_LSDA flag in compact unwind table
filipnavara Sep 21, 2023
0ddefe2
COFF:
filipnavara Sep 26, 2023
afcd1e4
COFF: Fix off-by-one error when writing more than 0xffff relocations …
filipnavara Sep 26, 2023
e5cf2e3
Make ObjectWriterStream the only supported stream and fix padding emi…
filipnavara Sep 26, 2023
ee21394
Fix scope overlapping in NAOT DWARF info (backport of https://github.…
filipnavara Sep 27, 2023
efd5b92
ELF: Use the address of __managedcode in DWARF info (backport of http…
filipnavara Sep 27, 2023
1fd9f55
ELF: Fix emitting global symbols
filipnavara Sep 27, 2023
ab2be43
ELF: Fix TLS support on linux-x64 Release builds
filipnavara Sep 27, 2023
6de5920
Return sorted set from GetUndefinedSymbols to avoid extra sorting
filipnavara Sep 26, 2023
f5017bc
COFF: Fix generating COMDAT section references in big-obj files
filipnavara Sep 27, 2023
2f5c20c
Generate Mach-O for iOS-like platforms, not ELF
filipnavara Sep 27, 2023
1c0fc8d
Fix EH frames on linux-arm64
filipnavara Sep 28, 2023
1176432
COFF: Support addend for IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A relocation
filipnavara Sep 30, 2023
dcaea22
COFF: Emit alignment for .pdata section
filipnavara Sep 30, 2023
553cce4
Fix padding emitted in ObjectWriterStream.AppendPadding
filipnavara Sep 30, 2023
b00650b
Fix ObjectWriterStream.Position setter (again)
filipnavara Sep 30, 2023
f713a2b
COFF: Emit .pdata/.xdata as associative COMDAT sections/symbols
filipnavara Sep 30, 2023
97435c0
ELF/LibObjectFile experiment: Add support for building optimized stri…
filipnavara Oct 2, 2023
c0ede64
LibObjectFile: Add support for >= 0xff00 sections
filipnavara Oct 4, 2023
b81765f
ELF: Add basic COMDAT support, don't emit empty relocation sections
filipnavara Oct 4, 2023
dfa9a82
ELF: Emit correct addresses and relocations in debug info, references…
filipnavara Oct 5, 2023
1dff572
Add missing StringComparer.Ordinal to dictionaries
filipnavara Oct 5, 2023
7821383
Remove incorrect assert
filipnavara Oct 5, 2023
632b638
WIP: Rewritten DWARF debug info emitter
filipnavara Oct 18, 2023
9124e97
Fix state change in ObjectWriterStream triggering an Assert
filipnavara Oct 20, 2023
a7aa171
WIP: Mach-O/DWARF
filipnavara Oct 20, 2023
e025342
DWARF Mach-O relocations done right
filipnavara Oct 20, 2023
5365b73
Do not output debug information for static variables that were trimmed
filipnavara Oct 22, 2023
bf697f7
WIP: Cleanup
filipnavara Oct 22, 2023
6cd80a2
Rework how symbol tables are generated, and how DWARF relocations are…
filipnavara Oct 23, 2023
1d921ca
Revert accidental change
filipnavara Oct 23, 2023
4d3f9d6
Update LibObjectFile to version 0.5.0.
filipnavara Oct 23, 2023
3c06121
Fix ELF section symbols and DW_AT_low_pc in DWARF debug info
filipnavara Oct 23, 2023
5b80655
Disable MinVer package in LibObjectFile
filipnavara Oct 23, 2023
6366906
ELF: Generate symbol table section index if there's more than 0xff00 …
filipnavara Oct 23, 2023
eb8c2af
Revert "Do not output debug information for static variables that wer…
filipnavara Oct 23, 2023
d8265ab
Fix typo
filipnavara Oct 23, 2023
9057747
Fix null dereference in CoffObjectWriter.CreateSection
filipnavara Oct 23, 2023
a303401
COFF: Add X86 support (tested on SmolSharp.HelloWorld)
filipnavara Oct 24, 2023
97a494f
Fix COMDAT symbol values
filipnavara Nov 12, 2023
f0306c8
Do not generate broken debug info for non-methods
filipnavara Nov 17, 2023
ad50dfb
Add generic StringTableBuilder and use it in COFF
filipnavara Nov 25, 2023
8bbdce3
Fix couple of bugs in last commit:
filipnavara Nov 26, 2023
9c883a4
COFF: Add support for '//BBBBBB' section names.
filipnavara Nov 26, 2023
93fb572
Add simple ELF writer
filipnavara Dec 6, 2023
1b08ff9
Port from main: Fix generating debug info for static fields
filipnavara Dec 6, 2023
819f2d0
Add (untested) x86 support to ElfObjectWriter
filipnavara Dec 7, 2023
6ef6e79
Cleanup
filipnavara Dec 7, 2023
094cdf0
Move Dwarf/CodeView files into their respective directories
filipnavara Dec 8, 2023
95a1fca
Make bulk of the ObjectWriter classes internal, improve logging
filipnavara Dec 8, 2023
10bb132
Use IBinaryInteger for WriteLittleEndian helper method
filipnavara Dec 8, 2023
28ee6ca
Add simple Mach-O object file writer that doesn't use Melanzana.MachO
filipnavara Dec 9, 2023
c219e63
Rename LlvmObjectWriter to LegacyObjectWriter to prevent conflict wit…
filipnavara Dec 9, 2023
3d53df5
Mach-O: Swap the order of symbol table and string table to make strip…
filipnavara Dec 9, 2023
fd274ed
Fix the CPU type/subtype
filipnavara Dec 10, 2023
9f69232
Fix Release build
filipnavara Dec 10, 2023
7213ce7
Eliminate relocations for known symbols within the same section
filipnavara Dec 11, 2023
0e9c899
Fix IMAGE_REL_BASED_ARM64_BRANCH26
filipnavara Dec 11, 2023
618e8c5
Attempt to fix CI errors
filipnavara Dec 11, 2023
558c2d6
Fix incorrect addends in COFF
filipnavara Dec 11, 2023
56ae35f
Fix ELF rela section flags; omit frame symbols for ELF
filipnavara Dec 11, 2023
ec4d5fa
Split the writing and reading part of section data
filipnavara Dec 11, 2023
b8be8b6
Cleanup
filipnavara Dec 11, 2023
e3499e3
Pattern matching consistency
filipnavara Dec 11, 2023
c7b4984
Comments, more cleanup
filipnavara Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split the writing and reading part of section data
  • Loading branch information
filipnavara committed Dec 11, 2023
commit ec4d5fa0a098d077d90993ce8302c14a5d5a318b
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,14 @@ public uint GetFileIndex(string fileName)
}
}

public void Write(Stream sectionStream)
public void Write(SectionWriter sectionWriter)
{
Span<byte> subsectionHeader = stackalloc byte[sizeof(uint) + sizeof(uint)];

BinaryPrimitives.WriteUInt32LittleEndian(subsectionHeader, (uint)DebugSymbolsSubsectionType.FileChecksums);
BinaryPrimitives.WriteUInt32LittleEndian(subsectionHeader.Slice(4), (uint)_fileTableWriter.Length);
sectionStream.Write(subsectionHeader);
_fileTableWriter.Position = 0;
_fileTableWriter.CopyTo(sectionStream);

BinaryPrimitives.WriteUInt32LittleEndian(subsectionHeader, (uint)DebugSymbolsSubsectionType.StringTable);
BinaryPrimitives.WriteUInt32LittleEndian(subsectionHeader.Slice(4), (uint)_stringTableWriter.Length);
sectionStream.Write(subsectionHeader);
_stringTableWriter.Position = 0;
_stringTableWriter.CopyTo(sectionStream);
sectionWriter.WriteLittleEndian<uint>((uint)DebugSymbolsSubsectionType.FileChecksums);
sectionWriter.WriteLittleEndian<uint>((uint)_fileTableWriter.Length);
sectionWriter.EmitData(_fileTableWriter.GetBuffer().AsMemory(0, (int)_fileTableWriter.Length));
sectionWriter.WriteLittleEndian<uint>((uint)DebugSymbolsSubsectionType.StringTable);
sectionWriter.WriteLittleEndian<uint>((uint)_stringTableWriter.Length);
sectionWriter.EmitData(_stringTableWriter.GetBuffer().AsMemory(0, (int)_stringTableWriter.Length));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CodeViewSymbolsBuilder(TargetArchitecture targetArchitecture, SectionWrit
// Write CodeView version header
Span<byte> versionBuffer = stackalloc byte[sizeof(uint)];
BinaryPrimitives.WriteUInt32LittleEndian(versionBuffer, 4);
sectionWriter.Stream.Write(versionBuffer);
sectionWriter.Write(versionBuffer);
}

// Maps an ICorDebugInfo register number to the corresponding CodeView
Expand Down Expand Up @@ -310,7 +310,7 @@ public void Dispose()
Span<byte> subsectionHeader = stackalloc byte[sizeof(uint) + sizeof(uint)];
BinaryPrimitives.WriteUInt32LittleEndian(subsectionHeader, (uint)_kind);
BinaryPrimitives.WriteUInt32LittleEndian(subsectionHeader.Slice(4), _size);
_sectionWriter.Stream.Write(subsectionHeader);
_sectionWriter.Write(subsectionHeader);

foreach (var (offset, relocType, symbolName) in _relocations)
{
Expand All @@ -324,7 +324,7 @@ public void Dispose()

foreach (byte[] data in _data)
{
_sectionWriter.Stream.Write(data);
_sectionWriter.Write(data);
}

_sectionWriter.EmitAlignment(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ILCompiler.ObjectWriter
internal sealed class CodeViewTypesBuilder : ITypesDebugInfoWriter
{
private NameMangler _nameMangler;
private Stream _outputStream;
private SectionWriter _sectionWriter;
private int _targetPointerSize;

private uint _classVTableTypeIndex;
Expand All @@ -50,10 +50,10 @@ internal sealed class CodeViewTypesBuilder : ITypesDebugInfoWriter

public IList<(string, uint)> UserDefinedTypes => _userDefinedTypes;

public CodeViewTypesBuilder(NameMangler nameMangler, TargetArchitecture targetArchitecture, Stream outputStream)
public CodeViewTypesBuilder(NameMangler nameMangler, TargetArchitecture targetArchitecture, SectionWriter sectionWriter)
{
_nameMangler = nameMangler;
_outputStream = outputStream;
_sectionWriter = sectionWriter;
_targetPointerSize = targetArchitecture switch
{
TargetArchitecture.ARM => 4,
Expand All @@ -64,7 +64,7 @@ public CodeViewTypesBuilder(NameMangler nameMangler, TargetArchitecture targetAr
// Write CodeView version header
Span<byte> versionBuffer = stackalloc byte[sizeof(uint)];
BinaryPrimitives.WriteUInt32LittleEndian(versionBuffer, 4);
_outputStream.Write(versionBuffer);
_sectionWriter.Write(versionBuffer);

// We pretend that the MethodTable pointer in System.Object is VTable shape.
// We use the same "Vtable" for all types because the vtable shape debug
Expand Down Expand Up @@ -418,9 +418,9 @@ public void Dispose()
Debug.Assert(length <= ushort.MaxValue);
Span<byte> lengthBuffer = stackalloc byte[sizeof(ushort)];
BinaryPrimitives.WriteUInt16LittleEndian(lengthBuffer, (ushort)(length + padding - sizeof(ushort)));
_debugTypesBuilder._outputStream.Write(lengthBuffer);
_debugTypesBuilder._outputStream.Write(_bufferWriter.WrittenSpan);
_debugTypesBuilder._outputStream.Write(stackalloc byte[padding]);
_debugTypesBuilder._sectionWriter.Write(lengthBuffer);
_debugTypesBuilder._sectionWriter.Write(_bufferWriter.WrittenSpan);
_debugTypesBuilder._sectionWriter.Write(stackalloc byte[padding]);
_bufferWriter.Clear();
}

Expand Down Expand Up @@ -517,11 +517,9 @@ public void EndListEntry()
// Flush the current record up to _lastListMemberStart and write LF_INDEX to reference it.
int length = sizeof(ushort) + _lastListMemberStart;
int padding = ((length + 3) & ~3) - length;
Span<byte> lengthBuffer = stackalloc byte[sizeof(ushort)];
BinaryPrimitives.WriteUInt16LittleEndian(lengthBuffer, (ushort)(length + padding - sizeof(ushort)));
_debugTypesBuilder._outputStream.Write(lengthBuffer);
_debugTypesBuilder._outputStream.Write(_bufferWriter.WrittenSpan.Slice(0, _lastListMemberStart));
_debugTypesBuilder._outputStream.Write(stackalloc byte[padding]);
_debugTypesBuilder._sectionWriter.WriteLittleEndian<ushort>((ushort)(length + padding - sizeof(ushort)));
_debugTypesBuilder._sectionWriter.Write(_bufferWriter.WrittenSpan.Slice(0, _lastListMemberStart));
_debugTypesBuilder._sectionWriter.Write(stackalloc byte[padding]);
byte[] overflow = _bufferWriter.WrittenSpan.Slice(_lastListMemberStart).ToArray();
_bufferWriter.Clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,9 @@ protected override void EmitSymbolTable(
// Create section with control flow guard symbols
SectionWriter gfidsSectionWriter = GetOrCreateSection(GfidsSection);

Span<byte> tempBuffer = stackalloc byte[4];
foreach (var symbolName in _referencedMethods)
{
BinaryPrimitives.WriteUInt32LittleEndian(tempBuffer, _symbolNameToIndex[symbolName]);
gfidsSectionWriter.Stream.Write(tempBuffer);
gfidsSectionWriter.WriteLittleEndian<uint>(_symbolNameToIndex[symbolName]);
}

// Emit the feat.00 symbol that controls various linker behaviors
Expand Down Expand Up @@ -436,13 +434,13 @@ protected override void EmitUnwindInfo(
xdataSectionWriter.EmitSymbolDefinition(unwindSymbolName);

// Emit UNWIND_INFO
xdataSectionWriter.Stream.Write(blob);
xdataSectionWriter.Write(blob);

FrameInfoFlags flags = frameInfo.Flags;

if (i != 0)
{
xdataSectionWriter.Stream.WriteByte((byte)flags);
xdataSectionWriter.WriteByte((byte)flags);
}
else
{
Expand All @@ -452,7 +450,7 @@ protected override void EmitUnwindInfo(
flags |= ehInfo != null ? FrameInfoFlags.HasEHInfo : 0;
flags |= associatedDataNode != null ? FrameInfoFlags.HasAssociatedData : 0;

xdataSectionWriter.Stream.WriteByte((byte)flags);
xdataSectionWriter.WriteByte((byte)flags);

if (associatedDataNode != null)
{
Expand All @@ -468,7 +466,7 @@ protected override void EmitUnwindInfo(

if (nodeWithCodeInfo.GCInfo != null)
{
xdataSectionWriter.Stream.Write(nodeWithCodeInfo.GCInfo);
xdataSectionWriter.Write(nodeWithCodeInfo.GCInfo);
}
}

Expand Down Expand Up @@ -614,7 +612,7 @@ protected override ITypesDebugInfoWriter CreateDebugInfoBuilder()
_debugTypesSectionWriter.EmitAlignment(4);
_debugTypesBuilder = new CodeViewTypesBuilder(
_nodeFactory.NameMangler, _nodeFactory.Target.Architecture,
_debugTypesSectionWriter.Stream);
_debugTypesSectionWriter);
return _debugTypesBuilder;
}

Expand Down Expand Up @@ -665,7 +663,7 @@ protected override void EmitDebugFunctionInfo(
protected override void EmitDebugSections(IDictionary<string, SymbolDefinition> definedSymbols)
{
_debugSymbolsBuilder.WriteUserDefinedTypes(_debugTypesBuilder.UserDefinedTypes);
_debugFileTableBuilder.Write(_debugSymbolSectionWriter.Stream);
_debugFileTableBuilder.Write(_debugSymbolSectionWriter);
}

private sealed class CoffHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ public DwarfAbbrev(ushort[] definition)

public int AbbreviationCode { get; set; }

public void Write(ObjectWriterStream stream, int targetPointerSize)
public void Write(SectionWriter writer, int targetPointerSize)
{
stream.WriteULEB128((ulong)AbbreviationCode);
stream.WriteULEB128(Tag);
stream.WriteULEB128(HasChildren ? DW_CHILDREN_yes : DW_CHILDREN_no);
writer.WriteULEB128((ulong)AbbreviationCode);
writer.WriteULEB128(Tag);
writer.WriteULEB128(HasChildren ? DW_CHILDREN_yes : DW_CHILDREN_no);

for (int i = 2; i < _definition.Length; i++)
{
// Attribute
stream.WriteULEB128(_definition[i++]);
writer.WriteULEB128(_definition[i++]);
// Form
if (_definition[i] != DW_FORM_size)
{
stream.WriteULEB128(_definition[i]);
writer.WriteULEB128(_definition[i]);
}
else if (targetPointerSize == 8)
{
stream.WriteULEB128(DW_FORM_data8);
writer.WriteULEB128(DW_FORM_data8);
}
else if (targetPointerSize == 4)
{
stream.WriteULEB128(DW_FORM_data4);
writer.WriteULEB128(DW_FORM_data4);
}
}

stream.Write([0, 0]);
writer.Write([0, 0]);
}

public static DwarfAbbrev CompileUnit = new([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ public void WriteInfoTable(
{
// Length
byte[] sizeBuffer = new byte[sizeof(uint)];
infoSectionWriter.Stream.AppendData(sizeBuffer);
infoSectionWriter.EmitData(sizeBuffer);
// Version
infoSectionWriter.Stream.WriteLittleEndian<ushort>((ushort)(_useDwarf5 ? 5u : 4u));
infoSectionWriter.WriteLittleEndian<ushort>((ushort)(_useDwarf5 ? 5u : 4u));
if (_useDwarf5)
{
// Unit type, Address Size
infoSectionWriter.Stream.Write([DW_UT_compile, _targetPointerSize]);
infoSectionWriter.Write([DW_UT_compile, _targetPointerSize]);
// Abbrev offset
infoSectionWriter.EmitSymbolReference(RelocType.IMAGE_REL_BASED_HIGHLOW, ".debug_abbrev", 0);
}
Expand All @@ -137,12 +137,12 @@ public void WriteInfoTable(
// Abbrev offset
infoSectionWriter.EmitSymbolReference(RelocType.IMAGE_REL_BASED_HIGHLOW, ".debug_abbrev", 0);
// Address Size
infoSectionWriter.Stream.Write([_targetPointerSize]);
infoSectionWriter.Write([_targetPointerSize]);
}

using (DwarfInfoWriter dwarfInfoWriter = new(
infoSectionWriter,
stringSectionWriter.Stream,
stringSectionWriter,
abbrevSectionWriter,
locSectionWriter,
rangeSectionWriter,
Expand Down Expand Up @@ -199,10 +199,10 @@ public void WriteInfoTable(
}

// End of compile unit
infoSectionWriter.Stream.Write([(byte)0]);
infoSectionWriter.WriteByte(0);

// Update the size
BinaryPrimitives.WriteUInt32LittleEndian(sizeBuffer, (uint)(infoSectionWriter.Stream.Length - sizeof(uint)));
BinaryPrimitives.WriteUInt32LittleEndian(sizeBuffer, (uint)(infoSectionWriter.Position - sizeof(uint)));
}

private void WriteLineInfoTable(SectionWriter lineSectionWriter)
Expand All @@ -225,28 +225,28 @@ private void WriteAddressRangeTable(SectionWriter arangeSectionWriter)
{
// Length
var sizeBuffer = new byte[sizeof(uint)];
arangeSectionWriter.Stream.AppendData(sizeBuffer);
arangeSectionWriter.EmitData(sizeBuffer);
// Version
arangeSectionWriter.Stream.WriteLittleEndian<ushort>(2);
arangeSectionWriter.WriteLittleEndian<ushort>(2);
// Debug Info Offset
arangeSectionWriter.EmitSymbolReference(RelocType.IMAGE_REL_BASED_HIGHLOW, ".debug_info", 0);
// Address size, Segment selector size
arangeSectionWriter.Stream.Write([_targetPointerSize, 0]);
arangeSectionWriter.Write([_targetPointerSize, 0]);
// Ranges have to be aligned
arangeSectionWriter.EmitAlignment(_targetPointerSize * 2);
foreach (var sectionInfo in _sections)
{
arangeSectionWriter.EmitSymbolReference(_codeRelocType, sectionInfo.SectionSymbolName, 0);
switch (_targetPointerSize)
{
case 8: arangeSectionWriter.Stream.WriteLittleEndian<ulong>(sectionInfo.Size); break;
case 4: arangeSectionWriter.Stream.WriteLittleEndian<uint>((uint)sectionInfo.Size); break;
case 8: arangeSectionWriter.WriteLittleEndian<ulong>(sectionInfo.Size); break;
case 4: arangeSectionWriter.WriteLittleEndian<uint>((uint)sectionInfo.Size); break;
default: throw new NotSupportedException();
}
}
arangeSectionWriter.Stream.Write(stackalloc byte[_targetPointerSize * 2]);
arangeSectionWriter.Write(stackalloc byte[_targetPointerSize * 2]);
// Update the size
BinaryPrimitives.WriteUInt32LittleEndian(sizeBuffer, (uint)(arangeSectionWriter.Stream.Length - sizeof(uint)));
BinaryPrimitives.WriteUInt32LittleEndian(sizeBuffer, (uint)(arangeSectionWriter.Position - sizeof(uint)));
}

public uint GetPrimitiveTypeIndex(TypeDesc type)
Expand Down
Loading