Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into release/stable
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyosjs committed Jun 21, 2024
2 parents 8042ac9 + 464e06c commit d98406f
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 86 deletions.
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
<Uri>https://github.com/dotnet/installer</Uri>
<Sha>fa261b952d702c6bd604728fcbdb58ac071a22b1</Sha>
</Dependency>
<Dependency Name="Microsoft.AspNetCore.App.Ref.Internal" Version="9.0.0-preview.6.24315.1">
<Dependency Name="Microsoft.AspNetCore.App.Ref.Internal" Version="9.0.0-preview.6.24320.2">
<Uri>https://github.com/dotnet/aspnetcore</Uri>
<Sha>c283d05ce0e49941c7df3eeea6143ca58e2d0b3b</Sha>
<Sha>cd92ed12476de4e03ae5293d81362f2eb07b4f80</Sha>
</Dependency>
<Dependency Name="Microsoft.AspNetCore.App.Ref" Version="9.0.0-preview.6.24315.1">
<Dependency Name="Microsoft.AspNetCore.App.Ref" Version="9.0.0-preview.6.24320.2">
<Uri>https://github.com/dotnet/aspnetcore</Uri>
<Sha>c283d05ce0e49941c7df3eeea6143ca58e2d0b3b</Sha>
<Sha>cd92ed12476de4e03ae5293d81362f2eb07b4f80</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Runtime.win-x64" Version="9.0.0-preview.6.24307.2">
<Uri>https://github.com/dotnet/runtime</Uri>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<VSRedistCommonNetCoreSharedFrameworkx6490Version>9.0.0-preview.6.24307.2</VSRedistCommonNetCoreSharedFrameworkx6490Version>
<MicrosoftNETCoreAppRuntimewinx64Version>9.0.0-preview.6.24307.2</MicrosoftNETCoreAppRuntimewinx64Version>
<!-- Latest shared aspnetcore version updated by darc -->
<MicrosoftAspNetCoreAppRefInternalVersion>9.0.0-preview.6.24315.1</MicrosoftAspNetCoreAppRefInternalVersion>
<MicrosoftAspNetCoreAppRefVersion>9.0.0-preview.6.24315.1</MicrosoftAspNetCoreAppRefVersion>
<MicrosoftAspNetCoreAppRefInternalVersion>9.0.0-preview.6.24320.2</MicrosoftAspNetCoreAppRefInternalVersion>
<MicrosoftAspNetCoreAppRefVersion>9.0.0-preview.6.24320.2</MicrosoftAspNetCoreAppRefVersion>
<!-- dotnet/installer: Testing version of the SDK. Needed for the signed & entitled host. -->
<MicrosoftDotnetSdkInternalVersion>9.0.100-preview.5.24253.16</MicrosoftDotnetSdkInternalVersion>
</PropertyGroup>
Expand Down
8 changes: 8 additions & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@ if (CLR_CMAKE_HOST_UNIX)
add_compile_options(-Wimplicit-fallthrough)
endif()

# VLAs are non standard in C++, aren't available on Windows and
# are a warning by default since clang 18.
# For consistency, enable warnings for all compiler versions.
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wvla>)

#These seem to indicate real issues
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)

Expand Down Expand Up @@ -591,6 +596,9 @@ if (CLR_CMAKE_HOST_UNIX)
# other clang 16.0 suppressions
add_compile_options(-Wno-single-bit-bitfield-constant-conversion)
add_compile_options(-Wno-cast-function-type-strict)

# clang 18.1 supressions
add_compile_options(-Wno-switch-default)
else()
add_compile_options(-Wno-uninitialized)
add_compile_options(-Wno-strict-aliasing)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);CA1852</NoWarn>
<IsPackable>true</IsPackable>
<IsShipping>false</IsShipping>
Expand Down
180 changes: 105 additions & 75 deletions src/Microsoft.SymbolManifestGenerator/SymbolManifestGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,110 +10,140 @@
using Microsoft.SymbolStore;
using Microsoft.SymbolStore.KeyGenerators;

namespace Microsoft.SymbolManifestGenerator
namespace Microsoft.SymbolManifestGenerator;

