lld: Target-specific section-folding logic for ICF#133990
Open
lld: Target-specific section-folding logic for ICF#133990
Conversation
This is needed when for AArch64 we try to fold two sections with unpaired ADRP/LDR relocations.
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- lld/ELF/Arch/AArch64.cpp lld/ELF/ICF.cpp lld/ELF/Target.hView the diff from clang-format here.diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index b42711a81..23a670c9d 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -982,11 +982,12 @@ void AArch64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
bool AArch64::canFoldSection(const SmallVector<Relocation> &relocs) const {
// Section cannot be folded as part of ICF if it contains unpaired relocations
// eg: ADR_GOT_PAGE and LD64_GOT_LO12_NC don't point to same symbol.
- SmallSet<Symbol*, 4> syms;
+ SmallSet<Symbol *, 4> syms;
for (const Relocation &reloc : relocs) {
if (reloc.type == R_AARCH64_ADR_GOT_PAGE)
syms.insert(reloc.sym);
- else if (reloc.type == R_AARCH64_LD64_GOT_LO12_NC && !syms.contains(reloc.sym))
+ else if (reloc.type == R_AARCH64_LD64_GOT_LO12_NC &&
+ !syms.contains(reloc.sym))
return false;
}
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 4493ba4a0..846aed50d 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -322,7 +322,8 @@ bool ICF<ELFT>::constantEq(const InputSection *secA, Relocs<RelTy> ra,
}
// Target-specific section-folding logic based on section's relocation list
- if (!ctx.target->canFoldSection(relocsA) || !ctx.target->canFoldSection(relocsB))
+ if (!ctx.target->canFoldSection(relocsA) ||
+ !ctx.target->canFoldSection(relocsB))
return false;
return true;
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 169bd17ec..76c3d4a39 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -102,8 +102,11 @@ public:
virtual void applyJumpInstrMod(uint8_t *loc, JumpModType type,
JumpModType val) const {}
- // Used by ICF to determine if section full of @relocs can be folded safely with another
- virtual bool canFoldSection(const SmallVector<Relocation> &relocs) const { return true; }
+ // Used by ICF to determine if section full of @relocs can be folded safely
+ // with another
+ virtual bool canFoldSection(const SmallVector<Relocation> &relocs) const {
+ return true;
+ }
virtual ~TargetInfo();
|
pranavk
commented
Apr 1, 2025
| rai->getType(ctx.arg.isMips64EL), 0, addA, &sa}); | ||
| relocsB.push_back( | ||
| {ctx.target->getRelExpr(rbi->getType(ctx.arg.isMips64EL), sb, 0), | ||
| rbi->getType(ctx.arg.isMips64EL), 0, addB, &sb}); |
Contributor
Author
There was a problem hiding this comment.
happy to either only pass rel.type and Symbol to TargetInfo::canFoldSection but passing Relocation sounded better to me.
smithp35
reviewed
Apr 2, 2025
Collaborator
smithp35
left a comment
There was a problem hiding this comment.
Thanks for making the patch!
It sounds like #131630 (comment) might end up with a different approach. I'll wait to see if that succeeds before commenting on the details here. There are some more relocation types we'd need to add to canFoldSection for example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is needed for AArch64 when we try to fold two sections with unpaired ADRP/LDR relocations in them.