Skip to content

Commit

Permalink
Retarget to netstandard 2.0 (.net 4.6.1 for tools build on windows, n…
Browse files Browse the repository at this point in the history
…et core 2.0 for libraries used at runtime)
  • Loading branch information
jncronin committed Nov 2, 2017
1 parent 3b5e8f8 commit 610772f
Show file tree
Hide file tree
Showing 35 changed files with 1,250 additions and 675 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Expand Up @@ -7,7 +7,3 @@
path = corefx
url = https://github.com/dotnet/corefx.git
branch = release/2.0.0

[submodule "tymake/ILMerge"]
path = tymake/ILMerge
url = https://github.com/Microsoft/ILMerge.git
2 changes: 1 addition & 1 deletion corefx
Submodule corefx updated 5265 files
11 changes: 6 additions & 5 deletions libsupcs/libsupcs.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>libsupcs</RootNamespace>
<AssemblyName>libsupcs</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -23,6 +23,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,6 +33,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Compile libsupcs|AnyCPU'">
<OutputPath>bin\Compile libsupcs\</OutputPath>
Expand All @@ -44,6 +46,7 @@
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Compile BareBones|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -54,6 +57,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="abi.cs" />
Expand All @@ -77,9 +81,6 @@
<Compile Include="x86_64_invoke.cs" />
<Compile Include="x86_64_Unwinder.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Content Include="x86_64_cpu.asm" />
<Content Include="x86_64_Invoke.asm" />
Expand Down
7 changes: 3 additions & 4 deletions libtysila5/libtysila5.csproj
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>libtysila5</RootNamespace>
<AssemblyName>libtysila5</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,6 +32,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssembleMethod.cs" />
Expand Down Expand Up @@ -99,9 +101,6 @@
<None Include="target\TargetInit.td" />
<None Include="target\x86\x86.td" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
7 changes: 7 additions & 0 deletions libtysila5/target/x86/x86_Assembler.cs
Expand Up @@ -39,14 +39,18 @@ bool has_cpu_feature(string name)
{
// get cpu family, model, stepping
int family = 0;
#if HAVE_SYSTEM
var lvls = Environment.GetEnvironmentVariable("PROCESSOR_LEVEL");
if(lvls != null)
{
int.TryParse(lvls, out family);
}
#endif

int model = 0;
int stepping = 0;

#if HAVE_SYSTEM
var rev = Environment.GetEnvironmentVariable("PROCESSOR_REVISION");
if(rev != null)
{
Expand All @@ -59,11 +63,14 @@ bool has_cpu_feature(string name)
int.TryParse(steps, System.Globalization.NumberStyles.HexNumber, null, out stepping);
}
}
#endif

bool is_amd64 = false;
#if HAVE_SYSTEM
var parch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (parch != null && parch == "AMD64")
is_amd64 = true;
#endif

if(name == "sse2")
{
Expand Down
2 changes: 1 addition & 1 deletion metadata/PEFile.cs
Expand Up @@ -136,7 +136,7 @@ public MetadataStream Parse(DataInterface file, AssemblyLoader al)

pefh.Sections[i].Name = new String(w_str);
pefh.Sections[i].Name = pefh.Sections[i].Name.Remove(pefh.Sections[i].Name.IndexOf("\0"));
System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: section name: " + pefh.Sections[i].Name + Environment.NewLine);
System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: section name: " + pefh.Sections[i].Name + "\n");

pefh.Sections[i].VSize = file.ReadUInt((int)s_start + 8);
pefh.Sections[i].VAddress = file.ReadUInt((int)s_start + 12);
Expand Down
4 changes: 3 additions & 1 deletion metadata/metadata.csproj
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>metadata</RootNamespace>
<AssemblyName>metadata</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -29,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyLoader.cs" />
Expand Down
2 changes: 2 additions & 0 deletions tl/binary_library/BinaryFile.cs
Expand Up @@ -187,6 +187,7 @@ public virtual ISection FindSection(string name)
return null;
}

#if HAVE_SYSTEM
public virtual ISection FindSection(System.Text.RegularExpressions.Regex r)
{
foreach (ISection sect in sections)
Expand All @@ -196,6 +197,7 @@ public virtual ISection FindSection(System.Text.RegularExpressions.Regex r)
}
return null;
}
#endif

public virtual bool ContainsSymbol(ISymbol symbol)
{
Expand Down
3 changes: 3 additions & 0 deletions tl/binary_library/IBinaryFile.cs
Expand Up @@ -60,7 +60,10 @@ public interface IBinaryFile
ISection CreateSection();
ISection CreateContentsSection();
ISection FindSection(string name);

#if HAVE_SYSTEM
ISection FindSection(System.Text.RegularExpressions.Regex r);
#endif

int GetSymbolCount();
ISymbol GetSymbol(int idx);
Expand Down
23 changes: 16 additions & 7 deletions tl/binary_library/binary/hex.cs
Expand Up @@ -59,7 +59,7 @@ protected override void Write(BinaryWriter w)
}
progbits.Sort((a, b) => a.LoadAddress.CompareTo(b.LoadAddress));

StreamWriter sw = new StreamWriter(w.BaseStream, Encoding.ASCII);
//StreamWriter sw = new StreamWriter(w.BaseStream, Encoding.ASCII);

// Now rebase zero to be the load address of the first section
uint addr = 0;
Expand All @@ -75,25 +75,34 @@ protected override void Write(BinaryWriter w)
// write zeros up to the current load address
while (base_addr < sect.LoadAddress)
{
Write(sw, addr, 0);
Write(w.BaseStream, addr, 0);
base_addr++;
addr++;
}

