Skip to content

Commit 5d7d3e7

Browse files
authored
Merge pull request dotnet#719 from SrivastavaAnubhav/optional-mapfile
Disable generating a map file by default.
2 parents 6b78906 + 0997ba5 commit 5d7d3e7

8 files changed

Lines changed: 50 additions & 11 deletions

File tree

src/coreclr/src/tools/ReadyToRun.SuperIlc/BuildOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class BuildOptions
2121
public bool NoExe { get; set; }
2222
public bool NoEtw { get; set; }
2323
public bool NoCleanup { get; set; }
24+
public bool GenerateMapFile { get; set; }
2425
public FileInfo PackageList { get; set; }
2526
public int DegreeOfParallelism { get; set; }
2627
public bool Sequential { get; set; }

src/coreclr/src/tools/ReadyToRun.SuperIlc/CommandLineOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Command CompileFolder() =>
3838
NoExe(),
3939
NoEtw(),
4040
NoCleanup(),
41+
GenerateMapFile(),
4142
DegreeOfParallelism(),
4243
Sequential(),
4344
Framework(),
@@ -70,6 +71,7 @@ Command CompileSubtree() =>
7071
NoExe(),
7172
NoEtw(),
7273
NoCleanup(),
74+
GenerateMapFile(),
7375
DegreeOfParallelism(),
7476
Sequential(),
7577
Framework(),
@@ -179,6 +181,9 @@ Option NoEtw() =>
179181
Option NoCleanup() =>
180182
new Option(new[] { "--nocleanup" }, "Don't clean up compilation artifacts after test runs", new Argument<bool>());
181183

184+
Option GenerateMapFile() =>
185+
new Option(new[] { "--map" }, "Generate a map file (Crossgen2)", new Argument<bool>());
186+
182187
Option DegreeOfParallelism() =>
183188
new Option(new[] { "--degree-of-parallelism", "-dop" }, "Override default compilation / execution DOP (default = logical processor count)", new Argument<int>());
184189

src/coreclr/src/tools/ReadyToRun.SuperIlc/CpaotRunner.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ protected override IEnumerable<string> BuildCommandLineArguments(string assembly
4949
// Todo: Allow control of some of these
5050
yield return "--targetarch=x64";
5151

52+
if (_options.GenerateMapFile)
53+
{
54+
yield return "--map";
55+
}
56+
5257
if (_options.Release)
5358
{
5459
yield return "-O";

src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal class ReadyToRunObjectWriter
2727
private readonly string _objectFilePath;
2828
private readonly IEnumerable<DependencyNode> _nodes;
2929
private readonly PEReader _inputPeReader;
30+
private readonly bool _generateMapFile;
3031

3132
#if DEBUG
3233
private struct NodeInfo
@@ -46,12 +47,13 @@ public NodeInfo(ISymbolNode node, int nodeIndex, int symbolIndex)
4647
Dictionary<string, NodeInfo> _previouslyWrittenNodeNames = new Dictionary<string, NodeInfo>();
4748
#endif
4849

49-
public ReadyToRunObjectWriter(PEReader inputPeReader, string objectFilePath, IEnumerable<DependencyNode> nodes, ReadyToRunCodegenNodeFactory factory)
50+
public ReadyToRunObjectWriter(PEReader inputPeReader, string objectFilePath, IEnumerable<DependencyNode> nodes, ReadyToRunCodegenNodeFactory factory, bool generateMapFile)
5051
{
5152
_objectFilePath = objectFilePath;
5253
_nodes = nodes;
5354
_nodeFactory = factory;
5455
_inputPeReader = inputPeReader;
56+
_generateMapFile = generateMapFile;
5557
}
5658

5759
public void EmitPortableExecutable()
@@ -63,13 +65,18 @@ public void EmitPortableExecutable()
6365

6466
try
6567
{
66-
string mapFileName = Path.ChangeExtension(_objectFilePath, ".map");
67-
mapFileStream = new FileStream(mapFileName, FileMode.Create, FileAccess.Write);
68-
mapFile = new StreamWriter(mapFileStream);
68+
if (_generateMapFile)
69+
{
70+
string mapFileName = Path.ChangeExtension(_objectFilePath, ".map");
71+
mapFileStream = new FileStream(mapFileName, FileMode.Create, FileAccess.Write);
72+
mapFile = new StreamWriter(mapFileStream);
73+
}
6974

7075
Stopwatch stopwatch = new Stopwatch();
7176
stopwatch.Start();
72-
mapFile.WriteLine($@"R2R object emission started: {DateTime.Now}");
77+
78+
if (mapFile != null)
79+
mapFile.WriteLine($@"R2R object emission started: {DateTime.Now}");
7380

7481
R2RPEBuilder r2rPeBuilder = new R2RPEBuilder(
7582
_nodeFactory.Target,
@@ -125,9 +132,12 @@ public void EmitPortableExecutable()
125132
r2rPeBuilder.Write(peStream);
126133
}
127134

128-
mapFile.WriteLine($@"R2R object emission finished: {DateTime.Now}, {stopwatch.ElapsedMilliseconds} msecs");
129-
mapFile.Flush();
130-
mapFileStream.Flush();
135+
if (mapFile != null)
136+
{
137+
mapFile.WriteLine($@"R2R object emission finished: {DateTime.Now}, {stopwatch.ElapsedMilliseconds} msecs");
138+
mapFile.Flush();
139+
mapFileStream.Flush();
140+
}
131141

132142
succeeded = true;
133143
}
@@ -194,10 +204,10 @@ private void EmitObjectData(R2RPEBuilder r2rPeBuilder, ObjectData data, int node
194204
r2rPeBuilder.AddObjectData(data, section, name, mapFile);
195205
}
196206

197-
public static void EmitObject(PEReader inputPeReader, string objectFilePath, IEnumerable<DependencyNode> nodes, ReadyToRunCodegenNodeFactory factory)
207+
public static void EmitObject(PEReader inputPeReader, string objectFilePath, IEnumerable<DependencyNode> nodes, ReadyToRunCodegenNodeFactory factory, bool generateMapFile)
198208
{
199209
Console.WriteLine($@"Emitting R2R PE file: {objectFilePath}");
200-
ReadyToRunObjectWriter objectWriter = new ReadyToRunObjectWriter(inputPeReader, objectFilePath, nodes, factory);
210+
ReadyToRunObjectWriter objectWriter = new ReadyToRunObjectWriter(inputPeReader, objectFilePath, nodes, factory, generateMapFile);
201211
objectWriter.EmitPortableExecutable();
202212
}
203213
}

src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ public sealed class ReadyToRunCodegenCompilation : Compilation
205205

206206
private int _parallelism;
207207

208+
private bool _generateMapFile;
209+
208210
public new ReadyToRunCodegenNodeFactory NodeFactory { get; }
209211

210212
public ReadyToRunSymbolNodeFactory SymbolNodeFactory { get; }
@@ -220,11 +222,13 @@ internal ReadyToRunCodegenCompilation(
220222
string inputFilePath,
221223
IEnumerable<ModuleDesc> modulesBeingInstrumented,
222224
bool resilient,
225+
bool generateMapFile,
223226
int parallelism)
224227
: base(dependencyGraph, nodeFactory, roots, ilProvider, devirtualizationManager, modulesBeingInstrumented, logger)
225228
{
226229
_resilient = resilient;
227230
_parallelism = parallelism;
231+
_generateMapFile = generateMapFile;
228232
NodeFactory = nodeFactory;
229233
SymbolNodeFactory = new ReadyToRunSymbolNodeFactory(nodeFactory);
230234
_jitConfigProvider = configProvider;
@@ -247,7 +251,7 @@ public override void Compile(string outputFile)
247251
using (PerfEventSource.StartStopEvents.EmittingEvents())
248252
{
249253
NodeFactory.SetMarkingComplete();
250-
ReadyToRunObjectWriter.EmitObject(inputPeReader, outputFile, nodes, NodeFactory);
254+
ReadyToRunObjectWriter.EmitObject(inputPeReader, outputFile, nodes, NodeFactory, _generateMapFile);
251255
}
252256
}
253257
}

