Uh oh!
There was an error while loading. Please reload this page.
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.
ghost
commented
Jun 2, 2023
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?
filipnavara
commented
Jun 2, 2023
Can we run the NativeAOT extras pipeline for this? There's lot of quirks with |
MichalStrehovsky
commented
Jun 2, 2023
/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.
| <LinkerArgInclude="-Wl,--icf=all"Condition="'$(LinkerFlavor)' == 'lld' or '$(LinkerFlavor)' == 'gold'" /> | |
| <LinkerArgInclude="-Wl,--icf=all"Condition="'$(_IsApplePlatform)' != 'true' and '$(LinkerFlavor)' != 'bfd'" /> |
as moldalso 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