// write the section data
foreach (byte b in sect.Data)
{
Write(sw, addr, b);
Write(w.BaseStream, addr, b);
base_addr++;
addr++;
}
}

sw.WriteLine(":00000001FF");
sw.Flush();
writeStr(w.BaseStream, ":00000001FF", true);
w.BaseStream.Flush();
}

private void Write(StreamWriter sw, uint addr, byte v)
/* Implemented here incase mscorlib does not contain StreamWriter */
public static void writeStr(Stream s, string v = "", bool newline = true)
{
foreach (var c in v)
s.WriteByte((byte)c);
if (newline)
s.WriteByte((byte)'\n');
}

private void Write(Stream sw, uint addr, byte v)
{
StringBuilder sb = new StringBuilder();
sb.Append(":01");
Expand All @@ -107,7 +116,7 @@ private void Write(StreamWriter sw, uint addr, byte v)
csum &= 0xffU;
sb.Append(csum.ToString("X2"));

sw.WriteLine(sb.ToString());
writeStr(sw, sb.ToString(), true);
}
}
}
13 changes: 7 additions & 6 deletions tl/binary_library/binary_library.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,9 +10,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>binary_library</RootNamespace>
<AssemblyName>binary_library</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -22,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Compile BareBones|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -39,6 +42,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="BinaryFile.cs" />
Expand All @@ -60,9 +64,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Symbol.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions tl/binary_library/elf/ElfFile.cs
Expand Up @@ -503,15 +503,19 @@ protected override void Write(System.IO.BinaryWriter w)
if(sect == null)
{
// default to 0x0
#if HAVE_SYSTEM
Console.WriteLine("Entry point " + EntryPoint +
" not found, defaulting to 0x0");
#endif
e_entry = 0;
}
else
{
#if HAVE_SYSTEM
Console.WriteLine("Entry point " + EntryPoint +
" not found, defaulting to 0x" +
sect.LoadAddress.ToString("X"));
#endif
e_entry = sect.LoadAddress;
}
}
Expand Down
27 changes: 25 additions & 2 deletions tymake/Program.cs
Expand Up @@ -116,7 +116,10 @@ public TyProject()
args = new List<FunctionArg> { new FunctionArg { name = "projfile", argtype = Expression.EvalResult.ResultType.String },
new FunctionArg { name = "config", argtype = Expression.EvalResult.ResultType.String },
new FunctionArg { name = "tools_ver", argtype = Expression.EvalResult.ResultType.String },
new FunctionArg { name = "unsafe", argtype = Expression.EvalResult.ResultType.Int } };
new FunctionArg { name = "unsafe", argtype = Expression.EvalResult.ResultType.Int },
new FunctionArg { name = "imports", argtype = Expression.EvalResult.ResultType.Array },
new FunctionArg { name = "ref_overrides", argtype = Expression.EvalResult.ResultType.Array },
new FunctionArg { name = "lib_dir", argtype = Expression.EvalResult.ResultType.String } };
}

public override Expression.EvalResult Run(MakeState s, List<Expression.EvalResult> args)
Expand All @@ -133,12 +136,26 @@ public override Expression.EvalResult Run(MakeState s, List<Expression.EvalResul
throw new Exception("_typroject: " + fname + " does not exist");
}

/* Extract out imports */
List<string> imports = new List<string>();
foreach (var import in args[4].arrval)
imports.Add(import.strval);

/* Extract out ref overrides */
List<string> ref_overrides = new List<string>();
foreach (var ro in args[5].arrval)
ref_overrides.Add(ro.strval);


typroject.Project p = null;
if (fname.ToLower().EndsWith(".csproj"))
p = typroject.Project.xml_read(fi.OpenRead(), config, fi.DirectoryName, cur_dir);
p = typroject.Project.xml_read(fi.OpenRead(), config, fi.DirectoryName, cur_dir, imports, ref_overrides);
else if (fname.ToLower().EndsWith(".sources"))
p = typroject.Project.sources_read(fi.OpenRead(), config, fi.DirectoryName, cur_dir);

if (args[6].strval != "")
p.lib_dir = args[6].strval;

Dictionary<string, Expression.EvalResult> ret = new Dictionary<string, Expression.EvalResult>();
ret["OutputFile"] = new Expression.EvalResult(p.OutputFile);
ret["OutputType"] = new Expression.EvalResult(p.output_type.ToString());
Expand All @@ -150,6 +167,9 @@ public override Expression.EvalResult Run(MakeState s, List<Expression.EvalResul
ret["ProjectReferences"] = new Expression.EvalResult(new string[] { });
foreach (typroject.Project pref in p.ProjectReferences)
ret["ProjectReferences"].arrval.Add(new Expression.EvalResult(pref.ProjectFile));
ret["References"] = new Expression.EvalResult(new string[] { });
foreach (var rref in p.References)
ret["References"].arrval.Add(new Expression.EvalResult(rref));
ret["ProjectFile"] = new Expression.EvalResult(fi.FullName);
ret["ProjectName"] = new Expression.EvalResult(p.ProjectName);

Expand Down Expand Up @@ -178,6 +198,9 @@ public BuildFunction(typroject.Project proj)

public override Expression.EvalResult Run(MakeState s, List<Expression.EvalResult> passed_args)
{
var o = passed_args[0].objval;
p.assembly_name = o["AssemblyName"].strval;

return new Expression.EvalResult(p.build(new List<string>(), new List<string>(), new List<string>(), do_unsafe));
}
}
Expand Down

0 comments on commit 610772f

Please sign in to comment.