Skip to content

Commit 179146b

Browse files
committed
Add the PlatformNativeImage flag as spec'd in #120584
1 parent 9e807d9 commit 179146b

File tree

7 files changed

+58
-41
lines changed

7 files changed

+58
-41
lines changed

docs/design/coreclr/botr/readytorun-format.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct READYTORUN_CORE_HEADER
135135
| READYTORUN_FLAG_COMPONENT | 0x00000020 | This is a component assembly of a composite R2R image
136136
| READYTORUN_FLAG_MULTIMODULE_VERSION_BUBBLE | 0x00000040 | This R2R module has multiple modules within its version bubble (For versions before version 6.3, all modules are assumed to possibly have this characteristic)
137137
| READYTORUN_FLAG_UNRELATED_R2R_CODE | 0x00000080 | This R2R module has code in it that would not be naturally encoded into this module
138+
| READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE | 0x00000100 | The owning composite executable is in the platform native format
138139

139140
## READYTORUN_SECTION
140141

src/coreclr/inc/readytorun.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// If you update this, ensure you run `git grep MINIMUM_READYTORUN_MAJOR_VERSION`
2121
// and handle pending work.
2222
#define READYTORUN_MAJOR_VERSION 16
23-
#define READYTORUN_MINOR_VERSION 0x0000
23+
#define READYTORUN_MINOR_VERSION 0x0001
2424

2525
#define MINIMUM_READYTORUN_MAJOR_VERSION 16
2626

@@ -47,6 +47,8 @@
4747
// R2R Version 14 changed x86 code generation to use funclets
4848
// R2R Version 15 removes double to int/uint helper calls
4949
// R2R Version 16 replaces the compression format for debug boundaries with a new format that is smaller and more efficient to parse
50+
// R2R 16 is not backward compatible with 15.x or earlier.
51+
// R2R Version 16.1 adds the READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE flag to specify that the R2R image pointed to by OwnerCompositeExecutable is in the platform native format.
5052

5153
struct READYTORUN_CORE_HEADER
5254
{
@@ -83,6 +85,7 @@ enum ReadyToRunFlag
8385
READYTORUN_FLAG_COMPONENT = 0x00000020, // This is the header describing a component assembly of composite R2R
8486
READYTORUN_FLAG_MULTIMODULE_VERSION_BUBBLE = 0x00000040, // This R2R module has multiple modules within its version bubble (For versions before version 6.2, all modules are assumed to possibly have this characteristic)
8587
READYTORUN_FLAG_UNRELATED_R2R_CODE = 0x00000080, // This R2R module has code in it that would not be naturally encoded into this module
88+
READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE = 0x00000100, // The owning composite executable is in the platform native format
8689
};
8790

8891
enum class ReadyToRunSectionType : uint32_t

src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct ReadyToRunHeaderConstants
1212
static const uint32_t Signature = 0x00525452; // 'RTR'
1313

1414
static const uint32_t CurrentMajorVersion = 16;
15-
static const uint32_t CurrentMinorVersion = 0;
15+
static const uint32_t CurrentMinorVersion = 1;
1616
};
1717

1818
struct ReadyToRunHeader

src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal struct ReadyToRunHeaderConstants
1616
public const uint Signature = 0x00525452; // 'RTR'
1717

1818
public const ushort CurrentMajorVersion = 16;
19-
public const ushort CurrentMinorVersion = 0;
19+
public const ushort CurrentMinorVersion = 1;
2020
}
2121
#if READYTORUN
2222
#pragma warning disable 0169

src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public enum ReadyToRunFlags
1717
READYTORUN_FLAG_NonSharedPInvokeStubs = 0x00000008, // PInvoke stubs compiled into image are non-shareable (no secret parameter)
1818
READYTORUN_FLAG_EmbeddedMSIL = 0x00000010, // MSIL is embedded in the composite R2R executable
1919
READYTORUN_FLAG_Component = 0x00000020, // This is the header describing a component assembly of composite R2R
20-
READYTORUN_FLAG_MultiModuleVersionBubble = 0x00000040, // This R2R module has multiple modules within its version bubble
20+
READYTORUN_FLAG_MultiModuleVersionBubble = 0x00000040, // This R2R module has multiple modules within its version bubble
2121
READYTORUN_FLAG_UnrelatedR2RCode = 0x00000080, // This R2R module has generic code in it that would not be naturally encoded into this module
22+
READYTORUN_FLAG_PlatformNativeImage = 0x00000100, // The owning composite executable is in the platform native format
2223
}
2324

