[lld] r234269 - ELF: Do not return error from handleDefinedSymbol.
Rui Ueyama
ruiu at google.com
Mon Apr 6 18:00:21 PDT 2015
Author: ruiu
Date: Mon Apr 6 20:00:20 2015
New Revision: 234269
URL: http://llvm.org/viewvc/llvm-project?rev=234269&view=rev
Log:
ELF: Do not return error from handleDefinedSymbol.
handleDefinedSymbol has return type of ErrorOr<ELFDefinedAtom *>.
However, it never returns an error. We are not checking errors.
It's marked as ErrorOr "just in case". That's a bad engineering
practice.
This patch simplifies the return type of the function.
Modified:
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMELFFile.h
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMELFFile.h?rev=234269&r1=234268&r2=234269&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMELFFile.h Mon Apr 6 20:00:20 2015
@@ -81,12 +81,12 @@ private:
}
/// Process the Defined symbol and create an atom for it.
- ErrorOr<ELFDefinedAtom<ELFT> *> handleDefinedSymbol(StringRef symName,
- StringRef sectionName,
- const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
- ArrayRef<uint8_t> contentData,
- unsigned int referenceStart, unsigned int referenceEnd,
- std::vector<ELFReference<ELFT> *> &referenceList) override {
+ ELFDefinedAtom<ELFT> *
+ createDefinedAtom(StringRef symName, StringRef sectionName,
+ const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
+ ArrayRef<uint8_t> contentData, unsigned int referenceStart,
+ unsigned int referenceEnd,
+ std::vector<ELFReference<ELFT> *> &referenceList) override {
if (symName.size() >= 2 && symName[0] == '$') {
switch (symName[1]) {
case 'a':
@@ -106,7 +106,7 @@ private:
referenceStart, referenceEnd, referenceList);
default:
// Fall through and create regular defined atom.
- break;
+ break;
}
}
return new (this->_readerStorage) ARMELFDefinedAtom<ELFT>(
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=234269&r1=234268&r2=234269&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Mon Apr 6 20:00:20 2015
@@ -334,13 +334,13 @@ protected:
sym->getType() == llvm::ELF::STT_TLS);
}
- /// Process the Defined symbol and create an atom for it.
- virtual ErrorOr<ELFDefinedAtom<ELFT> *>
- handleDefinedSymbol(StringRef symName, StringRef sectionName,
- const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
- ArrayRef<uint8_t> contentData,
- unsigned int referenceStart, unsigned int referenceEnd,
- std::vector<ELFReference<ELFT> *> &referenceList) {
+ /// Creates an atom for a given defined symbol.
+ virtual ELFDefinedAtom<ELFT> *
+ createDefinedAtom(StringRef symName, StringRef sectionName,
+ const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
+ ArrayRef<uint8_t> contentData, unsigned int referenceStart,
+ unsigned int referenceEnd,
+ std::vector<ELFReference<ELFT> *> &referenceList) {
return new (_readerStorage) ELFDefinedAtom<ELFT>(
*this, symName, sectionName, sym, sectionHdr, contentData,
referenceStart, referenceEnd, referenceList);
@@ -789,14 +789,14 @@ template <class ELFT> std::error_code EL
// resolution
if (isMergeableStringSection(section)) {
if (symbol->getBinding() == llvm::ELF::STB_GLOBAL) {
- auto definedMergeAtom = handleDefinedSymbol(
+ ELFDefinedAtom<ELFT> *atom = createDefinedAtom(
symbolName, *sectionName, &**si, section, symbolData,
_references.size(), _references.size(), _references);
- (*definedMergeAtom)->setOrdinal(++_ordinal);
+ atom->setOrdinal(++_ordinal);
if (addAtoms)
- _definedAtoms._atoms.push_back(*definedMergeAtom);
+ _definedAtoms._atoms.push_back(atom);
else
- atomsForSection[*sectionName].push_back(*definedMergeAtom);
+ atomsForSection[*sectionName].push_back(atom);
}
continue;
}
@@ -891,13 +891,13 @@ std::error_code ELFFile<ELFT>::handleGnu
}
atomsForSection[signature].clear();
// Create a gnu linkonce atom.
- auto gnuLinkOnceAtom = handleDefinedSymbol(
+ ELFDefinedAtom<ELFT> *atom = createDefinedAtom(
signature, signature, nullptr, shdr, ArrayRef<uint8_t>(), referenceStart,
_references.size(), _references);
- (*gnuLinkOnceAtom)->setOrdinal(++_ordinal);
- _definedAtoms._atoms.push_back(*gnuLinkOnceAtom);
+ atom->setOrdinal(++_ordinal);
+ _definedAtoms._atoms.push_back(atom);
for (auto reference : refs)
- (*gnuLinkOnceAtom)->addReference(reference);
+ atom->addReference(reference);
return std::error_code();
}
@@ -922,13 +922,13 @@ std::error_code ELFFile<ELFT>::handleSec
atomsForSection[sectionName].clear();
}
// Create a gnu linkonce atom.
- auto sectionGroupAtom = handleDefinedSymbol(
+ ELFDefinedAtom<ELFT> *atom = createDefinedAtom(
signature, groupSectionName, nullptr, shdr, ArrayRef<uint8_t>(),
referenceStart, _references.size(), _references);
- (*sectionGroupAtom)->setOrdinal(++_ordinal);
- _definedAtoms._atoms.push_back(*sectionGroupAtom);
+ atom->setOrdinal(++_ordinal);
+ _definedAtoms._atoms.push_back(atom);
for (auto reference : refs)
- (*sectionGroupAtom)->addReference(reference);
+ atom->addReference(reference);
return std::error_code();
}
@@ -983,9 +983,8 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::cre
createRelocationReferences(symbol, symContent, secContent, rri->second);
// Create the DefinedAtom and add it to the list of DefinedAtoms.
- return *handleDefinedSymbol(symbolName, sectionName, symbol, section,
- symContent, referenceStart, _references.size(),
- _references);
+ return createDefinedAtom(symbolName, sectionName, symbol, section, symContent,
+ referenceStart, _references.size(), _references);
}
template <class ELFT>
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h?rev=234269&r1=234268&r2=234269&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h Mon Apr 6 20:00:20 2015
@@ -128,12 +128,12 @@ public:
}
/// Process the Defined symbol and create an atom for it.
- ErrorOr<ELFDefinedAtom<ELFT> *>
- handleDefinedSymbol(StringRef symName, StringRef sectionName,
- const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
- ArrayRef<uint8_t> contentData,
- unsigned int referenceStart, unsigned int referenceEnd,
- std::vector<ELFReference<ELFT> *> &referenceList) override {
+ ELFDefinedAtom<ELFT> *
+ createDefinedAtom(StringRef symName, StringRef sectionName,
+ const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
+ ArrayRef<uint8_t> contentData, unsigned int referenceStart,
+ unsigned int referenceEnd,
+ std::vector<ELFReference<ELFT> *> &referenceList) override {
return new (this->_readerStorage) HexagonELFDefinedAtom<ELFT>(
*this, symName, sectionName, sym, sectionHdr, contentData,
referenceStart, referenceEnd, referenceList);
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=234269&r1=234268&r2=234269&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Mon Apr 6 20:00:20 2015
@@ -127,11 +127,12 @@ private:
uint64_t _tpOff = 0;
uint64_t _dtpOff = 0;
- ErrorOr<ELFDefinedAtom<ELFT> *> handleDefinedSymbol(
- StringRef symName, StringRef sectionName, const Elf_Sym *sym,
- const Elf_Shdr *sectionHdr, ArrayRef<uint8_t> contentData,
- unsigned int referenceStart, unsigned int referenceEnd,
- std::vector<ELFReference<ELFT> *> &referenceList) override {
+ ELFDefinedAtom<ELFT> *
+ createDefinedAtom(StringRef symName, StringRef sectionName,
+ const Elf_Sym *sym, const Elf_Shdr *sectionHdr,
+ ArrayRef<uint8_t> contentData, unsigned int referenceStart,
+ unsigned int referenceEnd,
+ std::vector<ELFReference<ELFT> *> &referenceList) override {
return new (this->_readerStorage) MipsELFDefinedAtom<ELFT>(
*this, symName, sectionName, sym, sectionHdr, contentData,
referenceStart, referenceEnd, referenceList);
More information about the llvm-commits
mailing list