Skip to content

Commit

Permalink
Re-enable gc-sections with lld for NativeAOT (#84935)
Browse files Browse the repository at this point in the history
* Revert "Revert "Write linker script for lld to enable gc-sections (#84493)""

This reverts the revert of commit 3ab663e.
The revert of that commit was included in 887c043.

* Lower the lld version requirement

* Adjust dwarfdump baseline

---------

Co-authored-by: Adeel <3840695+am11@users.noreply.github.com>
  • Loading branch information
sbomer and am11 authored Apr 17, 2023
1 parent 07834fd commit 410aa0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ The .NET Foundation licenses this file to you under the MIT license.
<Error Condition="'$(_WhereLinker)' != '0' and '$(CppCompilerAndLinkerAlternative)' == '' and '$(_IsApplePlatform)' != 'true'"
Text="Requested linker ('$(CppLinker)') not found in PATH." />

<Exec Command="&quot;$(CppLinker)&quot; -fuse-ld=lld -Wl,--version" Condition="'$(LinkerFlavor)' == 'lld'" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">
<Output TaskParameter="ExitCode" PropertyName="_LinkerVersionStringExitCode" />
<Output TaskParameter="ConsoleOutput" PropertyName="_LinkerVersionString" />
</Exec>

<PropertyGroup Condition="'$(_LinkerVersionStringExitCode)' == '0' and '$(_LinkerVersionString)' != ''">
<_LinkerVersion>$([System.Text.RegularExpressions.Regex]::Match($(_LinkerVersionString), '[1-9]\d*'))</_LinkerVersion>
</PropertyGroup>

<Exec Command="command -v &quot;$(ObjCopyName)&quot;" IgnoreExitCode="true" StandardOutputImportance="Low" Condition="'$(_IsApplePlatform)' != 'true' and '$(StripSymbols)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="_WhereSymbolStripper" />
</Exec>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ The .NET Foundation licenses this file to you under the MIT license.
</ItemGroup>
<ItemGroup Condition="'$(_targetOS)' != 'win' and '$(_IsApplePlatform)' != 'true'">
<CustomLinkerArg Include="-Wl,--discard-all" />
<CustomLinkerArg Include="-Wl,--gc-sections" Condition="'$(LinkerFlavor)' == '' or '$(LinkerFlavor)' == 'bfd'" />
<CustomLinkerArg Include="-Wl,--gc-sections" Condition="'$(LinkerFlavor)' == '' or '$(LinkerFlavor)' == 'bfd' or '$(LinkerFlavor)' == 'lld'" />
<CustomLinkerArg Include="-Wl,-T,&quot;$(NativeIntermediateOutputPath)sections.ld&quot;" Condition="'$(LinkerFlavor)' == 'lld' and '$(_LinkerVersion)' &gt; '12'" />
</ItemGroup>
<ItemGroup>
<CustomLibArg Include="-crs &quot;$(NativeBinary)&quot;" Condition="'$(_targetOS)' != 'win'" />
Expand All @@ -335,6 +336,9 @@ The .NET Foundation licenses this file to you under the MIT license.
<StripFlag Condition="'$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">-x</StripFlag> <!-- keep global symbols in dylib -->
</PropertyGroup>

<!-- write linker script for lld (13+) to retain the __modules section -->
<WriteLinesToFile File="$(NativeIntermediateOutputPath)sections.ld" Lines="OVERWRITE_SECTIONS { __modules : { KEEP(*(__modules)) } }" Overwrite="true" Condition="'$(LinkerFlavor)' == 'lld' and '$(_LinkerVersion)' &gt; '12'" />

<Exec Command="&quot;$(CppLinker)&quot; @(CustomLinkerArg, ' ')" Condition="'$(_targetOS)' != 'win' and '$(NativeLib)' != 'Static'" IgnoreStandardErrorWarningFormat="$(_IgnoreLinkerWarnings)" />
<Exec Command="&quot;$(CppLibCreator)&quot; @(CustomLibArg, ' ')" Condition="'$(_targetOS)' != 'win' and '$(NativeLib)' == 'Static'" />

Expand Down
4 changes: 2 additions & 2 deletions src/tests/nativeaot/SmokeTests/DwarfDump/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public static int Main(string[] args)
const int MinWarnings = 16500;
const int MaxWarnings = 18500;
#else
const int MinWarnings = 9500;
const int MaxWarnings = 10500;
const int MinWarnings = 12000;
const int MaxWarnings = 13000;
#endif
int count = 0;
string line;
Expand Down

0 comments on commit 410aa0a

Please sign in to comment.