Commit Graph

67 Commits

Author SHA1 Message Date
Rui Ueyama 3d45179d56 ELF2: Split SymbolTable::addFile(). NFC.
llvm-svn: 250073
2015-10-12 18:03:21 +00:00
Rafael Espindola b9ca7bb6ab Delete getFirstELF.
llvm-svn: 250030
2015-10-12 11:52:31 +00:00
Rafael Espindola dfce5a25cb Simplify the InputFile type hierarchy by removing unnecessary middle classses.
llvm-svn: 250006
2015-10-12 02:22:58 +00:00
Rafael Espindola af70764aa1 Simplify the InputFile type hierarchy.
Now that the SymbolTable is templated, we don't need the ELFData class or
multiple inheritance.

llvm-svn: 250005
2015-10-12 01:55:32 +00:00
Rafael Espindola 9afbac479f Handle a crash in conflict detection with archive members.
llvm-svn: 249996
2015-10-11 20:19:20 +00:00
Rafael Espindola 525914defd Detect incompatible files when one of them comes from an archive.
llvm-svn: 249968
2015-10-11 03:36:49 +00:00
Rui Ueyama ff77768569 ELF2: Move Target and entry initialization from SymbolTable to Driver.
SymbolTable was not a right place for initialization. We had to do that
because Driver didn't know what type of ELF objects are being handled.
We taught Driver that, so we can now move this code to Driver.

llvm-svn: 249904
2015-10-09 21:12:40 +00:00
Rui Ueyama 3ce825ed26 ELF2: Make SymbolTable a template class.
SymbolTable was not a template class. Instead we had switch-case-based
type dispatch to call desired functions. We had to do that because
SymbolTable was created before we know what ELF type objects had been
passed.

Every time I tried to add a new function to the symbol table, I had to
define a dispatcher which consist of a single switch statement.

It also brought an restriction what the driver can do. For example,
we cannot add undefined symbols before any files are added to the symbol
table. That's because no symbols can be added until the symbol table
knows the ELF type, but when it knows about that, it's too late.

In this patch, the driver makes a decision on what ELF type objects
are being handled. Then the driver creates a SymbolTable object for
an appropriate ELF type.

http://reviews.llvm.org/D13544

llvm-svn: 249902
2015-10-09 21:07:25 +00:00
Rafael Espindola 444576d4c4 Add support for comdats.
The implementation is a direct translation to c++ of the rules in the ELF spec.

llvm-svn: 249881
2015-10-09 19:25:07 +00:00
Igor Kudrin 65bddeaacf [ELF2] Check for TLS mismatch in symbol resolution.
The linker should generate an error if a TLS symbol is resolved
for a non-TLS reference and vice versa.

