[lld] r316817 - Simplify error handling.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 27 17:05:12 PDT 2017
Author: ruiu
Date: Fri Oct 27 17:05:12 2017
New Revision: 316817
URL: http://llvm.org/viewvc/llvm-project?rev=316817&view=rev
Log:
Simplify error handling.
I don't think we have to aim for precise bug compatibility.
We can return a nullptr if a section is consumed by the linker, and
the rest should naturally work.
Removed:
lld/trunk/test/ELF/invalid/Inputs/section-index2.elf
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/test/ELF/invalid/invalid-elf.test
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=316817&r1=316816&r2=316817&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Oct 27 17:05:12 2017
@@ -516,25 +516,18 @@ template <class ELFT> void ObjFile<ELFT>
template <class ELFT>
InputSectionBase *ObjFile<ELFT>::getSection(const Elf_Sym &Sym) const {
uint32_t Index = this->getSectionIndex(Sym);
- if (Index >= this->Sections.size())
- fatal(toString(this) + ": invalid section index: " + Twine(Index));
- InputSectionBase *S = this->Sections[Index];
+ if (Index == 0)
+ return nullptr;
- // We found that GNU assembler 2.17.50 [FreeBSD] 2007-07-03 could
- // generate broken objects. STT_SECTION/STT_NOTYPE symbols can be
- // associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections.
- // In this case it is fine for section to be null here as we do not
- // allocate sections of these types.
- if (!S) {
- if (Index == 0 || Sym.getType() == STT_SECTION ||
- Sym.getType() == STT_NOTYPE)
- return nullptr;
+ if (Index >= this->Sections.size())
fatal(toString(this) + ": invalid section index: " + Twine(Index));
- }
- if (S == &InputSection::Discarded)
- return S;
- return S->Repl;
+ InputSectionBase *Sec = this->Sections[Index];
+ if (!Sec)
+ return nullptr;
+ if (Sec == &InputSection::Discarded)
+ return Sec;
+ return Sec->Repl;
}
template <class ELFT>
Removed: lld/trunk/test/ELF/invalid/Inputs/section-index2.elf
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/Inputs/section-index2.elf?rev=316816&view=auto
==============================================================================
Binary file - no diff available.
Modified: lld/trunk/test/ELF/invalid/invalid-elf.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-elf.test?rev=316817&r1=316816&r2=316817&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-elf.test (original)
+++ lld/trunk/test/ELF/invalid/invalid-elf.test Fri Oct 27 17:05:12 2017
@@ -20,10 +20,6 @@
# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX-LLD %s
# INVALID-SECTION-INDEX-LLD: invalid section index
-## section-index2.elf has local symbol with incorrect section index.
-# RUN: not ld.lld %p/Inputs/section-index2.elf -o %t2 2>&1 | \
-# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX-LLD %s
-
# RUN: not ld.lld %p/Inputs/multiple-eh-relocs.elf -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-EH-RELOCS %s
# INVALID-EH-RELOCS: multiple relocation sections to one section are not supported
More information about the llvm-commits
mailing list