-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ObjWriter in C# #95876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ObjWriter in C# #95876
Changes from all commits
Commits
Show all changes
144 commits
Select commit
Hold shift + click to select a range
6f62905
Move ObjectWriter and ObjectWritingOptions into its own namespace
filipnavara b3a2198
Add external sources for Melanzana.MachO and LibObjectFile
filipnavara 55094c9
Disable versioning NuGets in external projects (MinVer, Nerdbank.GitV…
filipnavara ee4bf61
Add first draft of MachO and ELF object writers
filipnavara a9ead97
Generate relocatable DWARF info in ELF, fix X64 register mapping
filipnavara 1ba7e46
Fix writing base address with relocations
filipnavara f160dc8
Emit information about static variables, minor DWARF fixes
filipnavara 490495d
Fix generated section layout in symbol table for Mach-O after EmitSym…
filipnavara 685fcb8
Add support for ARM64 ELF
filipnavara ff0d382
Add ObjectWriter class and derive UnixObjectWriter from it
filipnavara fc31d42
Add initial take on CoffObjectWriter
filipnavara bd13d55
Emit control flow guard information
filipnavara d19459a
Add win-arm64 support
filipnavara efd0c57
Misc cleanups of the COFF object writer
filipnavara 14a4755
Remove GetSection
filipnavara ef5ffb4
Add COFF COMDAT support
filipnavara 19501ca
Add support for writing extended COFF object files (> 65279 sections)
filipnavara 88e1002
Wrap some logic in SectionWriter struct; clean up code
filipnavara 6d2d4bd
Emit GNU-stack note in ELF
filipnavara cdce467
Propagate DWARF5 option
filipnavara f900b0d
Initial take on CodeView type section builder
filipnavara 1f2473b
Move SectionWriter out of ObjectWriter so it can be used by other bui…
filipnavara 00d86ff
Switch DwarfEhFrame to use UnixObjectWriter
filipnavara b770f78
WIP: CodeView debugging information
filipnavara 65d59f0
WIP: CodeView line mapping
filipnavara bc8b8d5
WIP: CodeView restructuring
filipnavara 22ae5a6
CodeView cleanup
filipnavara cd56a6c
CodeView: Handle continuation records in lists
filipnavara 81210d1
Add comments and asserts
filipnavara 249407c
Emit CodeView symbols correctly when COMDAT is used
filipnavara 904bec4
Minor cleanup in CodeView, add ARM64 register mapping
filipnavara d72a472
Optimize memory usage when writing section content
filipnavara 0aca151
CodeView: Fix emitting size of big structures
filipnavara f5a9081
Fix too aggressive zeroing of buffer
filipnavara 87afd74
Make sure not to dereference null returned from _debugInfo.GetLocalVa…
filipnavara f1ad210
HACK: Do not emit debug information where LLVM ObjWriter would not.
filipnavara fbc6f3e
Avoid some unnecessary name mangling calls
filipnavara 2ca35a6
Cache mangled names
filipnavara c5d0547
Fix ArgumentOutOfRangeException when writing DWARF debug info
filipnavara 670a14a
Fix build after rebase
filipnavara bdc441f
Add support for SectionType.Uninitialized
filipnavara f7aa827
Add support for iOS-like platforms
filipnavara 2bef42c
Invoke object dumper from shared ObjectWriter
filipnavara 3579987
macOS/iOS: Emit simple compact unwinding information
filipnavara 4567163
Add support for new TLS relocations in ELF
filipnavara 8a6774c
Generate debug info even if managed debug info not present
filipnavara a9cc9b4
Fix counting the DwarfLineProgramTable layout (backport of https://gi…
filipnavara 7eb39c1
Remove incorrect assert in MachObjectWriter (text section starts at v…
filipnavara a96157d
Temporarily disable optimization that results in incorrect LSDA point…
filipnavara 0e855a1
Fix emitting unwind tables in Mach-O
filipnavara aee297e
Emit the MH_SUBSECTIONS_VIA_SYMBOLS header flag for Mach-O
filipnavara f728fb5
Fix seeking in ObjectWriterStream
filipnavara d7ef771
Avoid excessive seeks by implementing SliceStream.CopyTo
filipnavara 4b84616
Use ObjectWriterStream in ElfObjectWriter
filipnavara a8a12b9
Use ObjectWriterStream for Mach-O
filipnavara 18a39ab
Fix setting the UNWIND_HAS_LSDA flag in compact unwind table
filipnavara 64dc26c
COFF:
filipnavara 66d35bd
COFF: Fix off-by-one error when writing more than 0xffff relocations …
filipnavara e333caa
Make ObjectWriterStream the only supported stream and fix padding emi…
filipnavara 5645f9a
Fix scope overlapping in NAOT DWARF info (backport of https://github.…
filipnavara 4025c09
ELF: Use the address of __managedcode in DWARF info (backport of http…
filipnavara 6e0f1b6
ELF: Fix emitting global symbols
filipnavara 9dc6b63
ELF: Fix TLS support on linux-x64 Release builds
filipnavara 1d76838
Return sorted set from GetUndefinedSymbols to avoid extra sorting
filipnavara a1922c5
COFF: Fix generating COMDAT section references in big-obj files
filipnavara 3e9fcc7
Generate Mach-O for iOS-like platforms, not ELF
filipnavara 9e95e9b
Fix EH frames on linux-arm64
filipnavara 9a50db5
COFF: Support addend for IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A relocation
filipnavara 6c28f5a
COFF: Emit alignment for .pdata section
filipnavara b357425
Fix padding emitted in ObjectWriterStream.AppendPadding
filipnavara febce5a
Fix ObjectWriterStream.Position setter (again)
filipnavara 93e84cb
COFF: Emit .pdata/.xdata as associative COMDAT sections/symbols
filipnavara 0a61577
ELF/LibObjectFile experiment: Add support for building optimized stri…
filipnavara bfb6db4
LibObjectFile: Add support for >= 0xff00 sections
filipnavara 6f0d770
ELF: Add basic COMDAT support, don't emit empty relocation sections
filipnavara 62c478e
ELF: Emit correct addresses and relocations in debug info, references…
filipnavara 14f5d17
Add missing StringComparer.Ordinal to dictionaries
filipnavara ec7bc5e
Remove incorrect assert
filipnavara 307ca09
WIP: Rewritten DWARF debug info emitter
filipnavara e8a19ff
Fix state change in ObjectWriterStream triggering an Assert
filipnavara fedcab7
WIP: Mach-O/DWARF
filipnavara 5cda00a
DWARF Mach-O relocations done right
filipnavara 5d54858
Do not output debug information for static variables that were trimmed
filipnavara cd4a543
WIP: Cleanup
filipnavara cbd7f83
Rework how symbol tables are generated, and how DWARF relocations are…
filipnavara 8530c75
Revert accidental change
filipnavara 0575b0f
Update LibObjectFile to version 0.5.0.
filipnavara 157dbdc
Fix ELF section symbols and DW_AT_low_pc in DWARF debug info
filipnavara d7f4e2d
Disable MinVer package in LibObjectFile
filipnavara 941e0a3
ELF: Generate symbol table section index if there's more than 0xff00 …
filipnavara a00cd12
Revert "Do not output debug information for static variables that wer…
filipnavara ea9360f
Fix typo
filipnavara 81ac747
Fix null dereference in CoffObjectWriter.CreateSection
filipnavara f1a1bfa
COFF: Add X86 support (tested on SmolSharp.HelloWorld)
filipnavara 07dd8a6
Fix COMDAT symbol values
filipnavara d89308d
Do not generate broken debug info for non-methods
filipnavara 43d8e3d
Add generic StringTableBuilder and use it in COFF
filipnavara d92d31a
Fix couple of bugs in last commit:
filipnavara 6ff8ae9
COFF: Add support for '//BBBBBB' section names.
filipnavara 018f727
Add simple ELF writer
filipnavara e7cda50
Port from main: Fix generating debug info for static fields
filipnavara a1a9050
Add (untested) x86 support to ElfObjectWriter
filipnavara 75d34e5
Cleanup
filipnavara aa6e94e
Move Dwarf/CodeView files into their respective directories
filipnavara 0048be7
Make bulk of the ObjectWriter classes internal, improve logging
filipnavara 5c5d6a1
Use IBinaryInteger for WriteLittleEndian helper method
filipnavara 288eedd
Add simple Mach-O object file writer that doesn't use Melanzana.MachO
filipnavara f17b308
Rename LlvmObjectWriter to LegacyObjectWriter to prevent conflict wit…
filipnavara 004b5c5
Mach-O: Swap the order of symbol table and string table to make strip…
filipnavara e5d6e72
Fix the CPU type/subtype
filipnavara d38b91a
Fix Release build
filipnavara 57133a9
Eliminate relocations for known symbols within the same section
filipnavara 93f0650
Fix IMAGE_REL_BASED_ARM64_BRANCH26
filipnavara a4312a1
Attempt to fix CI errors
filipnavara 130cfe1
Fix incorrect addends in COFF
filipnavara 53c9f00
Fix ELF rela section flags; omit frame symbols for ELF
filipnavara 96635da
Split the writing and reading part of section data
filipnavara 17c3001
Cleanup
filipnavara 6dde29b
Pattern matching consistency
filipnavara bee3113
Comments, more cleanup
filipnavara 2f7bda3
Refactor ULEB128 writing in CfiCodeToInstructions
filipnavara df31fc6
Make JamCrc32 table a read-only span with collection initializer
filipnavara dd168d1
IsOSXLike -> IsApplePlatform
filipnavara cdb7b63
Follow up on 'using static' for relocations and *Native
filipnavara deb4df2
Use Relocation.ReadValue/WriteValue instead of manual implementation …
filipnavara 9c24e71
Fix handling of IMAGE_REL_BASED_RELPTR32 in the last commit
filipnavara 2c92fd5
Add missing enum values in Relocation.WriteValue
filipnavara 4cce374
Apply readonly on class members where appropriate
filipnavara 1c10dce
Zero-initialize stackalloc
filipnavara af416b8
Add comments; few missed readonly members
filipnavara 8e5ed26
Use 'static readonly' for reminder of ObjectNodeSection members
filipnavara 2f3df76
Pass target pointer size to CodeViewTypesBuilder instead of target ar…
filipnavara e970927
Set attribute values in CodeViewTypesBuilder
filipnavara 666d654
Use upper case hex constants for consistency
filipnavara a64485e
Move AbbreviationCode out of DwarfAbbrev
filipnavara c07a3d7
More readonly treatment
filipnavara a1ad976
Update comment
filipnavara eb143fd
Consistently throw exception for unsupported architectures
filipnavara a182ea7
Use the WriteLittleEndian helper method where appropriate
filipnavara 939fa83
Refactor how DwarfFde/DwarfCie are constructed and make them readonly…
filipnavara 47e8094
Add WritePadding method and use it instead of Write(stackalloc byte[.…
filipnavara 96a9e7c
Fix DWARF EH frame building
filipnavara 1fa5074
Revert accidental change
filipnavara e716e3d
Add code paths for ARM32 to ELF object writer
filipnavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.