Enable identical code folding on Linux#87045
Enable identical code folding on Linux#87045MichalStrehovsky wants to merge 2 commits intodotnet:mainfrom
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.
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). |
| <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.
| <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:
.textsection, so let's just do the same.I also found out why
--foldmethodbodiesdoesn't work outside Windows - we place managed code into a__managedcodesection and Linux linkers won't fold sections that have names that are valid C identifiers (would need to name this.managedcodelike 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