Skip to content

Commit

Permalink
Improved assembly loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jun 4, 2024
1 parent 2cce68a commit c81e87b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
10 changes: 2 additions & 8 deletions chibild/chibild.core/CilLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,8 @@ when Path.GetExtension(relativePath) == ".a":
this.logger,
baseInputPath,
relativePath,
// Create this assembly specific resolver,
// because shared resolver can not resolve on multi-threaded context.
// At the cost of having to load it again later in the primary assembly resolver.
this.CreateAssemblyResolver(
ReadingMode.Immediate,
ReadingMode.Deferred,
assemblyReferenceBasePaths)),
};
break;
Expand Down Expand Up @@ -194,11 +191,8 @@ when Path.GetExtension(relativePath) == ".a":
this.logger,
foundEntry.basePath,
foundEntry.fileName,
// Create this assembly specific resolver,
// because shared resolver can not resolve on multi-threaded context.
// At the cost of having to load it again later in the primary assembly resolver.
this.CreateAssemblyResolver(
ReadingMode.Immediate,
ReadingMode.Deferred,
assemblyReferenceBasePaths)),
};
}
Expand Down
12 changes: 6 additions & 6 deletions chibild/chibild.core/Internal/MultipleSymbolReaderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/////////////////////////////////////////////////////////////////////////////////////

using chibicc.toolchain.Internal;
using chibicc.toolchain.IO;
using chibicc.toolchain.Logging;
using Mono.Cecil;
using Mono.Cecil.Cil;
Expand Down Expand Up @@ -53,17 +54,16 @@ public MultipleSymbolReaderProvider(ILogger logger) =>
if (File.Exists(path))
{
var ms = new MemoryStream();
using (var mdbStream = new FileStream(
path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var stream = StreamUtilities.OpenStream(path, false))
{
mdbStream.CopyTo(ms);
stream.CopyTo(ms);
}
ms.Position = 0;

var sr = provider.GetSymbolReader(module, ms);
if (this.loaded.Add(path))
{
this.logger.Debug($"Symbol loaded from: {path}");
this.logger.Debug($"Debug symbol is loaded from: {path}");
}

return sr;
Expand Down Expand Up @@ -98,7 +98,7 @@ public MultipleSymbolReaderProvider(ILogger logger) =>
var sr = embeddedProvider.GetSymbolReader(module, fullPath);
if (this.loaded.Add(fullPath))
{
this.logger.Debug($"Embedded symbol loaded from: {fullPath}");
this.logger.Debug($"Embedded debug symbol is loaded from: {fullPath}");
}

return sr;
Expand All @@ -119,7 +119,7 @@ public MultipleSymbolReaderProvider(ILogger logger) =>

if (this.notFound.Add(fileName))
{
this.logger.Trace($"Symbol not found: {fileName}");
this.logger.Trace($"Debug symbol is not found: {fileName}");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion toolchain.common/IO/StreamUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public static Stream OpenStream(string path, bool writable) =>
path,
writable ? FileMode.Create : FileMode.Open,
writable ? FileAccess.ReadWrite : FileAccess.Read,
FileShare.Read);
FileShare.Read,
1024 * 1024);
}

0 comments on commit c81e87b

Please sign in to comment.