Skip to content

Commit

Permalink
Added prepend execution base path feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed May 13, 2024
1 parent 1abf973 commit 8c20cb2
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 158 deletions.
7 changes: 7 additions & 0 deletions chibicc-cil-toolchain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "toolchain.common", "toolcha
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "chibias.core", "chibias\chibias.core\chibias.core.csproj", "{CC1EC762-ED84-47A5-914F-5B5DD820D980}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "prependertestbed", "chibild\misc\prependertestbed\prependertestbed.csproj", "{C19D59AA-7D72-4DD0-8A0A-A5B664E0EE74}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -128,6 +130,10 @@ Global
{CC1EC762-ED84-47A5-914F-5B5DD820D980}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC1EC762-ED84-47A5-914F-5B5DD820D980}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC1EC762-ED84-47A5-914F-5B5DD820D980}.Release|Any CPU.Build.0 = Release|Any CPU
{C19D59AA-7D72-4DD0-8A0A-A5B664E0EE74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C19D59AA-7D72-4DD0-8A0A-A5B664E0EE74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C19D59AA-7D72-4DD0-8A0A-A5B664E0EE74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C19D59AA-7D72-4DD0-8A0A-A5B664E0EE74}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -147,6 +153,7 @@ Global
{9C384CE3-4BD5-44B9-AE59-F0159D20D302} = {5F40AA75-7382-487D-B2F7-3D07DC68C566}
{EDFB3E84-7FD5-414D-9A17-378C62CA3F35} = {5F40AA75-7382-487D-B2F7-3D07DC68C566}
{CC1EC762-ED84-47A5-914F-5B5DD820D980} = {A4C160C3-9D6F-4B0C-9A66-CA5FE5264672}
{C19D59AA-7D72-4DD0-8A0A-A5B664E0EE74} = {2D17624C-B2B8-4343-94BF-34056C7FD4EC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {50B7704D-EFFD-4789-90DD-F594F80C2B97}
Expand Down
2 changes: 2 additions & 0 deletions chibild/chibild.core.Tests/LinkerTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static string RunCore(
string[] chibildSourceCodes,
string[]? additionalReferencePaths,
string? injectToAssemblyPath,
string[]? prependExecutionSearchPaths,
Func<LinkerCreationOptions?> creationOptionsF,
string memberName)
{
Expand Down Expand Up @@ -116,6 +117,7 @@ public static string RunCore(
IsDeterministic = true,
ApplyOptimization = false,
CreationOptions = creationOptions,
PrependExecutionSearchPaths = prependExecutionSearchPaths ?? Array.Empty<string>(),
},
injectToAssemblyPath,
basePath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

// .NET IL Disassembler. Version 8.0.0



// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickey = (00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 )
.ver 4:0:0:0
}
.assembly extern prependertestbed
{
.ver 0:0:0:0
}
.assembly output
{
.custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 1A 2E 4E 45 54 46 72 61 6D 65 77 6F 72 6B // ....NETFramework
2C 56 65 72 73 69 6F 6E 3D 76 34 2E 35 00 00 ) // ,Version=v4.5..
.ver 1:0:0:0
}
.module output.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY


// ================== GLOBAL METHODS =========================

.method assembly static int32 _start() cil managed
{
.entrypoint
// Code size 26 (0x1a)
.maxstack 8
IL_0000: ldstr "aaa/bin"
IL_0005: call void [prependertestbed]C.text::__prepend_path_env(string)
IL_000a: ldstr "bbb/bin"
IL_000f: call void [prependertestbed]C.text::__prepend_path_env(string)
IL_0014: call int32 C.text::main()
IL_0019: ret
} // end of global method _start


// =============================================================


// =============== CLASS MEMBERS DECLARATION ===================

.class public abstract auto ansi sealed C.text
extends [mscorlib]System.Object
{
.method public static int32 main() cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldc.i4.1
IL_0001: ret
} // end of method text::main

} // end of class C.text


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
15 changes: 15 additions & 0 deletions chibild/chibild.core.Tests/LinkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2980,4 +2980,19 @@ call int64_add
injectToAssemblyPath);
return Verify(actual);
}

[Test]
public Task PrependSearchPath()
{
var combineToAssemblyPath = Path.Combine(
LinkerTestRunner.ArtifactsBasePath, "prependertestbed.dll");
var actual = Run(@"
.function public int32() main
ldc.i4.1
ret",
assemblyType: AssemblyTypes.Exe,
prependExecutionSearchPaths: new[] { "aaa/bin", "bbb/bin" },
additionalReferencePaths: new[] { combineToAssemblyPath });
return Verify(actual);
}
}
7 changes: 6 additions & 1 deletion chibild/chibild.core.Tests/LinkerTests_Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ private string Run(
string[]? additionalReferencePaths = null,
AssemblyTypes assemblyType = AssemblyTypes.Dll,
string targetFrameworkMoniker = "net45",
[CallerMemberName] string memberName = null!) =>
string[]? prependExecutionSearchPaths = null,
[CallerMemberName] string memberName = null!) =>
LinkerTestRunner.RunCore(
chibildSourceCodes,
additionalReferencePaths,
null,
prependExecutionSearchPaths,
() =>
{
var appHostTemplatePath = Path.GetFullPath(
Expand All @@ -49,12 +51,14 @@ private string Run(
string[]? additionalReferencePaths = null,
AssemblyTypes assemblyType = AssemblyTypes.Dll,
string targetFrameworkMoniker = "net45",
string[]? prependExecutionSearchPaths = null,
[CallerMemberName] string memberName = null!) =>
this.Run(
new[] { chibildSourceCode },
additionalReferencePaths,
assemblyType,
targetFrameworkMoniker,
prependExecutionSearchPaths,
memberName);

private string RunInjection(
Expand All @@ -66,6 +70,7 @@ private string RunInjection(
new[] { chibildSourceCode },
additionalReferencePaths,
injectToAssemblyPath,
null,
() => null,
memberName);
}
Binary file not shown.
Binary file not shown.
8 changes: 0 additions & 8 deletions chibild/chibild.core.Tests/chibild.core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
<Content Include="artifacts\*" />
</ItemGroup>

<ItemGroup>
<Content Remove="artifacts\crt0.o" />
</ItemGroup>

<ItemGroup>
<None Include="artifacts\crt0.o" />
</ItemGroup>

<ItemGroup>
<Compile Update="LinkerTests.cs">
<DependentUpon>AssemblerTests_Common.cs</DependentUpon>
Expand Down
6 changes: 4 additions & 2 deletions chibild/chibild.core/CilLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/////////////////////////////////////////////////////////////////////////////////////

using chibicc.toolchain.IO;
using chibicc.toolchain.Internal;
using chibicc.toolchain.Logging;
using chibild.Generating;
using chibild.Internal;
Expand Down Expand Up @@ -213,7 +214,7 @@ when Path.GetExtension(relativePath) == ".a":
#endif

fragments = loadedFragmentLists.
SelectMany(loadedFragments => loadedFragments).
SelectMany(loadedFragments => loadedFragments ?? CommonUtilities.Empty<InputFragment>()).
ToArray();
return caughtErrorCount == 0;
}
Expand Down Expand Up @@ -394,7 +395,8 @@ injectToAssemblyPath is { } injectPath ?
loadedFragments,
options.ApplyOptimization,
options.DebugSymbolType == DebugSymbolTypes.Embedded,
options.CreationOptions))
options.CreationOptions,
options.PrependExecutionSearchPaths))
{
return false;
}
Expand Down
Loading

0 comments on commit 8c20cb2

Please sign in to comment.