[lld] 5dbbd4e - [ELF] Move OffsetGetter before some static functions. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 10 20:16:07 PST 2022
Author: Fangrui Song
Date: 2022-01-10T20:16:02-08:00
New Revision: 5dbbd4eeb8c47d82d3acd804d0e2961be6914b4f
URL: https://github.com/llvm/llvm-project/commit/5dbbd4eeb8c47d82d3acd804d0e2961be6914b4f
DIFF: https://github.com/llvm/llvm-project/commit/5dbbd4eeb8c47d82d3acd804d0e2961be6914b4f.diff
LOG: [ELF] Move OffsetGetter before some static functions. NFC
to prepare for D116881.
Added:
Modified:
lld/ELF/Relocations.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 7dbefaf7d93e2..c3161a793a420 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -403,6 +403,52 @@ static void addCopyRelSymbol(SharedSymbol &ss) {
}
}
+// .eh_frame sections are mergeable input sections, so their input
+// offsets are not linearly mapped to output section. For each input
+// offset, we need to find a section piece containing the offset and
+// add the piece's base address to the input offset to compute the
+// output offset. That isn't cheap.
+//
+// This class is to speed up the offset computation. When we process
+// relocations, we access offsets in the monotonically increasing
+// order. So we can optimize for that access pattern.
+//
+// For sections other than .eh_frame, this class doesn't do anything.
+namespace {
+class OffsetGetter {
+public:
+ explicit OffsetGetter(InputSectionBase &sec) {
+ if (auto *eh = dyn_cast<EhInputSection>(&sec))
+ pieces = eh->pieces;
+ }
+
+ // Translates offsets in input sections to offsets in output sections.
+ // Given offset must increase monotonically. We assume that Piece is
+ // sorted by inputOff.
+ uint64_t get(uint64_t off) {
+ if (pieces.empty())
+ return off;
+
+ while (i != pieces.size() && pieces[i].inputOff + pieces[i].size <= off)
+ ++i;
+ if (i == pieces.size())
+ fatal(".eh_frame: relocation is not in any piece");
+
+ // Pieces must be contiguous, so there must be no holes in between.
+ assert(pieces[i].inputOff <= off && "Relocation not in any piece");
+
+ // Offset -1 means that the piece is dead (i.e. garbage collected).
+ if (pieces[i].outputOff == -1)
+ return -1;
+ return pieces[i].outputOff + off - pieces[i].inputOff;
+ }
+
+private:
+ ArrayRef<EhSectionPiece> pieces;
+ size_t i = 0;
+};
+} // namespace
+
// MIPS has an odd notion of "paired" relocations to calculate addends.
// For example, if a relocation is of R_MIPS_HI16, there must be a
// R_MIPS_LO16 relocation after that, and an addend is calculated using
@@ -786,52 +832,6 @@ template <class RelTy> static RelType getMipsN32RelType(RelTy *&rel, RelTy *end)
return type;
}
-// .eh_frame sections are mergeable input sections, so their input
-// offsets are not linearly mapped to output section. For each input
-// offset, we need to find a section piece containing the offset and
-// add the piece's base address to the input offset to compute the
-// output offset. That isn't cheap.
-//
-// This class is to speed up the offset computation. When we process
-// relocations, we access offsets in the monotonically increasing
-// order. So we can optimize for that access pattern.
-//
-// For sections other than .eh_frame, this class doesn't do anything.
-namespace {
-class OffsetGetter {
-public:
- explicit OffsetGetter(InputSectionBase &sec) {
- if (auto *eh = dyn_cast<EhInputSection>(&sec))
- pieces = eh->pieces;
- }
-
- // Translates offsets in input sections to offsets in output sections.
- // Given offset must increase monotonically. We assume that Piece is
- // sorted by inputOff.
- uint64_t get(uint64_t off) {
- if (pieces.empty())
- return off;
-
- while (i != pieces.size() && pieces[i].inputOff + pieces[i].size <= off)
- ++i;
- if (i == pieces.size())
- fatal(".eh_frame: relocation is not in any piece");
-
- // Pieces must be contiguous, so there must be no holes in between.
- assert(pieces[i].inputOff <= off && "Relocation not in any piece");
-
- // Offset -1 means that the piece is dead (i.e. garbage collected).
- if (pieces[i].outputOff == -1)
- return -1;
- return pieces[i].outputOff + off - pieces[i].inputOff;
- }
-
-private:
- ArrayRef<EhSectionPiece> pieces;
- size_t i = 0;
-};
-} // namespace
-
static void addRelativeReloc(InputSectionBase &isec, uint64_t offsetInSec,
Symbol &sym, int64_t addend, RelExpr expr,
RelType type) {
More information about the llvm-commits
mailing list