Commit Graph

302 Commits

Author SHA1 Message Date
Rafael Espindola 22e9a8e366 Update for llvm change.
llvm-svn: 285962
2016-11-03 20:17:25 +00:00
Rui Ueyama 271194016a Simplify by directly using this->Symbols. NFC.
llvm-svn: 285952
2016-11-03 18:20:08 +00:00
Rafael Espindola 6dcf4c6859 Change how we store the symbol table.
Instead of remembering a raw Elf_Shdr, store the symbol table proper
and the index of the first non local.

This moves error handling upfront and simplifies it.

llvm-svn: 285933
2016-11-03 16:55:44 +00:00
Rafael Espindola 21d8be9a4e Initialize the StringTable early and do it only once.
llvm-svn: 285926
2016-11-03 15:43:47 +00:00
Rafael Espindola 73aba6229f Use the getSectionIndex from llvm.
llvm-svn: 285918
2016-11-03 14:26:25 +00:00
Rafael Espindola cc728b41b6 Use existing ELFObj function. NFC.
llvm-svn: 285913
2016-11-03 14:17:53 +00:00
Rafael Espindola 382200abb7 Update for llvm change.
llvm-svn: 285911
2016-11-03 13:58:26 +00:00
Rafael Espindola dd6abaad75 Update for llvm change.
llvm-svn: 285906
2016-11-03 13:43:51 +00:00
Rafael Espindola 6d18d388c5 Pass the section table around instead of recomputing it.
llvm-svn: 285904
2016-11-03 13:24:29 +00:00
Rafael Espindola 84d6a17134 We already have the sections, pass them to getSHNDXTable.
llvm-svn: 285897
2016-11-03 12:21:00 +00:00
George Rimar 4d2aad9da6 [ELF] - Update after LLVM change (r285886)
llvm-svn: 285888
2016-11-03 08:42:52 +00:00
Rafael Espindola 7c7abafd81 Pass the sections to getShtGroupSignature.
This avoids fetching it again from the object.

llvm-svn: 285875
2016-11-03 02:28:13 +00:00
Rui Ueyama 7463adadbf Fix Windows buildbot.
llvm-svn: 285854
2016-11-02 19:51:41 +00:00
Rui Ueyama 7556f6b276 Reduce number of classes by merging DIHelper with ObjectFile.
DIHelper is a class having only one member, and ObjectFile has
a unique pointer to a DIHelper. So we can directly have ObjectFile
have the member.

Differential Revision: https://reviews.llvm.org/D26223

llvm-svn: 285850
2016-11-02 18:42:13 +00:00
Rafael Espindola 199e00408f Pass the section table to getSectionStringTable. NFC.
This will let us simplify the llvm side.

llvm-svn: 285816
2016-11-02 15:21:24 +00:00
Rafael Espindola 235d82cd0a Don't use getNumSections.
It is just the size of sections() which we were already calling.

llvm-svn: 285811
2016-11-02 14:42:20 +00:00
Rafael Espindola 390aaca662 Update for llvm change.
llvm-svn: 285808
2016-11-02 14:11:05 +00:00
Rafael Espindola c17e0b6f68 Simplify SHF_LINK_ORDER handling. NFC.
While ARM is the only currently user we support this is a general
feature.

This avoids a second walk over the sections.

llvm-svn: 285805
2016-11-02 13:36:31 +00:00
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
Rui Ueyama d52adb3917 Provide a convenient function to allocate and initialize objects.
You can now write make<T>(Args) instead of new (alloc<T>()) T(Args).

llvm-svn: 285760
2016-11-01 22:53:18 +00:00
Rafael Espindola ec05a574fe Don't fetch the section string table multiple times. NFC.
llvm-svn: 285755
2016-11-01 21:48:00 +00:00
Rafael Espindola 5c9e8f5e52 Replace GAlloc with a template function.
This patch replaces GAlloc<ELFT>::<sometype>.Allocate() with
alloc<sometype<ELFT>>().

Patch by Rui!

llvm-svn: 285748
2016-11-01 21:06:40 +00:00
Eugene Leviant c4681203e1 Allow fetching source line, when multiple "AX" sections present
Differential revision: https://reviews.llvm.org/D26070

llvm-svn: 285680
2016-11-01 09:17:50 +00:00
Rui Ueyama 55518e7dd8 Consolidate BumpPtrAllocators.
Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

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

llvm-svn: 285452
2016-10-28 20:57:25 +00:00
Rui Ueyama 44fa48f986 Define ~DIHelper::DIHelper() in .cpp.
llvm-svn: 285347
2016-10-27 21:26:57 +00:00
Rafael Espindola 093abab817 Don't create a dummy ELF to process a binary file.
Now that it is easy to create input section and symbols, this is
simple.

