[PATCH] D51180: [LLD] Check for too large offsets into merge sections earlier to avoid DenseMap tombstone collision
ben via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 31 04:55:19 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341206: [LLD] Check too large offsets into merge sections earlier (authored by bd1976llvm, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D51180?vs=162251&id=163508#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51180
Files:
lld/trunk/ELF/InputSection.cpp
lld/trunk/test/ELF/merge-string-error.s
lld/trunk/test/ELF/relocation-past-merge-end.s
Index: lld/trunk/test/ELF/merge-string-error.s
===================================================================
--- lld/trunk/test/ELF/merge-string-error.s
+++ lld/trunk/test/ELF/merge-string-error.s
@@ -8,4 +8,4 @@
.data
.long .rodata.str1.1 + 4
-// CHECK: merge-string-error.s.tmp.o:(.rodata.str1.1): entry is past the end of the section
+// CHECK: merge-string-error.s.tmp.o:(.rodata.str1.1): offset is outside the section
Index: lld/trunk/test/ELF/relocation-past-merge-end.s
===================================================================
--- lld/trunk/test/ELF/relocation-past-merge-end.s
+++ lld/trunk/test/ELF/relocation-past-merge-end.s
@@ -1,7 +1,7 @@
// REQUIRES: x86
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s
-// CHECK: relocation-past-merge-end.s.tmp.o:(.foo): entry is past the end of the section
+// CHECK: relocation-past-merge-end.s.tmp.o:(.foo): offset is outside the section
.data
.long .foo + 10
Index: lld/trunk/ELF/InputSection.cpp
===================================================================
--- lld/trunk/ELF/InputSection.cpp
+++ lld/trunk/ELF/InputSection.cpp
@@ -1149,43 +1149,32 @@
return Comp(Value, *First) ? First : First + 1;
}
-// Do binary search to get a section piece at a given input offset.
-static SectionPiece *findSectionPiece(MergeInputSection *Sec, uint64_t Offset) {
- if (Sec->Data.size() <= Offset)
- fatal(toString(Sec) + ": entry is past the end of the section");
-
- // Find the element this offset points to.
- auto I = fastUpperBound(
- Sec->Pieces.begin(), Sec->Pieces.end(), Offset,
- [](const uint64_t &A, const SectionPiece &B) { return A < B.InputOff; });
- --I;
- return &*I;
-}
-
SectionPiece *MergeInputSection::getSectionPiece(uint64_t Offset) {
+ if (this->Data.size() <= Offset)
+ fatal(toString(this) + ": offset is outside the section");
+
// Find a piece starting at a given offset.
auto It = OffsetMap.find(Offset);
if (It != OffsetMap.end())
return &Pieces[It->second];
// If Offset is not at beginning of a section piece, it is not in the map.
- // In that case we need to search from the original section piece vector.
- return findSectionPiece(this, Offset);
+ // In that case we need to do a binary search of the original section piece vector.
+ auto I = fastUpperBound(
+ Pieces.begin(), Pieces.end(), Offset,
+ [](const uint64_t &A, const SectionPiece &B) { return A < B.InputOff; });
+ --I;
+ return &*I;
}
// Returns the offset in an output section for a given input offset.
// Because contents of a mergeable section is not contiguous in output,
// it is not just an addition to a base output offset.
uint64_t MergeInputSection::getParentOffset(uint64_t Offset) const {
- // Find a string starting at a given offset.
- auto It = OffsetMap.find(Offset);
- if (It != OffsetMap.end())
- return Pieces[It->second].OutputOff;
-
// If Offset is not at beginning of a section piece, it is not in the map.
// In that case we need to search from the original section piece vector.
const SectionPiece &Piece =
- *findSectionPiece(const_cast<MergeInputSection *>(this), Offset);
+ *(const_cast<MergeInputSection *>(this)->getSectionPiece (Offset));
uint64_t Addend = Offset - Piece.InputOff;
return Piece.OutputOff + Addend;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51180.163508.patch
Type: text/x-patch
Size: 3424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180831/79746c73/attachment.bin>
More information about the llvm-commits
mailing list