Skip to content

Commit 1f2628a

Browse files
committed
Enable dead stripping of NativeAOT executables on Apple platforms
1 parent 9fca0c3 commit 1f2628a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ The .NET Foundation licenses this file to you under the MIT license.
341341
<CustomLinkerArg Include="-exported_symbols_list /dev/null" Condition="'$(OutputType)' == 'exe' and '$(_IsApplePlatform)' == 'true' and '$(ExportsFile)' == ''" />
342342
<CustomLinkerArg Include="-Wl,--version-script=$(ExportsFile)" Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true' and '$(ExportsFile)' != ''" />
343343
<CustomLinkerArg Include="-Wl,--export-dynamic" Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true' and '$(ExportsFile)' != ''" />
344+
<CustomLinkerArg Include="-Wl,-dead_strip" Condition="'$(_IsApplePlatform)' == 'true'" />
344345
<CustomLinkerArg Include="@(LinkerArg)" />
345346
</ItemGroup>
346347
<ItemGroup Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true'">

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/MachObjectWriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,15 @@ private protected override void EmitSymbolTable(
475475
foreach ((string name, SymbolDefinition definition) in definedSymbols)
476476
{
477477
MachSection section = _sections[definition.SectionIndex];
478+
// Sections in our object file should not be altered during native linking as the runtime
479+
// depends on the layout generated during compilation. For this reason we mark all symbols
480+
// with N_NO_DEAD_STRIP to prevent breaking up sections into subsections during linking.
478481
sortedDefinedSymbols.Add(new MachSymbol
479482
{
480483
Name = name,
481484
Section = section,
482485
Value = section.VirtualAddress + (ulong)definition.Value,
483-
Descriptor = 0,
486+
Descriptor = N_NO_DEAD_STRIP,
484487
Type = N_SECT | N_EXT,
485488
});
486489
}

0 commit comments

Comments
 (0)