llvm-svn: 285322
2016-10-27 17:45:40 +00:00
Rafael Espindola 7cc713adcb Store OSABI in Config.
This allows us to set a value for it based on -m.

llvm-svn: 285294
2016-10-27 14:00:51 +00:00
Rafael Espindola a8631e3887 Use fewer allocators.
Instead of having 3 section allocators per file, have 3 for all files.

This is a substantial performance improvement for some cases. Linking
chromium without gc speeds up by 1.065x.

This requires using _exit in fatal since we have to avoid destructing
an InputSection if fatal is called from the constructor.

Thanks to Rui for the suggestion.

llvm-svn: 285290
2016-10-27 13:32:32 +00:00
Rafael Espindola 5da1d88492 Reduce the number of allocators.
We used to have one allocator per file, which reduces the advantage of
using an allocator in the first place.

This is a small speed up is most cases. The largest speedup was in
1.014X in chromium no-gc. The largest slowdown was scylla at 1.003X.

llvm-svn: 285205
2016-10-26 15:34:24 +00:00
Eugene Leviant b380b24e6e [ELF] Better error reporting for undefined symbols
This patch make lld show following details for undefined symbol errors:
- file (line)
- file (function name)
- file (section name + offset)

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

llvm-svn: 285186
2016-10-26 11:07:09 +00:00
Rafael Espindola 3db70210f8 Update for llvm change.
llvm-svn: 285062
2016-10-25 12:02:31 +00:00
Rafael Espindola 8b2c8536e5 Use a CachedHashString for comdats too.
We were already using it in the larger sets/maps. This provides about
1% speedup in linking xul and chromium.

llvm-svn: 284862
2016-10-21 19:49:42 +00:00
Rui Ueyama 617d587432 Move code from InputFile to ELFCreator to decouple the two files.
Now that only one non-member function is exported from ELFCreator.h.
All the details are handled internally in ELFCreator.cpp file.

llvm-svn: 284786
2016-10-20 21:57:06 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Rui Ueyama 673c9d9018 Add a helper function to define symbols.
Also replace std::copy with memcpy because in other places we are
using memcpy.

llvm-svn: 284700
2016-10-20 06:44:58 +00:00
Rui Ueyama f2e78818e8 Rename variables so that they are more in line with rest of the code.
llvm-svn: 284699
2016-10-20 06:34:03 +00:00
Rui Ueyama 837182ec1e Remove std:: from std::size_t.
llvm-svn: 284687
2016-10-20 01:33:09 +00:00
Rafael Espindola 00ee5edc0d Avoid using getComdatSymbolTable.
This is not particularly efficient, but does avoid exposing Comdat*
out of LTO.h.

I will send a patch for review with a more efficient interface that
should map nicely to a bitcode symbol table.

llvm-svn: 284413
2016-10-17 19:25:08 +00:00
Rafael Espindola b18783e441 Update for llvm change.
llvm-svn: 284409
2016-10-17 18:51:27 +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 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
Davide Italiano bcdd6c60a0 [ThinLTO] Avoid archive member collisions.
This fixes PR30665.

Differential Revision:  https://reviews.llvm.org/D25495

llvm-svn: 284034
2016-10-12 19:35:54 +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
Peter Smith bafd3c40e2 [ELF][ARM] Fix formatting mistake, removed extra space before ) NFC.
llvm-svn: 283735
2016-10-10 10:18:58 +00:00
Peter Smith 0760605ac5 [ELF][ARM] Garbage collection support for .ARM.exidx sections
.ARM.exidx sections have a reverse dependency on the section they have
a SHF_LINK_ORDER dependency on. In other words a .ARM.exidx section is
live only if the executable section it describes is live. We implement
this with a reverse dependency field in InputSection.

Adding the dependency to InputSection is the simplest implementation
but it could be moved out to a separate map if it were found to decrease
performance for non ARM targets.

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

llvm-svn: 283734
2016-10-10 10:10:27 +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 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
Simon Atanasyan 02b9c3f8c3 [ELF] Do not merge sections in case of relocatable object generation
Do not merge sections if generating a relocatable object. It makes
the code simpler because we do not need to update relocations addends
to reflect changes introduced by merging. Instead of that we write
such "merge" sections into separate OutputSections and keep SHF_MERGE
/ SHF_STRINGS flags and sh_entsize value to be able to perform merging
later during a final linking.

Differential Revision: http://reviews.llvm.org/D25066

llvm-svn: 283300
2016-10-05 07:49:18 +00:00