[llvm] 1a6bf94 - [MC] Remove ELFRelocationEntry::OriginalAddend
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 18 15:47:43 PDT 2024
Author: Fangrui Song
Date: 2024-08-18T15:47:38-07:00
New Revision: 1a6bf94407af7962345ffaf6ac9e9a9766fd8913
URL: https://github.com/llvm/llvm-project/commit/1a6bf94407af7962345ffaf6ac9e9a9766fd8913
DIFF: https://github.com/llvm/llvm-project/commit/1a6bf94407af7962345ffaf6ac9e9a9766fd8913.diff
LOG: [MC] Remove ELFRelocationEntry::OriginalAddend
For MIPS's o32 ABI (REL), https://reviews.llvm.org/D19718 introduced
`OriginalAddend` to find the matching R_MIPS_LO16 relocation for
R_MIPS_GOT16 when STT_SECTION conversion is applicable.
lw $2, %lo(local1)
lui $2, %got(local1)
However, we could just store the original `Addend` in
`ELFRelocationEntry` and remove `OriginalAddend`.
Note: The relocation ordering algorithm in
https://reviews.llvm.org/D19718 is inefficient (#104562), which will be
addressed by another patch.
Added:
Modified:
llvm/include/llvm/MC/MCELFObjectWriter.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 3b418083eecceb..d17fc931d1561c 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -38,18 +38,15 @@ struct ELFRelocationEntry {
unsigned Type; // The type of the relocation.
uint64_t Addend; // The addend to use.
const MCSymbolELF *OriginalSymbol; // The original value of Symbol if we changed it.
- uint64_t OriginalAddend; // The original value of addend.
ELFRelocationEntry(uint64_t Offset, const MCSymbolELF *Symbol, unsigned Type,
- uint64_t Addend, const MCSymbolELF *OriginalSymbol,
- uint64_t OriginalAddend)
+ uint64_t Addend, const MCSymbolELF *OriginalSymbol)
: Offset(Offset), Symbol(Symbol), Type(Type), Addend(Addend),
- OriginalSymbol(OriginalSymbol), OriginalAddend(OriginalAddend) {}
+ OriginalSymbol(OriginalSymbol) {}
void print(raw_ostream &Out) const {
Out << "Off=" << Offset << ", Sym=" << Symbol << ", Type=" << Type
- << ", Addend=" << Addend << ", OriginalSymbol=" << OriginalSymbol
- << ", OriginalAddend=" << OriginalAddend;
+ << ", Addend=" << Addend << ", OriginalSymbol=" << OriginalSymbol;
}
LLVM_DUMP_METHOD void dump() const { print(errs()); }
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 7a8a6c8daf9593..35d0a2eb52dfc7 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1443,22 +1443,17 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
bool RelocateWithSymbol =
shouldRelocateWithSymbol(Asm, Target, SymA, C, Type) ||
(Parent->getType() == ELF::SHT_LLVM_CALL_GRAPH_PROFILE);
- uint64_t Addend = 0;
-
- FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()
- ? C + Asm.getSymbolOffset(*SymA)
- : C;
- if (usesRela(TO, FixupSection)) {
- Addend = FixedValue;
- FixedValue = 0;
- }
+ uint64_t Addend = !RelocateWithSymbol && SymA && !SymA->isUndefined()
+ ? C + Asm.getSymbolOffset(*SymA)
+ : C;
+ FixedValue = usesRela(TO, FixupSection) ? 0 : Addend;
if (!RelocateWithSymbol) {
const auto *SectionSymbol =
SecA ? cast<MCSymbolELF>(SecA->getBeginSymbol()) : nullptr;
if (SectionSymbol)
SectionSymbol->setUsedInReloc();
- ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend, SymA, C);
+ ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend, SymA);
Relocations[&FixupSection].push_back(Rec);
return;
}
@@ -1473,7 +1468,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
else
RenamedSymA->setUsedInReloc();
}
- ELFRelocationEntry Rec(FixupOffset, RenamedSymA, Type, Addend, SymA, C);
+ ELFRelocationEntry Rec(FixupOffset, RenamedSymA, Type, Addend, SymA);
Relocations[&FixupSection].push_back(Rec);
}
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 1f047020d96c80..19b6bf0da22a60 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -166,10 +166,9 @@ static FindBestPredicateResult isMatchingReloc(const MipsRelocationEntry &X,
const ELFRelocationEntry &R,
unsigned MatchingType) {
if (X.R.Type == MatchingType && X.R.OriginalSymbol == R.OriginalSymbol) {
- if (!X.Matched &&
- X.R.OriginalAddend == R.OriginalAddend)
+ if (!X.Matched && X.R.Addend == R.Addend)
return FindBest_PerfectMatch;
- else if (X.R.OriginalAddend >= R.OriginalAddend)
+ else if (X.R.Addend >= R.Addend)
return FindBest_Match;
}
return FindBest_NoMatch;
@@ -183,8 +182,8 @@ static FindBestPredicateResult isMatchingReloc(const MipsRelocationEntry &X,
/// - It is not already involved in a match.
static bool compareMatchingRelocs(const MipsRelocationEntry &Candidate,
const MipsRelocationEntry &PreviousBest) {
- if (Candidate.R.OriginalAddend != PreviousBest.R.OriginalAddend)
- return Candidate.R.OriginalAddend < PreviousBest.R.OriginalAddend;
+ if (Candidate.R.Addend != PreviousBest.R.Addend)
+ return Candidate.R.Addend < PreviousBest.R.Addend;
return PreviousBest.Matched && !Candidate.Matched;
}
More information about the llvm-commits
mailing list