Skip to content

Commit

Permalink
Dogfood ComInterfaceGenerator in crossgen2 (#84643)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtschuster authored May 23, 2023
1 parent b87a698 commit b591193
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 209 deletions.
3 changes: 3 additions & 0 deletions src/coreclr/tools/aot/ILCompiler.Diagnostics/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

[assembly: DisableRuntimeMarshalling]

namespace ILCompiler.Diagnostics
{
Expand Down

This file was deleted.

27 changes: 9 additions & 18 deletions src/coreclr/tools/aot/ILCompiler.Diagnostics/ISymNGenWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Security;
using System.Text;

Expand Down Expand Up @@ -38,10 +39,10 @@ namespace Microsoft.DiaSymReader
/// };
/// </code>
/// </remarks>
internal interface ISymNGenWriter
[GeneratedComInterface]
[Guid("D682FD12-43dE-411C-811B-BE8404CEA126")]
internal partial interface ISymNGenWriter
{
public static readonly Guid IID = new Guid("D682FD12-43dE-411C-811B-BE8404CEA126");

// Add a new public symbol to the NGEN PDB.
void AddSymbol([MarshalAs(UnmanagedType.BStr)] string pSymbol,
ushort iSection,
Expand Down Expand Up @@ -110,21 +111,10 @@ internal enum OMF : ushort
/// };
/// </remarks>
/// </code>
internal interface ISymNGenWriter2 : ISymNGenWriter
[GeneratedComInterface]
[Guid("B029E51B-4C55-4fe2-B993-9F7BC1F10DB4")]
internal partial interface ISymNGenWriter2 : ISymNGenWriter
{
public readonly static new Guid IID = new Guid("B029E51B-4C55-4fe2-B993-9F7BC1F10DB4");

// Add a new public symbol to the NGEN PDB.
new void AddSymbol([MarshalAs(UnmanagedType.BStr)] string pSymbol,
ushort iSection,
ulong rva);

// Adds a new section to the NGEN PDB.
new void AddSection(ushort iSection,
OMF flags,
int offset,
int cb);

void OpenModW([MarshalAs(UnmanagedType.LPWStr)] string wszModule,
[MarshalAs(UnmanagedType.LPWStr)] string wszObjFile,
out UIntPtr ppmod);
Expand All @@ -143,7 +133,8 @@ void ModAddSecContribEx(
uint dwRelocCrc);

void QueryPDBNameExW(
[MarshalAs(UnmanagedType.LPWStr)] char[] pdb,
[MarshalUsing(CountElementName = nameof(cchMax))]
char[] pdb,
IntPtr cchMax);
}
}
18 changes: 9 additions & 9 deletions src/coreclr/tools/aot/ILCompiler.Diagnostics/PdbWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reflection;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;

using Internal.TypeSystem;
Expand Down Expand Up @@ -73,7 +74,7 @@ public bool Equals(SymDocument other)
}
}

public class PdbWriter
public partial class PdbWriter
{
private const string DiaSymReaderLibrary = "Microsoft.DiaSymReader.Native";

Expand All @@ -89,7 +90,7 @@ public class PdbWriter
Dictionary<SymDocument,int> _documentToChecksumOffsetMapping;

UIntPtr _pdbMod;
SymNgenWriterWrapper _ngenWriter;
ISymNGenWriter2 _ngenWriter;

static PdbWriter()
{
Expand All @@ -112,10 +113,10 @@ private static IntPtr DllImportResolver(string libraryName, Assembly assembly, D
}

[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.SafeDirectories)]
[DllImport(DiaSymReaderLibrary, PreserveSig = false)]
private extern static void CreateNGenPdbWriter(
[MarshalAs(UnmanagedType.LPWStr)] string ngenImagePath,
[MarshalAs(UnmanagedType.LPWStr)] string pdbPath,
[LibraryImport(DiaSymReaderLibrary, StringMarshalling = StringMarshalling.Utf16)]
private static partial void CreateNGenPdbWriter(
string ngenImagePath,
string pdbPath,
out IntPtr ngenPdbWriterPtr);

public PdbWriter(string pdbPath, PDBExtraData pdbExtraData, TargetDetails target)
Expand Down Expand Up @@ -145,7 +146,6 @@ public void WritePDBData(string dllPath, IEnumerable<MethodInfo> methods)
if ((_ngenWriter != null) && (_pdbMod != UIntPtr.Zero))
{
_ngenWriter.CloseMod(_pdbMod);
_ngenWriter?.Dispose();
}
}

Expand Down Expand Up @@ -208,9 +208,9 @@ private void WritePDBDataHelper(string dllPath, IEnumerable<MethodInfo> methods)
// Delete any preexisting PDB file upfront, otherwise CreateNGenPdbWriter silently opens it
File.Delete(_pdbFilePath);

var comWrapper = new ILCompilerComWrappers();
var comWrapper = new StrategyBasedComWrappers();
CreateNGenPdbWriter(dllPath, _pdbFilePath, out var pdbWriterInst);
_ngenWriter = (SymNgenWriterWrapper)comWrapper.GetOrCreateObjectForComInstance(pdbWriterInst, CreateObjectFlags.UniqueInstance);
_ngenWriter = (ISymNGenWriter2)comWrapper.GetOrCreateObjectForComInstance(pdbWriterInst, CreateObjectFlags.UniqueInstance);

{
// PDB file is now created. Get its path and update _pdbFilePath so the PDB file
Expand Down
150 changes: 0 additions & 150 deletions src/coreclr/tools/aot/ILCompiler.Diagnostics/SymNgenWriterWrapper.cs

This file was deleted.

0 comments on commit b591193

Please sign in to comment.