[lld] r233765 - ELF: Fix dereferencing end() iterator.
Rui Ueyama
ruiu at google.com
Tue Mar 31 15:08:43 PDT 2015
Author: ruiu
Date: Tue Mar 31 17:08:43 2015
New Revision: 233765
URL: http://llvm.org/viewvc/llvm-project?rev=233765&view=rev
Log:
ELF: Fix dereferencing end() iterator.
findAbsoluteAtom() returns absoluteAtom().end() if no atom is found.
Dereferencing end() value results an undefined behavior.
Modified:
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h?rev=233765&r1=233764&r2=233765&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Tue Mar 31 17:08:43 2015
@@ -30,8 +30,7 @@ public:
};
HexagonTargetLayout(HexagonLinkingContext &hti)
- : TargetLayout<HexagonELFType>(hti), _sdataSection(nullptr),
- _gotSymAtom(nullptr), _cachedGotSymAtom(false) {
+ : TargetLayout<HexagonELFType>(hti), _sdataSection() {
_sdataSection = new (_alloc) SDataSection<HexagonELFType>(hti);
}
@@ -84,21 +83,19 @@ public:
}
uint64_t getGOTSymAddr() {
- if (!_cachedGotSymAtom) {
- auto gotAtomIter = this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
- _gotSymAtom = (*gotAtomIter);
- _cachedGotSymAtom = true;
+ if (!_gotSymAtom.hasValue()) {
+ auto iter = this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
+ _gotSymAtom = (iter == this->absoluteAtoms().end()) ? nullptr : *iter;
}
- if (_gotSymAtom)
- return _gotSymAtom->_virtualAddr;
+ if (*_gotSymAtom)
+ return (*_gotSymAtom)->_virtualAddr;
return 0;
}
private:
llvm::BumpPtrAllocator _alloc;
- SDataSection<HexagonELFType> *_sdataSection;
- AtomLayout *_gotSymAtom;
- bool _cachedGotSymAtom;
+ SDataSection<HexagonELFType> *_sdataSection = nullptr;
+ llvm::Optional<AtomLayout *> _gotSymAtom;
};
/// \brief TargetHandler for Hexagon
More information about the llvm-commits
mailing list