2425
public enum ReadyToRunImportSectionType : byte

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

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -179,43 +179,12 @@ public void EmitReadyToRunObjects(ReadyToRunContainerFormat format, Logger logge
179179
{
180180
var stopwatch = Stopwatch.StartNew();
181181

182-
Debug.Assert(format == ReadyToRunContainerFormat.PE);
183-
184-
int? timeDateStamp;
185-
186-
if (_nodeFactory.CompilationModuleGroup.IsCompositeBuildMode && _componentModule == null)
187-
{
188-
timeDateStamp = null;
189-
}
190-
else
191-
{
192-
PEReader inputPeReader = (_componentModule != null ? _componentModule.PEReader : _nodeFactory.CompilationModuleGroup.CompilationModuleSet.First().PEReader);
193-
timeDateStamp = inputPeReader.PEHeaders.CoffHeader.TimeDateStamp;
194-
}
195-
196-
ObjectWriter.ObjectWriter objectWriter;
197-
198-
if (format == ReadyToRunContainerFormat.PE)
182+
ObjectWriter.ObjectWriter objectWriter = format switch
199183
{
200-
PEObjectWriter peWriter = new(_nodeFactory, ObjectWritingOptions.None, _outputInfoBuilder, _objectFilePath, _customPESectionAlignment, timeDateStamp);
201-
202-
if (_nodeFactory.CompilationModuleGroup.IsCompositeBuildMode && _componentModule == null)
203-
{
204-
peWriter.AddExportedSymbol("RTR_HEADER");
205-
}
206-
objectWriter = peWriter;
207-
}
208-
else if (format == ReadyToRunContainerFormat.MachO)
209-
{
210-
// Use the base symbol name emitted into .dylib files,
211-
// with the expectation that the R2R object will be linked into
212-
// a dylib.
213-
objectWriter = new MachObjectWriter(_nodeFactory, ObjectWritingOptions.None, _outputInfoBuilder, baseSymbolName: "__mh_dylib_header");
214-
}
215-
else
216-
{
217-
throw new UnreachableException();
218-
}
184+
ReadyToRunContainerFormat.PE => CreatePEObjectWriter(),
185+
ReadyToRunContainerFormat.MachO => CreateMachObjectWriter(),
186+
_ => throw new UnreachableException()
187+
};
219188

220189
using FileStream stream = new FileStream(_objectFilePath, FileMode.Create);
221190
objectWriter.EmitObject(stream, _nodes, dumper: null, logger);
@@ -300,6 +269,34 @@ public void EmitReadyToRunObjects(ReadyToRunContainerFormat format, Logger logge
300269
}
301270
}
302271

272+
private PEObjectWriter CreatePEObjectWriter()
273+
{
274+
int? timeDateStamp;
275+
276+
if (_nodeFactory.CompilationModuleGroup.IsCompositeBuildMode && _componentModule == null)
277+
{
278+
timeDateStamp = null;
279+
}
280+
else
281+
{
282+
PEReader inputPeReader = (_componentModule != null ? _componentModule.PEReader : _nodeFactory.CompilationModuleGroup.CompilationModuleSet.First().PEReader);
283+
timeDateStamp = inputPeReader.PEHeaders.CoffHeader.TimeDateStamp;
284+
}
285+
286+
PEObjectWriter objectWriter = new(_nodeFactory, ObjectWritingOptions.None, _outputInfoBuilder, _objectFilePath, _customPESectionAlignment, timeDateStamp);
287+
288+
if (_nodeFactory.CompilationModuleGroup.IsCompositeBuildMode && _componentModule == null)
289+
{
290+
objectWriter.AddExportedSymbol("RTR_HEADER");
291+
}
292+
return objectWriter;
293+
}
294+
295+
private MachObjectWriter CreateMachObjectWriter()
296+
{
297+
return new MachObjectWriter(_nodeFactory, ObjectWritingOptions.None, _outputInfoBuilder, baseSymbolName: "__mh_dylib_header");
298+
}
299+
303300
public static void EmitObject(
304301
string objectFilePath,
305302
EcmaModule componentModule,
@@ -319,7 +316,7 @@ public static void EmitObject(
319316
int customPESectionAlignment,
320317
Logger logger)
321318
{
322-
Console.WriteLine($@"Emitting R2R PE file: {objectFilePath}");
319+
Console.WriteLine($@"Emitting R2R {format} file: {objectFilePath}");
323320
ReadyToRunObjectWriter objectWriter = new ReadyToRunObjectWriter(
324321
objectFilePath,
325322
componentModule,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,21 @@ private void RewriteComponentFile(string inputFile, string outputFile, string ow
469469

470470
flags |= _nodeFactory.CompilationModuleGroup.GetReadyToRunFlags() & ReadyToRunFlags.READYTORUN_FLAG_MultiModuleVersionBubble;
471471

472+
bool isNativeCompositeImage = false;
473+
if (NodeFactory.Target.IsWindows && NodeFactory.Format == ReadyToRunContainerFormat.PE)
474+
{
475+
isNativeCompositeImage = true;
476+
}
477+
else if (NodeFactory.Target.IsApplePlatform && NodeFactory.Format == ReadyToRunContainerFormat.MachO)
478+
{
479+
isNativeCompositeImage = true;
480+
}
481+
482+
if (isNativeCompositeImage)
483+
{
484+
flags |= ReadyToRunFlags.READYTORUN_FLAG_PlatformNativeImage;
485+
}
486+
472487
CopiedCorHeaderNode copiedCorHeader = new CopiedCorHeaderNode(inputModule);
473488
// Re-written components shouldn't have any additional diagnostic information - only information about the forwards.
474489
// Even with all of this, we might be modifying the image in a silly manner - adding a directory when if didn't have one.

0 commit comments

Comments
 (0)