The patch addresses PR24244 (https://llvm.org/bugs/show_bug.cgi?id=24244)

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

llvm-svn: 249817
2015-10-09 09:58:39 +00:00
Rui Ueyama aca48ffb41 ELF2: Inititalize other symbols only once as well.
llvm-svn: 249645
2015-10-08 00:44:28 +00:00
Rui Ueyama 833ce281db ELF2: Make member variable names shorter.
I'm going to use them in other patches, and the names feel too long
despite their narrow scope.

llvm-svn: 249642
2015-10-08 00:29:00 +00:00
Rui Ueyama 9ea49c7948 ELF2: Initialize SyntheticOptional only once.
llvm-svn: 249636
2015-10-07 23:46:11 +00:00
Rui Ueyama e1f91529c8 ELF2: Rename dupError() -> reportConflict().
llvm-svn: 249622
2015-10-07 21:37:24 +00:00
Denis Protivensky 1ef7b3ff55 [ELF2] Handle -m option
Parse and apply emulation given with -m option.
Check input files to match ELF type and machine architecture provided with -m.

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

llvm-svn: 249529
2015-10-07 09:13:03 +00:00
Rafael Espindola c05ad3dedb Create linker generated symbols earlier.
We were incorrectly deciding that a dynamic relocation was needed for them.

llvm-svn: 249512
2015-10-07 02:51:44 +00:00
Michael J. Spencer f32446fb65 [elf2] Correctly determine if we should ignore missing __tls_get_addr.
llvm-svn: 249462
2015-10-06 20:39:09 +00:00
Rafael Espindola 85a6e0f870 Never fetch members for weak undefined symbols.
We were still fetching them when the archive was seen first.

We should experiment with just letting lazy symbols get to compare, it
might be cleaner for ELF.

llvm-svn: 249417
2015-10-06 15:18:50 +00:00
Rafael Espindola b90582dbbd Avoid recursive calls to init (we would crash).
llvm-svn: 249412
2015-10-06 15:03:52 +00:00
Rafael Espindola 8614c566e2 Handle strong undefined symbols fetching members after a weak undefined.
This is a case that requires --start-group --end-group with regular ELF
linkers. Fortunately it is still possible to handle it with lazy symbols without
taking a second look at archives.

Thanks to Michael Spencer for the bug report.

llvm-svn: 249406
2015-10-06 14:33:58 +00:00
Michael J. Spencer 4c46f57a49 [elf2] Ignore __tls_get_addr when static linking.
llvm-svn: 249365
2015-10-06 00:45:42 +00:00
Denis Protivensky 22220d5d5f [ELF2] Add --undefined option
Add symbol specified with -u as undefined which may cause additional
object files from archives to be linked into the resulting binary.

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

llvm-svn: 249295
2015-10-05 09:43:57 +00:00
Rafael Espindola b2a5cafb37 Weak undefined symbols should not fetch archive members.
llvm-svn: 249160
2015-10-02 17:41:22 +00:00
Rafael Espindola 5d41326751 Still define __init_array_(start|end) if there is no .init_array.
This matches the behavior of other linkers and seems necessary to link
in some older systems.

llvm-svn: 249077
2015-10-01 21:22:26 +00:00
Rafael Espindola d31088b37a Simplify instantiation. NFC.
llvm-svn: 249074
2015-10-01 21:18:37 +00:00
Rafael Espindola 6a3b5ded8a Don't include shared libraries multiple times.
llvm-svn: 249061
2015-10-01 19:52:48 +00:00
Igor Kudrin 2696bbeb93 [ELF2] Add --[no-]whole-archive command line switches
Summary:
If --whole-archive is used, all symbols from the following archives are added to the output. --no-whole-archive restores default behavior. These switches can be used multiple times.

NB. We have to keep an ArchiveFile instance within SymbolTable even if --whole-archive mode is active since it can be a thin archive which contains just names of external files. In that case actual memory buffers for the archive members will be stored within the File member of ArchiveFile class.

Reviewers: rafael, ruiu

Subscribers: grimar, llvm-commits

Projects: #lld

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

llvm-svn: 249045
2015-10-01 18:02:21 +00:00
Rui Ueyama 9d4c6d771b [ELF2] Implemented --entry flag.
Patch from George Rimar!

llvm-svn: 248806
2015-09-29 16:40:13 +00:00
Simon Atanasyan 49829a1bfe [ELF2] Add initial MIPS support
Besides a trivial MIPS support the patch introduces new TargetInfo class
member getDefaultEntry() to override default name of the entry symbol.
MIPS uses __start for that.

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

llvm-svn: 248779
2015-09-29 05:34:03 +00:00
Rafael Espindola 4b2ca85c1a Implement --allow-multiple-definition.
Patch by George Rimar!

llvm-svn: 248733
2015-09-28 20:30:11 +00:00
Davide Italiano aabc45b5ad [ELF] Sort a list of cases alphabetically for consistency/clarity. NFC.
llvm-svn: 248680
2015-09-27 09:01:28 +00:00
Davide Italiano cde9336717 [ELF2] Add initial AArch64 support.
Differential Revision:	http://reviews.llvm.org/D13167

llvm-svn: 248641
2015-09-26 00:32:04 +00:00
Rafael Espindola 0e604f913a Add support for creating the symbols __init_array_start and __init_array_end.
llvm-svn: 248604
2015-09-25 18:56:53 +00:00
Rafael Espindola e1901cc33d Simplify memory management by having ELFData contain a ELFObj.
llvm-svn: 248502
2015-09-24 15:11:50 +00:00
Rafael Espindola d27adc42e6 Add support for the _GLOBAL_OFFSET_TABLE_ symbol.
llvm-svn: 248490
2015-09-24 13:34:01 +00:00
Rafael Espindola 5a5fdf7f73 Fix typo.
Thanks to Sean Silva for noticing.

llvm-svn: 248488
2015-09-24 12:58:44 +00:00
Rafael Espindola 1a49e58181 Print more information about duplicated symbols.
llvm-svn: 248380
2015-09-23 14:10:24 +00:00
Rafael Espindola 1d6063e804 Stub out ARM and PPC targets so that we can use a switch to create them.
llvm-svn: 248324
2015-09-22 21:24:52 +00:00
Rafael Espindola c40108858d Move relocation processing to Target.
I will add a couple of ppc64 relocs in the next patches.

llvm-svn: 248319
2015-09-22 20:54:08 +00:00
Rafael Espindola 01205f79a4 Start adding target abstractions.
This is just enough to get PLT working on 32 bit x86.

The idea behind using a virtual interface is that it should be easy to
convert any of the functions to template parameters if any turns out to be
performance critical.

llvm-svn: 248308
2015-09-22 18:19:46 +00:00
Rafael Espindola 67a5da60ed Add support of Elf_Rel dynamic relocations.
llvm-svn: 247888
2015-09-17 14:02:10 +00:00
Rafael Espindola 4340aad144 Start adding support for creating shared libraries.
They are not fully functional yet, but this implements enough support for lld
itself to read them.

With that, delete the .so binary we were using for tests and start eating our
own dog food.

llvm-svn: 247487
2015-09-11 22:42:45 +00:00
Rui Ueyama d5004e1c69 Fix indentation.
llvm-svn: 247169
2015-09-09 18:02:23 +00:00
Michael J. Spencer ac5f048e09 [lld][elf2] Address review comments.
llvm-svn: 247096
2015-09-08 22:51:46 +00:00
Michael J. Spencer 546c64c733 [lld][elf2] Fix hard coded entry address.
llvm-svn: 247089
2015-09-08 22:34:57 +00:00
Rafael Espindola 18173d420e Start adding support for symbols in shared libraries.
llvm-svn: 247019
2015-09-08 15:50:05 +00:00
Rafael Espindola 4f624b9581 Simplify reporting of undefined symbols.
llvm-svn: 247016
2015-09-08 14:32:29 +00:00
Michael J. Spencer 1b348a68e5 [elf2] Add basic archive file support.
llvm-svn: 246886
2015-09-04 22:28:10 +00:00
Rafael Espindola 824d1a975f Add a template helper to avoid multiple switches over the ELF kind. NFC.
llvm-svn: 246823
2015-09-04 00:09:43 +00:00
Rafael Espindola f98d6d84cd Start adding support for shared libraries.
This just adds the types and enough support to detect incompatibilities among
shared libraries and object files.

llvm-svn: 246797
2015-09-03 20:03:54 +00:00