[PATCH] D159177: [BOLT] Fix a bug related to iterators in ReorderData pass
Sinan Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 01:17:23 PDT 2023
sinan created this revision.
sinan added reviewers: Amir, maksfb.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a project: All.
sinan requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.
If `Itr` is the last element then `std::next(Itr)` will be `Range.end()`, so that the statement `std::next(Itr)->second` is a UB.
I encountered a segmentation fault in test "reorder-data-writable-ptload.c" with my llvm-bolt linked against static libc++.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159177
Files:
bolt/lib/Passes/ReorderData.cpp
Index: bolt/lib/Passes/ReorderData.cpp
===================================================================
--- bolt/lib/Passes/ReorderData.cpp
+++ bolt/lib/Passes/ReorderData.cpp
@@ -413,17 +413,17 @@
auto Range = BC.getBinaryDataForSection(Section);
bool FoundUnmoveable = false;
for (auto Itr = Range.begin(); Itr != Range.end(); ++Itr) {
+ BinaryData *Next =
+ std::next(Itr) != Range.end() ? std::next(Itr)->second : nullptr;
if (Itr->second->getName().startswith("PG.")) {
BinaryData *Prev =
Itr != Range.begin() ? std::prev(Itr)->second : nullptr;
- BinaryData *Next = Itr != Range.end() ? std::next(Itr)->second : nullptr;
bool PrevIsPrivate = Prev && isPrivate(Prev);
bool NextIsPrivate = Next && isPrivate(Next);
if (isPrivate(Itr->second) && (PrevIsPrivate || NextIsPrivate))
Itr->second->setIsMoveable(false);
} else {
// check for overlapping symbols.
- BinaryData *Next = Itr != Range.end() ? std::next(Itr)->second : nullptr;
if (Next && Itr->second->getEndAddress() != Next->getAddress() &&
Next->containsAddress(Itr->second->getEndAddress())) {
Itr->second->setIsMoveable(false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159177.554620.patch
Type: text/x-patch
Size: 1217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230830/7153ee64/attachment.bin>
More information about the llvm-commits
mailing list