Skip to content

Commit 9e807d9

Browse files
committed
Hook up emitting the Mach-O format with the expectation of getting put into a dylib.
1 parent e0560e9 commit 9e807d9

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

src/coreclr/tools/Common/Compiler/ObjectWriter/MachObjectWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ internal sealed partial class MachObjectWriter : UnixObjectWriter
7272
/// </summary>
7373
private readonly string _baseSymbolName;
7474

75-
public MachObjectWriter(NodeFactory factory, ObjectWritingOptions options)
76-
: base(factory, options)
75+
public MachObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder = null)
76+
: base(factory, options, outputInfoBuilder)
7777
{
7878
switch (factory.Target.Architecture)
7979
{
@@ -98,8 +98,8 @@ public MachObjectWriter(NodeFactory factory, ObjectWritingOptions options)
9898
_targetOS = factory.Target.OperatingSystem;
9999
}
100100

101-
public MachObjectWriter(NodeFactory factory, ObjectWritingOptions options, string baseSymbolName)
102-
: this(factory, options)
101+
public MachObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder, string baseSymbolName)
102+
: this(factory, options, outputInfoBuilder)
103103
{
104104
_baseSymbolName = baseSymbolName;
105105
}

src/coreclr/tools/Common/Compiler/ObjectWriter/UnixObjectWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ private sealed record UnixSectionDefinition(string SymbolName, Stream SectionStr
2525
private static readonly ObjectNodeSection LsdaSection = new ObjectNodeSection(".dotnet_eh_table", SectionType.ReadOnly);
2626
private static readonly ObjectNodeSection EhFrameSection = new ObjectNodeSection(".eh_frame", SectionType.UnwindData);
2727

28-
protected UnixObjectWriter(NodeFactory factory, ObjectWritingOptions options)
29-
: base(factory, options)
28+
protected UnixObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder = null)
29+
: base(factory, options, outputInfoBuilder)
3030
{
3131
}
3232

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ILCompiler.DependencyAnalysis
99
{
1010
public enum ReadyToRunContainerFormat
1111
{
12-
PE
12+
PE,
13+
MachO,
1314
}
1415
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,28 @@ public void EmitReadyToRunObjects(ReadyToRunContainerFormat format, Logger logge
193193
timeDateStamp = inputPeReader.PEHeaders.CoffHeader.TimeDateStamp;
194194
}
195195

196-
PEObjectWriter objectWriter = new(_nodeFactory, ObjectWritingOptions.None, _outputInfoBuilder, _objectFilePath, _customPESectionAlignment, timeDateStamp);
196+
ObjectWriter.ObjectWriter objectWriter;
197197

198-
if (_nodeFactory.CompilationModuleGroup.IsCompositeBuildMode && _componentModule == null)
198+
if (format == ReadyToRunContainerFormat.PE)
199+
{
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
199216
{
200-
objectWriter.AddExportedSymbol("RTR_HEADER");
217+
throw new UnreachableException();
201218
}
202219

203220
using FileStream stream = new FileStream(_objectFilePath, FileMode.Create);

src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ private static ReadyToRunContainerFormat MakeOutputFormat(ArgumentResult result)
415415
return result.Tokens[0].Value.ToLowerInvariant() switch
416416
{
417417
"pe" => ReadyToRunContainerFormat.PE,
418+
"macho" => ReadyToRunContainerFormat.MachO,
418419
_ => throw new CommandLineException(SR.InvalidOutputFormat)
419420
};
420421
}

0 commit comments

Comments
 (0)