Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/coreclr/tools/Common/Compiler/NameMangler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public NameMangler(NodeMangler nodeMangler)

public abstract string CompilationUnitPrefix { get; set; }

public abstract string SanitizeName(string s, bool typeName = false);
public abstract Utf8String SanitizeName(Utf8String s);

public abstract string GetMangledTypeName(TypeDesc type);
public abstract Utf8String GetMangledTypeName(TypeDesc type);

public abstract Utf8String GetMangledMethodName(MethodDesc method);

Expand Down
301 changes: 201 additions & 100 deletions src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/coreclr/tools/Common/Compiler/ObjectWriter/SectionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Numerics;
using System.Text;
using ILCompiler.DependencyAnalysis;
using Internal.Text;

namespace ILCompiler.ObjectWriter
{
Expand Down Expand Up @@ -115,6 +116,16 @@ public readonly void WriteLittleEndian<T>(T value)
bufferWriter.Advance(value.WriteLittleEndian(buffer));
}

public readonly void WriteUtf8String(Utf8String value)
{
IBufferWriter<byte> bufferWriter = _sectionData.BufferWriter;
int size = value.Length + 1;
Span<byte> buffer = bufferWriter.GetSpan(size);
value.AsSpan().CopyTo(buffer);
buffer[size - 1] = 0;
bufferWriter.Advance(size);
}

public readonly void WriteUtf8String(string value)
{
IBufferWriter<byte> bufferWriter = _sectionData.BufferWriter;
Expand Down
18 changes: 18 additions & 0 deletions src/coreclr/tools/Common/Internal/Text/Utf8String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,23 @@ public int CompareTo(Utf8String other)
{
return Compare(this, other);
}

public static Utf8String Concat(params ReadOnlySpan<Utf8String> strings)
{
int length = 0;
foreach (Utf8String s in strings)
length += s.Length;

var result = new byte[length];
Span<byte> resultSpan = result;

foreach (Utf8String s in strings)
{
s.AsSpan().CopyTo(resultSpan);
resultSpan = resultSpan.Slice(s.Length);
}

return new Utf8String(result);
}
}
}
5 changes: 5 additions & 0 deletions src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public Utf8StringBuilder()
{
}

public Utf8StringBuilder(int capacity)
{
_buffer = new byte[capacity];
}

public int Length => _length;

