-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable identical code folding on Linux #87045
Conversation
This instructs the linker to deduplicate identical sections on Linux. We were previously not doing this for two reasons: 1. We weren't passing the command line switch. 2. We had trouble getting linker to actually fold things. Linux linkers are particularly picky on what they're willing to fold. We've been historically putting these things to RW sections (dotnet/corert#686) and that doesn't help. Looking at C++, it looks like it places vtables into `.text` section, so let's just do the same. I also found out why `--foldmethodbodies` doesn't work outside Windows - we place managed code into a `__managedcode` section and Linux linkers won't fold sections that have names that are valid C identifiers (would need to name this `.managedcode` like on Windows) - https://github.com/dotnet/llvm-project/blob/c01ca3bc8a420b3796d816c43bdd06e337c72ea6/lld/ELF/ICF.cpp#L192. Not addressing that part because the whole thing looks like a hairy yak and this option is not supported anyway.
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsThis instructs the linker to deduplicate identical sections on Linux. We were previously not doing this for two reasons:
I also found out why Cc @dotnet/ilc-contrib
|
After the second commit this is just an okay saving:
|
@@ -19,7 +19,7 @@ public override ObjectNodeSection GetSection(NodeFactory factory) | |||
if (factory.Target.IsWindows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we extract this piece of logic into a helper method on ObjectNodeSection
or NodeFactory
so that we do not need to fix up a bunch of places everytime a new right way to do foldable readonly data sections shows up?
Can we run the NativeAOT extras pipeline for this? There's lot of quirks with |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -151,6 +151,7 @@ The .NET Foundation licenses this file to you under the MIT license. | |||
<LinkerArg Include="-Wl,-segprot,__THUNKS,rx,rx" Condition="'$(_IsiOSLikePlatform)' == 'true'" /> | |||
<LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(_IsApplePlatform)' == 'true'" /> | |||
<LinkerArg Include="-Wl,--eh-frame-hdr" Condition="'$(_IsApplePlatform)' != 'true'" /> | |||
<LinkerArg Include="-Wl,--icf=all" Condition="'$(LinkerFlavor)' == 'lld' or '$(LinkerFlavor)' == 'gold'" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<LinkerArg Include="-Wl,--icf=all" Condition="'$(LinkerFlavor)' == 'lld' or '$(LinkerFlavor)' == 'gold'" /> | |
<LinkerArg Include="-Wl,--icf=all" Condition="'$(_IsApplePlatform)' != 'true' and '$(LinkerFlavor)' != 'bfd'" /> |
as mold
also supports it.
Extracting a piece of dotnet#87045 that I had to revert in that PR. Native linkers don't like when LSDA is in a COMDAT so fold these in the object writer instead. Seems to save about 1.2% in the Stage1 app. Obviously Unix only.
Extracting a piece of #87045 that I had to revert in that PR. Native linkers don't like when LSDA is in a COMDAT so fold these in the object writer instead. Seems to save about 1.2% in the Stage1 app. Obviously Unix only.
This instructs the linker to deduplicate identical sections on Linux. We were previously not doing this for two reasons:
.text
section, so let's just do the same.I also found out why
--foldmethodbodies
doesn't work outside Windows - we place managed code into a__managedcode
section and Linux linkers won't fold sections that have names that are valid C identifiers (would need to name this.managedcode
like on Windows) - https://github.com/dotnet/llvm-project/blob/c01ca3bc8a420b3796d816c43bdd06e337c72ea6/lld/ELF/ICF.cpp#L192. Not addressing that part because the whole thing looks like a hairy yak and this option is not supported anyway.Cc @dotnet/ilc-contrib