-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is reimplementation of NativeAOT ObjWriter in pure C# instead of depending on LLVM. It implements Mach-O, ELF, COFF object file emitter with DWARF and CodeView debugging information. Only x64 and arm64 targets are implemented to cover officially supported platforms (win-x86 code is present and lightly tested; linux-x86 code is present and incomplete, only serves as a test bed for emitting 32-bit ELF files if we ever need that). Original object writer code is still present and can be used by setting the `DOTNET_USE_LLVM_OBJWRITER=1` environment variable. **Thanks to @am11 for helping with testing and debugging this, @xoofx for making LibObjectFile which helped kickstart this project, @PaulusParssinen for tips about branchless U/SLEB128 size calculation, and all the people on the .NET team who helped push this forward!** Fixes #77178
- Loading branch information
1 parent
21b4a85
commit abffa8f
Showing
34 changed files
with
11,429 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ public enum SectionType | |
Writeable, | ||
Executable, | ||
Uninitialized, | ||
Debug, | ||
} | ||
|
||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
.../tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CodeView/CodeViewFileTableBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Buffers; | ||
using System.Buffers.Binary; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Text; | ||
|
||
using static ILCompiler.ObjectWriter.CodeViewNative; | ||
|
||
namespace ILCompiler.ObjectWriter | ||
{ | ||
internal sealed class CodeViewFileTableBuilder | ||
{ | ||
private readonly MemoryStream _stringTableWriter = new(); | ||
private readonly MemoryStream _fileTableWriter = new(); | ||
private readonly Dictionary<string, uint> _fileNameToIndex = new(); | ||
|
||
public CodeViewFileTableBuilder() | ||
{ | ||
// Insert empty entry at the beginning of string table | ||
_stringTableWriter.Write(stackalloc byte[2] { 0, 0 }); | ||
} | ||
|
||
public uint GetFileIndex(string fileName) | ||
{ | ||
if (fileName == "") | ||
{ | ||
// Match the placeholder value from LLVM. We need to use a non-empty | ||
// string to ensure that the null terminator of the UTF-8 representation | ||
// is not treated as the terminator of the whole file name table. | ||
fileName = "<stdin>"; | ||
} | ||
|
||
if (_fileNameToIndex.TryGetValue(fileName, out uint fileIndex)) | ||
{ | ||
return fileIndex; | ||
} | ||
else | ||
{ | ||
uint stringTableIndex = (uint)_stringTableWriter.Position; | ||
_stringTableWriter.Write(Encoding.UTF8.GetBytes(fileName)); | ||
_stringTableWriter.WriteByte(0); | ||
|
||
uint fileTableIndex = (uint)_fileTableWriter.Position; | ||
Span<byte> fileTableEntry = stackalloc byte[sizeof(uint) + sizeof(uint)]; | ||
BinaryPrimitives.WriteUInt32LittleEndian(fileTableEntry, stringTableIndex); | ||
BinaryPrimitives.WriteUInt32LittleEndian(fileTableEntry.Slice(4), 0); | ||
_fileTableWriter.Write(fileTableEntry); | ||
|
||
_fileNameToIndex.Add(fileName, fileTableIndex); | ||
|
||
return fileTableIndex; | ||
} | ||
} | ||
|
||
public void Write(SectionWriter sectionWriter) | ||
{ | ||
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)); | ||
} | ||
} | ||
} |
2,364 changes: 2,364 additions & 0 deletions
2,364
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CodeView/CodeViewNative.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.