src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilationBuilder.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public sealed class ReadyToRunCodegenCompilationBuilder : CompilationBuilder
2222
private readonly EcmaModule _inputModule;
2323
private bool _ibcTuning;
2424
private bool _resilient;
25+
private bool _generateMapFile;
2526
private int _parallelism;
2627
private string _jitPath;
2728

@@ -94,6 +95,12 @@ public ReadyToRunCodegenCompilationBuilder UseResilience(bool resilient)
9495
return this;
9596
}
9697

98+
public ReadyToRunCodegenCompilationBuilder UseMapFile(bool generateMapFile)
99+
{
100+
_generateMapFile = generateMapFile;
101+
return this;
102+
}
103+
97104
public ReadyToRunCodegenCompilationBuilder UseParallelism(int parallelism)
98105
{
99106
_parallelism = parallelism;
@@ -185,6 +192,7 @@ public override ICompilation ToCompilation()
185192
_inputFilePath,
186193
new ModuleDesc[] { _inputModule },
187194
_resilient,
195+
_generateMapFile,
188196
_parallelism);
189197
}
190198
}

src/coreclr/src/tools/crossgen2/crossgen2/CommandLineOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class CommandLineOptions
3131
public bool Tuning { get; set; }
3232
public bool Partial { get; set; }
3333
public bool Resilient { get; set; }
34+
public bool GenerateMapFile { get; set; }
3435
public int Parallelism { get; set; }
3536

3637

@@ -146,6 +147,10 @@ public static Command RootCommand()
146147
{
147148
Argument = new Argument<int>(() => Environment.ProcessorCount)
148149
},
150+
new Option(new[] { "--map" }, "Generate the map file")
151+
{
152+
Argument = new Argument<bool>()
153+
},
149154
};
150155
}
151156
}

src/coreclr/src/tools/crossgen2/crossgen2/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ private int Run()
323323
builder
324324
.UseIbcTuning(_commandLineOptions.Tuning)
325325
.UseResilience(_commandLineOptions.Resilient)
326+
.UseMapFile(_commandLineOptions.GenerateMapFile)
326327
.UseParallelism(_commandLineOptions.Parallelism)
327328
.UseILProvider(ilProvider)
328329
.UseJitPath(_commandLineOptions.JitPath)

0 commit comments

Comments
 (0)