Commit Graph

27 Commits

Author SHA1 Message Date
George Rimar bcba39ab9c [ELF] - Check that .dynsym is present in DSO if SHT_GNU_versym section is.
When we have SHT_GNU_versym section, it is should be associated with symbol table
section. Usually (and in out implementation) it is .dynsym.
In case when .dynsym is absent (due to broken object for example), 
lld crashes in parseVerdefs() when accesses null pointer:

Versym = reinterpret_cast<const Elf_Versym *>(this->ELFObj.base() +
                                              VersymSec->sh_offset) +
         this->Symtab->sh_info;

DIfferential revision: https://reviews.llvm.org/D25553

llvm-svn: 285796
2016-11-02 10:16:25 +00:00
Rafael Espindola e036907c59 Update for llvm change.
We no longer use the section names in this test.

llvm-svn: 285754
2016-11-01 21:34:26 +00:00
Rafael Espindola 4a2055bef9 Update for llvm change.
llvm-svn: 285739
2016-11-01 20:25:27 +00:00
George Rimar 6912147094 [ELF] - Testcase checking that we do not crash on invalid sh_info in SHT_GROUP sections. NFC.
Fix was landed as r284702 "[Object/ELF] - Check index argument in getSymbol()."

Patch contains LLD testcase only.

llvm-svn: 284703
2016-10-20 08:22:54 +00:00
George Rimar 17d566daaa [ELF] - Don't crash on multiple SHT_MIPS_REGINFO/SHT_MIPS_ABIFLAGS sections.
In continue of D25555, this patch fixes possible crash when
we have multiple SHT_MIPS_REGINFO or SHT_MIPS_ABIFLAGS sections.
yaml2obj was used to produce such objects.

Differential revision: https://reviews.llvm.org/D25609

llvm-svn: 284376
2016-10-17 11:31:46 +00:00
George Rimar 21cd1a6fa9 [ELF] - Added testcase relative to D25090.
It was requested on review for https://reviews.llvm.org/D25090 to add testcase in lld.

