-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[cdac] cdac-build-tool #100650
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
[cdac] cdac-build-tool #100650
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
8518e9f
checkpoint
lambdageek 12aef6d
add old tooling notes
lambdageek 1eff4d0
add an emitter
lambdageek 22e217b
checkpoint read in the directory header
lambdageek dd9279d
checkpoint plausible-looking offsets
lambdageek 492af29
checkpoint: field stuff is working
lambdageek 459d124
checkpoint json
lambdageek 28f8256
contract parsing
lambdageek 418739d
refactor
lambdageek 1c1524d
indirect pointer value support
lambdageek 34e852e
move sample to tool dir
lambdageek e48e709
Take baselines from the docs/design/datacontracts/data dir
lambdageek 0e8c60e
Add README
lambdageek cd4f0f0
fix BE
lambdageek b6b079e
hook up cdac-build-tool to the coreclr build; export DotNetRuntimeCon…
lambdageek a9b0d7f
try fix win-x86 build warning
lambdageek dbf0557
paths
lambdageek 74433f1
vebose
lambdageek ea441b6
fix typo; fixes win32
lambdageek 787b836
cleanup; add contracts.txt
lambdageek e015e83
add diagram to README
lambdageek 0354723
move implementation notes
lambdageek da038f3
better verbose output from ObjectFileScraper
lambdageek f64b548
turn off whole program optimizations for data-descriptor.obj
lambdageek 2e29a10
C++-ify and add real Thread offsets
lambdageek 58162a3
no C99 designated initializers in C++ until C++20
lambdageek 4bb51bf
build data descriptor after core runtime
lambdageek 9700e29
fix gcc build
lambdageek 3f22c7c
fix typo
lambdageek 4aae511
simplify ObjectFileScraper
lambdageek 60738ef
more dependencies
lambdageek c0dab90
try fix source build
lambdageek 84eaa3b
remove fixme; document
lambdageek 86e5258
Merge commit 'origin/main^' into cdac-contract-tool
lambdageek cc658c9
invoke 'dotnet cmake-build-tool.dll' instead of 'dotnet run --project'
lambdageek 39fe70d
clean up macro boilerplate
lambdageek 5064deb
platform flags
lambdageek 74000bc
turn off verbose output
lambdageek 76c27bc
can't use constexpr function in coreclr
lambdageek 270fe21
Code review fixups
lambdageek 84e0800
Rename "aux data" to "pointer data"
lambdageek 51da4e3
rename "data-descriptor" to "datadescriptor"
lambdageek b26f3ac
simplify linking
lambdageek 8f9d1a7
cdac-build-tool don't build dotnet tool; turn on analyzers
lambdageek 87b79b3
update README
lambdageek b33ad07
rationalize naming; update docs; add some inline comments
lambdageek c39e6f4
rm whitespace
lambdageek 5ef8428
renamce cdac.h to cdacoffsets.h
lambdageek 9f381be
comments
lambdageek 443f83b
fixup README
lambdageek 9fc2b26
hex offsets; improved formatting
lambdageek 024c566
don't throw in ParseContracts; add line numbers to errors
lambdageek b0f1f40
spelling
lambdageek 2852d8d
Update README.md
lambdageek 2429bd8
change input format for contracts to jsonc
lambdageek 18a863e
add custom JsonConverter instances for the compact json representation
lambdageek a49e5e6
code review changes
lambdageek 1f5ba44
inline comments into the data-descriptor-blob C code
lambdageek 2decea4
cleanup
lambdageek ce18bee
comments and markdown
lambdageek e143998
Apply suggestions from code review
lambdageek 08cf75d
simplify; bug fix - PointerDataCount include placeholder
lambdageek 0d4d40d
fixup docs
lambdageek 94c56ea
Merge remote-tracking branch 'origin/main' into cdac-contract-tool
lambdageek 3d49b70
Update src/coreclr/tools/cdac-build-tool/JsonConverter/GlobalModelJso…
lambdageek f845c41
one more set of feedback changes
lambdageek 64430cf
maybe no live ILLink ?
lambdageek 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
Next
Next commit
checkpoint
- Loading branch information
commit 8518e9fbd8dfce811b838ba459c0155fd9c75413
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// 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.Binary; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.DotNet.Diagnostics.DataContract.BuildTool; | ||
|
||
public class ObjectFileScraper | ||
{ | ||
public readonly ReadOnlyMemory<byte> MagicLE = new byte[4]{0x01, 0x02, 0x03, 0x4}; | ||
public readonly ReadOnlyMemory<byte> MagicBE = new byte[4]{0x04, 0x03, 0x02, 0x1}; | ||
|
||
public bool Verbose {get;} | ||
public ObjectFileScraper(bool verbose) { | ||
Verbose = verbose; | ||
} | ||
|
||
public async Task<bool> ScrapeInput(string inputPath, CancellationToken token) | ||
{ | ||
using var file = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
var r = await FindMagic(file, token); | ||
|
||
if (!r.Found){ | ||
return false; | ||
} | ||
if (Verbose) { | ||
Console.WriteLine ($"{inputPath}: magic at {r.Position}"); | ||
} | ||
file.Seek(r.Position, SeekOrigin.Begin); | ||
var header = ReadHeader(file, r.LittleEndian); | ||
if (Verbose) { | ||
Console.WriteLine ($"{inputPath}: {header}"); | ||
} | ||
return true; | ||
} | ||
|
||
struct MagicResult { | ||
public bool Found {get; init;} | ||
public long Position {get; init;} | ||
public bool LittleEndian {get; init;} | ||
} | ||
|
||
private async Task<MagicResult> FindMagic(Stream stream, CancellationToken token) | ||
{ | ||
var buf = new byte[4096]; | ||
long pos = stream.Position; | ||
while (true) { | ||
token.ThrowIfCancellationRequested(); | ||
int bytesRead = await stream.ReadAsync(buf, 0, buf.Length, token); | ||
if (bytesRead == 0) | ||
return new (){Found = false, Position = 0, LittleEndian = true}; | ||
// FIXME: what if magic spans a buffer boundary | ||
if (FindMagic(buf, out int offset, out bool isLittleEndian)) { | ||
pos += (long)offset; | ||
return new (){Found = true, Position = pos, LittleEndian = isLittleEndian}; | ||
} | ||
pos += bytesRead; | ||
} | ||
} | ||
|
||
private bool FindMagic(ReadOnlySpan<byte> buffer, out int offset, out bool isLittleEndian) | ||
{ | ||
int start = buffer.IndexOf(MagicLE.Span); | ||
if (start != -1) | ||
{ | ||
offset = start; | ||
isLittleEndian = true; | ||
return true; | ||
} | ||
start = buffer.IndexOf(MagicBE.Span); | ||
if (start != -1) | ||
{ | ||
offset = start; | ||
isLittleEndian = false; | ||
return true; | ||
} | ||
offset = 0; | ||
isLittleEndian = false; | ||
return false; | ||
} | ||
|
||
private string ReadHeader(Stream stream, bool isLittleEndian) | ||
{ | ||
return "TODO: read a header"; | ||
} | ||
|
||
} |
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,76 @@ | ||
// 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.Binary; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.CommandLine.Help; | ||
using System.CommandLine.Parsing; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Metadata; | ||
using System.Reflection.Metadata.Ecma335; | ||
using System.Reflection.PortableExecutable; | ||
using System.Runtime.Serialization.Json; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Encodings.Web; | ||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
lambdageek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
namespace Microsoft.DotNet.Diagnostics.DataContract.BuildTool; | ||
|
||
public class Program | ||
{ | ||
internal class ComposeCommand : CliCommand | ||
{ | ||
private readonly CliArgument<string[]> inputFiles = new ("INPUT [INPUTS...]") { Arity = ArgumentArity.OneOrMore, Description="One or more input files" }; | ||
private readonly CliOption<string> outputFile = new ("-o") { Arity = ArgumentArity.ExactlyOne, HelpName="OUTPUT", Required = true, Description = "Output file" }; | ||
private readonly CliOption<bool> _verboseOption; | ||
public ComposeCommand (CliOption<bool> verboseOption) : base("compose") | ||
{ | ||
_verboseOption = verboseOption; | ||
Add(inputFiles); | ||
Add(outputFile); | ||
SetAction(Run); | ||
} | ||
|
||
|
||
private async Task<int> Run(ParseResult parse, CancellationToken token = default) | ||
{ | ||
var inputs = parse.GetValue(inputFiles); | ||
var output = parse.GetValue(outputFile); | ||
var verbose = parse.GetValue(_verboseOption); | ||
var scraper = new ObjectFileScraper(verbose); | ||
foreach (var input in inputs) { | ||
token.ThrowIfCancellationRequested(); | ||
if (!await scraper.ScrapeInput(input, token)) { | ||
Console.Error.WriteLine ($"could not scrape payload in {input}"); | ||
return 1; | ||
} | ||
} | ||
//var model = await scraper.BuildModel(token); | ||
//using var modelWriter = new ModelWriter(output); | ||
//await modelWriter.Write(model, token); | ||
return 0; | ||
} | ||
} | ||
|
||
public static async Task<int> Main(string[] args) | ||
{ | ||
CliRootCommand rootCommand = new (); | ||
var verboseOption = new CliOption<bool>("-v", "--verbose") {Recursive = true, Description = "Verbose"}; | ||
rootCommand.Add(verboseOption); | ||
rootCommand.Add(new DiagramDirective()); | ||
rootCommand.Add(new ComposeCommand(verboseOption)); | ||
return await rootCommand.Parse(args).InvokeAsync(); | ||
} | ||
} |
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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>cdac-build-tool</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<OutputPath>$(RuntimeBinDir)/cdac-build-tool</OutputPath> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems> | ||
<IsPackable>true</IsPackable> | ||
<PackAsTool>true</PackAsTool> | ||
<ToolCommandName>cdac-build-tool</ToolCommandName> | ||
<PackagedShimOutputRootDirectory>$(OutputPath)</PackagedShimOutputRootDirectory> | ||
lambdageek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<IsShipping>false</IsShipping> <!-- This tool is an implementatino detail of the build process, it does not ship --> | ||
<Description>.NET runtime data contract build tool</Description> | ||
<PackageTags>Diagnostics</PackageTags> | ||
<PackageReleaseNotes>$(Description)</PackageReleaseNotes> | ||
<RootNamespace>Microsoft.DotNet.Diagnostics.DataContract</RootNamespace> | ||
<RollForward>Major</RollForward> | ||
<RunAnalyzers>false</RunAnalyzers> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" /> | ||
</ItemGroup> | ||
</Project> |
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.