public ReadOnlySpan<byte> AsSpan() => _buffer.AsSpan(0, _length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using Internal.Text;

namespace Internal.TypeSystem.TypesDebugInfo
{
Expand All @@ -24,7 +25,7 @@ uint GetCompleteClassTypeIndex(ClassTypeDescriptor classTypeDescriptor, ClassFie

uint GetPrimitiveTypeIndex(TypeDesc type);

string GetMangledName(TypeDesc type);
Utf8String GetMangledName(TypeDesc type);
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -39,14 +40,14 @@ public struct EnumTypeDescriptor
{
public uint ElementType;
public ulong ElementCount;
public string Name;
public Utf8String Name;
}

[StructLayout(LayoutKind.Sequential)]
public struct ClassTypeDescriptor
{
public int IsStruct;
public string Name;
public Utf8String Name;
public uint BaseClassId;
public ulong InstanceSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using ILCompiler.DependencyAnalysis;
using Internal.JitInterface;
using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.TypesDebugInfo;

Expand Down Expand Up @@ -275,7 +276,7 @@ public void EmitLineInfo(
}
}

public void WriteUserDefinedTypes(IList<(string, uint)> userDefinedTypes)
public void WriteUserDefinedTypes(IList<(Utf8String, uint)> userDefinedTypes)
{
using var symbolSubsection = GetSubsection(DebugSymbolsSubsectionType.Symbols);
foreach (var (name, typeIndex) in userDefinedTypes)
Expand Down Expand Up @@ -399,6 +400,13 @@ public void Write(ulong value)
_bufferWriter.Advance(sizeof(ulong));
}

public void Write(Utf8String value)
{
int byteCount = value.Length + 1;
value.AsSpan().CopyTo(_bufferWriter.GetSpan(byteCount));
_bufferWriter.Advance(byteCount);
}

public void Write(string value)
{
int byteCount = Encoding.UTF8.GetByteCount(value) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using ILCompiler.DependencyAnalysis;
using Internal.JitInterface;
using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.TypesDebugInfo;

Expand Down Expand Up @@ -44,11 +45,11 @@ internal sealed class CodeViewTypesBuilder : ITypesDebugInfoWriter

private readonly uint _classVTableTypeIndex;
private readonly uint _vfuncTabTypeIndex;
private readonly List<(string, uint)> _userDefinedTypes = new();
private readonly List<(Utf8String, uint)> _userDefinedTypes = new();

private uint _nextTypeIndex = 0x1000;

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

public CodeViewTypesBuilder(NameMangler nameMangler, int targetPointerSize, SectionWriter sectionWriter)
{
Expand Down Expand Up @@ -382,7 +383,7 @@ public uint GetMemberFunctionId(MemberFunctionIdTypeDescriptor memberIdDescripto
return _nextTypeIndex++;
}

public string GetMangledName(TypeDesc type)
public Utf8String GetMangledName(TypeDesc type)
{
return _nameMangler.GetMangledTypeName(type);
}
Expand Down Expand Up @@ -444,6 +445,13 @@ public void Write(ulong value)
_bufferWriter.Advance(sizeof(ulong));
}

public void Write(Utf8String value)
{
int byteCount = value.Length + 1;
value.AsSpan().CopyTo(_bufferWriter.GetSpan(byteCount));
_bufferWriter.Advance(byteCount);
}

public void Write(string value)
{
int byteCount = Encoding.UTF8.GetByteCount(value) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using ILCompiler.DependencyAnalysis;
using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.TypesDebugInfo;
using static ILCompiler.ObjectWriter.DwarfNative;
Expand Down Expand Up @@ -422,7 +423,7 @@ public uint GetMemberFunctionId(MemberFunctionIdTypeDescriptor memberIdDescripto
return (uint)_memberFunctions.Count;
}

public string GetMangledName(TypeDesc type)
public Utf8String GetMangledName(TypeDesc type)
{
return _nameMangler.GetMangledTypeName(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using ILCompiler.DependencyAnalysis;
using Internal.Text;
using Internal.TypeSystem;

namespace ILCompiler.ObjectWriter
Expand Down Expand Up @@ -95,6 +96,15 @@ public void WriteAddressSize(ulong value)
}
}

public void WriteStringReference(Utf8String value)
{
long stringsOffset = _stringTableWriter.Position;
_stringTableWriter.WriteUtf8String(value);

Debug.Assert(stringsOffset < uint.MaxValue);
_infoSectionWriter.EmitSymbolReference(RelocType.IMAGE_REL_BASED_HIGHLOW, ".debug_str", stringsOffset);
}

public void WriteStringReference(string value)
{
long stringsOffset = _stringTableWriter.Position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ public sealed override string MangledBoxedTypeName(TypeDesc type)

public sealed override string MethodTable(TypeDesc type)
{
string mangledJustTypeName;

if (type.IsValueType)
mangledJustTypeName = MangledBoxedTypeName(type);
else
mangledJustTypeName = NameMangler.GetMangledTypeName(type);
string mangledJustTypeName = type.IsValueType
? MangledBoxedTypeName(type)
: NameMangler.GetMangledTypeName(type).ToString();

return "_ZTV" + mangledJustTypeName.Length.ToString(CultureInfo.InvariantCulture) + mangledJustTypeName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ public sealed override string MangledBoxedTypeName(TypeDesc type)

public sealed override string MethodTable(TypeDesc type)
{
string mangledJustTypeName;

if (type.IsValueType)
mangledJustTypeName = MangledBoxedTypeName(type);
else
mangledJustTypeName = NameMangler.GetMangledTypeName(type);
string mangledJustTypeName = type.IsValueType
? MangledBoxedTypeName(type)
: NameMangler.GetMangledTypeName(type).ToString();

// "??_7TypeName@@6B@" is the C++ mangling for "const TypeName::`vftable'"
// This, along with LF_VTSHAPE debug records added by the object writer
Expand Down
Loading