public static class SymbolManifestGenerator
{
public static class SymbolManifestGenerator
private const int Private = 340;

public static bool GenerateManifest(ITracer tracer, DirectoryInfo dir, string manifestFileName, bool specialFilesRequireAdjacentRuntime = true)
{
private const int Private = 340;
ManifestDataV1 manifestData = new();

public static void GenerateManifest(ITracer tracer, DirectoryInfo dir, string manifestFileName)
FileInfo[] allFiles = dir.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo file in allFiles)
{
ManifestDataV1 manifestData = new();
using FileStream fileStream = file.OpenRead();
SymbolStoreFile symbolStoreFile = new(fileStream, file.FullName);
FileKeyGenerator generator = new(tracer, symbolStoreFile);
if (!generator.IsValid())
{
tracer.Information($"Could not generate a valid FileKeyGenerator from file '{file.FullName}'. Skipping.");
continue;
}

FileInfo[] allFiles = dir.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo file in allFiles)
// For any given runtime that's found - enumerate all possible special keys.
foreach (SymbolStoreKey runtimeCorrelatedKey in generator.GetKeys(KeyTypeFlags.ClrKeys))
{
using FileStream fileStream = file.OpenRead();
SymbolStoreFile symbolStoreFile = new(fileStream, file.FullName);
FileKeyGenerator generator = new(tracer, symbolStoreFile);
if (!generator.IsValid())
(bool foundMultipleCandidates, FileInfo correlatedFile) = FindCorrelatedFileForRuntimeModule(tracer, allFiles, file, runtimeCorrelatedKey, specialFilesRequireAdjacentRuntime);

if (foundMultipleCandidates)
{
tracer.Information($"Could not generate a valid FileKeyGenerator from file '{file.FullName}'. Skipping.");
tracer.Error("Multiple files with same name to be indexed under same runtime - aborting manifest creation.");
return false;
}

if (correlatedFile is null)
{
tracer.Information($"Unique special file '{runtimeCorrelatedKey.FullPathName}' for runtime module '{file.FullName}' could not be found under '{file.DirectoryName}'. Skipping.");
continue;
}

foreach (SymbolStoreKey clrKey in generator.GetKeys(KeyTypeFlags.ClrKeys))
string basedirRelativePath = correlatedFile.FullName.Replace(dir.FullName, string.Empty).TrimStart(Path.DirectorySeparatorChar);
string fileHash = CalculateSHA512(correlatedFile);

if (manifestData.Entries.Any(x => x.BasedirRelativePath == basedirRelativePath))
{
FileInfo specialFile = ResolveClrKeyToUniqueFileFromAllFiles(allFiles, clrKey);
if (specialFile == null)
{
tracer.Information($"Known special file '{clrKey.FullPathName}' for runtime module '{file.FullName}' does not exist in directory '{file.DirectoryName}'. Skipping.");
continue;
}

string basedirRelativePath = specialFile.FullName.Replace(dir.FullName, string.Empty).TrimStart(Path.DirectorySeparatorChar);
string fileHash = CalculateSHA512(specialFile);

ManifestDataEntry manifestDataEntry = new()
{
BasedirRelativePath = basedirRelativePath,
SymbolKey = clrKey.Index,
Sha512 = fileHash,
DebugInformationLevel = Private,
LegacyDebugInformationLevel = Private
};

manifestData.Entries.Add(manifestDataEntry);
tracer.Error($"Special module '{correlatedFile.FullName}' cannot be associated with a single runtime unambiguously. Multiple runtimes found in lookup scope. Aborting manifest creation.");
return false;
}
}

JsonSerializerOptions serializeOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
};
string manifestDataContent = JsonSerializer.Serialize(manifestData, serializeOptions);
File.WriteAllText(manifestFileName, manifestDataContent);
ManifestDataEntry manifestDataEntry = new()
{
BasedirRelativePath = basedirRelativePath,
SymbolKey = runtimeCorrelatedKey.Index,
Sha512 = fileHash,
DebugInformationLevel = Private,
LegacyDebugInformationLevel = Private
};

manifestData.Entries.Add(manifestDataEntry);
}
}

JsonSerializerOptions serializeOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
};

string manifestDataContent = JsonSerializer.Serialize(manifestData, serializeOptions);
File.WriteAllText(manifestFileName, manifestDataContent);

return true;

// Special files associated with a particular runtime module have not been guaranteed to be in the same directory as the runtime module.
// As such, the directory for which a manifest is being generated must guarantee that at most one file exists with the same name as the special file.
private static FileInfo ResolveClrKeyToUniqueFileFromAllFiles(FileInfo[] allFiles, SymbolStoreKey clrKey)
// in some scenarios (e.g. the ARM64 long-name binaries in the runtime pack for .NET/.NET Core).
// - In cases where we require the file to be collocated (CLR), just validate existence.
// - In cases where collocation is not guaranteed, guarantee at most one module under said name exists.
static (bool FoundMultipleCandidates, FileInfo File) FindCorrelatedFileForRuntimeModule(ITracer tracer, FileInfo[] allFiles, FileInfo runtimeModule, SymbolStoreKey correlatedKey, bool specialFilesRequireAdjacentRuntime)
{
string clrKeyFileName = Path.GetFileName(clrKey.FullPathName);
string correlatedFileName = Path.GetFileName(correlatedKey.FullPathName);

FileInfo matchingSymbolFileOnDisk = allFiles.SingleOrDefault(file => FileHasClrKeyFileName(file, clrKeyFileName));
if (specialFilesRequireAdjacentRuntime)
{
FileInfo correlatedFile = new(Path.Combine(runtimeModule.DirectoryName, correlatedFileName));
return (FoundMultipleCandidates: false,
File: correlatedFile.Exists ? correlatedFile : default);
}

return matchingSymbolFileOnDisk;
FileInfo[] correlatedFiles = allFiles.Where(file => file.Name.Equals(correlatedFileName, StringComparison.OrdinalIgnoreCase)).ToArray();

static bool FileHasClrKeyFileName(FileInfo file, string clrKeyFileName)
if (correlatedFiles.Length > 1)
{
return file.Name.Equals(clrKeyFileName, StringComparison.OrdinalIgnoreCase);
tracer.Error($"Multiple files '${correlatedFileName}' found for runtime '{runtimeModule.FullName}': {string.Join<FileInfo>(", ", correlatedFiles)}.");
}
}