Spec says (http://www.sco.com/developers/gabi/1998-04-29/ch4.eheader.html) :
e_shnum
This member holds the number of entries in the section header table. 
Thus the product of e_shentsize and e_shnum gives the section header table's size in bytes.
If a file has no section header table, e_shnum holds the value zero.

In case revealed, broken input did not contain zero in this field.
 LLD then could crash when proccessed sections (returned array has incorrect size):

template <class ELFT> void SharedFile<ELFT>::parseSoName() {
...
  for (const Elf_Shdr &Sec : Obj.sections()) {
...

llvm-svn: 284375
2016-10-17 11:15:12 +00:00
George Rimar 85e6106d76 [ELF] - Do not crash when object has multiple SHT_MIPS_OPTIONS
Issue was revealed by AFl and I was able to generate such object using yaml2obj.

When object has more than one SHT_MIPS_OPTIONS, 
each except the last one is destroyed after placing into Sections array.
Sections array contains dead pointers finally. LLD may crash then.

Differential revision: https://reviews.llvm.org/D25555

llvm-svn: 284227
2016-10-14 11:10:36 +00:00
George Rimar 78fe56e5ef [ELF] - Fixed assertion fail when symbol table has invalid sh_info value.
This part was splitted from D25016.

When sh_info value was set in the way that non-local symbol was treated as local, lld
was asserting, patch fixes that.

Differential revision: https://reviews.llvm.org/D25371

llvm-svn: 283859
2016-10-11 09:07:14 +00:00
Rui Ueyama b224c048b4 Remove trailing whitespace.
llvm-svn: 283786
2016-10-10 18:10:01 +00:00
George Rimar 27e651d4f6 Recommit r283733 "[ELF] - Do not crash if common symbol alignment set to value greater than UINT32_MAX.
With fix: commit changes from InputFiles.cpp too.

Original commit message:
We have following code in lld, that truncates the alignment value to 32 bit. Big alignment in this case
may give result 0 and crash later.

template <class ELFT>
CommonInputSection<ELFT>::CommonInputSection(std::vector<DefinedCommon *> Syms)
    : InputSection<ELFT>(nullptr, &Hdr, "") {
....
  for (DefinedCommon *Sym : Syms) {
    this->Alignment = std::max<uintX_t>(this->Alignment, Sym->Alignment);
...
  }
}

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25235

llvm-svn: 283738
2016-10-10 10:31:03 +00:00
George Rimar a1b8245654 Revert r283733 "[ELF] - Do not crash if common symbol alignment set to value greater than UINT32_MAX."
Broke BB because forgot to commit source file.

llvm-svn: 283737
2016-10-10 10:27:38 +00:00
George Rimar 50188b2771 [ELF] - Do not crash if common symbol alignment set to value greater than UINT32_MAX.
We have following code in lld, that truncates the alignment value to 32 bit. Big alignment in this case
may give result 0 and crash later.

template <class ELFT>
CommonInputSection<ELFT>::CommonInputSection(std::vector<DefinedCommon *> Syms)
    : InputSection<ELFT>(nullptr, &Hdr, "") {
....
  for (DefinedCommon *Sym : Syms) {
    this->Alignment = std::max<uintX_t>(this->Alignment, Sym->Alignment);
...
  }
}

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25235

llvm-svn: 283733
2016-10-10 10:10:09 +00:00
George Rimar 9397cf953c [ELF] - Fixed assert fail when symbol table has zero sh_info value.
When sh_info of sumbol table value was set to zero, lld was asserting.

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25016

llvm-svn: 283562
2016-10-07 15:16:27 +00:00
George Rimar 7c213fd17e [ELF] - Check that section alignment is a power of 2.
I found that this check still may be useful in some cases.
At fact since we use uint32_t alignment, then maximum value
that is valid for us is 0x80000000. But some broken files,
for example file from testcase may have greater value.
Because of that offset calculation overflow and crash happens.

Differential revision: https://reviews.llvm.org/D25324

llvm-svn: 283544
2016-10-07 12:27:45 +00:00
George Rimar 53cf2a8112 [ELF] - Do not crash on invalid size of dynamic section.
Previously if sh_size of dynamic section was broken,
lld may crash. Or even may not crash if used 32 bits host.
(then value may be truncated to 32 bits when doing pointer arithmetic 
and could be just zero).
Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25327

llvm-svn: 283533
2016-10-07 09:01:04 +00:00
George Rimar b7aec33125 [ELF] - Do not crash when unable to parse ELF object file.
createELFObj() may call error(...), for example when file is too short.
In that case header is not set and following line lead to crash:

EMachine = ELFObj.getHeader()->e_machine;

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25233

llvm-svn: 283532
2016-10-07 08:51:57 +00:00
George Rimar 24adce95b2 [ELF] - Make checks in ObjectFile<ELFT>::getSection() stricter.
This patch makes the check for null section stricter, 
so it is only allowed for STT_SECTION symbols now.

Differential revision: https://reviews.llvm.org/D25231

llvm-svn: 283426
2016-10-06 09:17:55 +00:00
Rui Ueyama b66260ac17 Remove trailing whitespace.
llvm-svn: 283372
2016-10-05 20:09:50 +00:00
George Rimar 40be15cfb0 [ELF] - Removed "invalid-" prefix from testcase. NFC.
llvm-svn: 283213
2016-10-04 11:51:38 +00:00
George Rimar 422e47a9f5 [ELF] - Do not hang if broken object has option descriptor in .MIPS.options with size of zero.
Previously lld would hang in infinite loop in this case,
patch fixes the issue. Object was found during AFL run.

Differential revision: https://reviews.llvm.org/D25229

llvm-svn: 283208
2016-10-04 10:23:07 +00:00
George Rimar b1f78d1202 [ELF] - Do not crash on invalid symbol index.
Relative to PR30540.

If .symtab has invalid type in elf, no bodies are created and any relocation
that tries to access them will fail.
The same can happen if symbol index is just incorrect.

This was revealed by "id_000005,sig_11,src_000000,op_flip2,pos_420"

Differential revision: https://reviews.llvm.org/D25025

llvm-svn: 283201
2016-10-04 09:02:42 +00:00
George Rimar 6a3b154aab [ELF] - Do not crash if symbol type set to TLS when there is no tls sections.
id_000021,sig_11,src_000002,op_flip1,pos_92 from PR30540

does not have TLS sections, but type
of one of the symbol is broken and set to STT_TLS,
what resulted in a crash. Patch fixes crash.

DIfferential revision: https://reviews.llvm.org/D25083

llvm-svn: 283198
2016-10-04 08:52:51 +00:00
George Rimar 0c82561c4c [ELF] - Do not crash if common symbol has alignment 0.
Testcase contains a common symbol with zero alignment,
previously lld would crash, patch fixes that.

Differential revision: https://reviews.llvm.org/D25085

llvm-svn: 283197
2016-10-04 08:49:52 +00:00
George Rimar 2c0a7f081a [ELF] - Do not crash on invalid section alignment.
Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.

Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D25082

llvm-svn: 283097
2016-10-03 10:04:38 +00:00
George Rimar 678bd05740 [ELF] - Fixed crash on invalid input.
I took the input from https://llvm.org/bugs/show_bug.cgi?id=30540, it was
"id_000000,sig_11,src_000000,op_flip1,pos_98"

File contains invalid symbol name offset (too large) and lld just crashes,
patch fixes the issue.

Differential revision: https://reviews.llvm.org/D24970

llvm-svn: 282709
2016-09-29 11:10:40 +00:00
George Rimar 1abe30a762 [ELF] - Testcases: remove "invalid-" prefix from inputs located in "invalid" subfolder. NFC.
llvm-svn: 282707
2016-09-29 09:39:06 +00:00
George Rimar c017bb3f11 [ELF] - Rename testcase folder from "Invalid" to "invalid". NFC.
llvm-svn: 282706
2016-09-29 09:30:01 +00:00