Skip to content

Commit

Permalink
[NativeAOT] Enable -dead_strip linker optimization by default on Appl…
Browse files Browse the repository at this point in the history
…e platforms (#103039)

Fixes #96663
  • Loading branch information
ivanpovazan authored Jun 13, 2024
1 parent 778b3ed commit d9a6607
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CustomLinkerArg Include="-exported_symbols_list /dev/null" Condition="'$(OutputType)' == 'exe' and '$(_IsApplePlatform)' == 'true' and '$(ExportsFile)' == ''" />
<CustomLinkerArg Include="-Wl,--version-script=$(ExportsFile)" Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true' and '$(ExportsFile)' != ''" />
<CustomLinkerArg Include="-Wl,--export-dynamic" Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true' and '$(ExportsFile)' != ''" />
<CustomLinkerArg Include="-Wl,-dead_strip" Condition="'$(_IsApplePlatform)' == 'true'" />
<CustomLinkerArg Include="@(LinkerArg)" />
</ItemGroup>
<ItemGroup Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,15 @@ private protected override void EmitSymbolTable(
foreach ((string name, SymbolDefinition definition) in definedSymbols)
{
MachSection section = _sections[definition.SectionIndex];
// Sections in our object file should not be altered during native linking as the runtime
// depends on the layout generated during compilation. For this reason we mark all symbols
// with N_NO_DEAD_STRIP to prevent breaking up sections into subsections during linking.
sortedDefinedSymbols.Add(new MachSymbol
{
Name = name,
Section = section,
Value = section.VirtualAddress + (ulong)definition.Value,
Descriptor = 0,
Descriptor = N_NO_DEAD_STRIP,
Type = N_SECT | N_EXT,
});
}
Expand Down

0 comments on commit d9a6607

Please sign in to comment.