private static string CalculateSHA512(FileInfo file)
{
using FileStream fileReadStream = file.OpenRead();
using System.Security.Cryptography.SHA512 sha = System.Security.Cryptography.SHA512.Create();
byte[] hashValueBytes = sha.ComputeHash(fileReadStream);
return BitConverter.ToString(hashValueBytes).Replace("-", "");
return correlatedFiles.Length switch
{
0 => (FoundMultipleCandidates: false, default),
1 => (FoundMultipleCandidates: false, correlatedFiles[0]),
_ => (FoundMultipleCandidates: true, default)
};
}
}

private class ManifestFileVersion
{
public string Version { get; set; }
}
private static string CalculateSHA512(FileInfo file)
{
using FileStream fileReadStream = file.OpenRead();
using System.Security.Cryptography.SHA512 sha = System.Security.Cryptography.SHA512.Create();
byte[] hashValueBytes = sha.ComputeHash(fileReadStream);
return BitConverter.ToString(hashValueBytes).Replace("-", "");
}

private class ManifestDataV1 : ManifestFileVersion
{
public List<ManifestDataEntry> Entries { get; set; }
private class ManifestFileVersion
{
public string Version { get; set; }
}

public ManifestDataV1()
{
Version = "1";
Entries = new List<ManifestDataEntry>();
}
}
private class ManifestDataV1 : ManifestFileVersion
{
public List<ManifestDataEntry> Entries { get; set; }

private class ManifestDataEntry
public ManifestDataV1()
{
public string BasedirRelativePath { get; set; }
public string SymbolKey { get; set; }
public string Sha512 { get; set; }
public int DebugInformationLevel { get; set; }
[JsonPropertyName("DebugInformationLevel")]
public int LegacyDebugInformationLevel { get; set; }
Version = "1";
Entries = new List<ManifestDataEntry>();
}
}

private class ManifestDataEntry
{
public string BasedirRelativePath { get; set; }
public string SymbolKey { get; set; }
public string Sha512 { get; set; }
public int DebugInformationLevel { get; set; }
[JsonPropertyName("DebugInformationLevel")]
public int LegacyDebugInformationLevel { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/SOS/SOS.Package/SOS.Package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
<TriggerSet>
<ModuleTrigger Name="libcoreclr.so" />
</TriggerSet>
<TriggerSet>
<ExceptionTrigger ExceptionCode="0xC0000409" >
<Parameters>
<Parameter Index="0" Value="0x48"/>
</Parameters>
</ExceptionTrigger>
</TriggerSet>
</LoadTriggers>
<EngineCommands>
<EngineCommand Name="soshelp">
Expand Down
2 changes: 1 addition & 1 deletion src/shared/minipal/getexepath.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static inline char* minipal_getexepath(void)
return NULL;
}

char path_buf[path_length];
char* path_buf = (char*)alloca(path_length);
if (_NSGetExecutablePath(path_buf, &path_length) != 0)
{
errno = EINVAL;
Expand Down
6 changes: 3 additions & 3 deletions src/shared/pal/src/file/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ GetTempPathW(
return 0;
}

char TempBuffer[nBufferLength > 0 ? nBufferLength : 1];
DWORD dwRetVal = GetTempPathA( nBufferLength, TempBuffer );
char* tempBuffer = (char*)alloca(nBufferLength > 0 ? nBufferLength : 1);
DWORD dwRetVal = GetTempPathA( nBufferLength, tempBuffer );

if ( dwRetVal >= nBufferLength )
{
Expand All @@ -413,7 +413,7 @@ GetTempPathW(
else if ( dwRetVal != 0 )
{
/* Convert to wide. */
if ( 0 == MultiByteToWideChar( CP_ACP, 0, TempBuffer, -1,
if ( 0 == MultiByteToWideChar( CP_ACP, 0, tempBuffer, -1,
lpBuffer, dwRetVal + 1 ) )
{
ASSERT( "An error occurred while converting the string to wide.\n" );
Expand Down
1 change: 1 addition & 0 deletions src/shared/pal/src/include/pal/palinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ function_name() to call the system's implementation
#undef va_start
#undef va_end
#undef va_copy
#undef va_arg
#undef stdin
#undef stdout
#undef stderr
Expand Down

0 comments on commit d98406f

Please sign in to comment.