Commit Graph

343 Commits

Author SHA1 Message Date
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
Rafael Espindola 6f4bd532d3 Rearrange a bit for clarity. NFC.
llvm-svn: 249404
2015-10-06 14:17:53 +00:00
Rafael Espindola 03ab3368a0 External symbols need a full dynamic reloc, not R_X86_64_RELATIVE.
We were already doing the right thing if the symbol was seen in a shared
library, but not if it was completely missing.

llvm-svn: 249397
2015-10-06 12:39:58 +00:00
George Rimar d01ffbdb1b Fixed typo
llvm-svn: 249393
2015-10-06 12:08:08 +00:00
Michael J. Spencer 6e78d16b3b [elf2] Address style comments.
llvm-svn: 249368
2015-10-06 02:13:54 +00:00
Michael J. Spencer 95538ca99a [elf2] Add __preinit_array, and __fini_array start and end symbols.
llvm-svn: 249367
2015-10-06 01:16:17 +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
Rafael Espindola 41127ad7af Fix R_X86_64_RELATIVE for local symbols that refer to other sections.
We were mixing up the relocated and target sections.

llvm-svn: 249360
2015-10-05 22:49:16 +00:00
Davide Italiano b4606e183e [ELF2/AArch64] Read the right amount of bytes.
This was clearly wrong (thanks Rui for spotting), and I honestly would 
like to get this tested so such mistakes won't repeat. Unfortunately, I
wasn't (easily) able to craft a test that exposes the bad behavior.
Ideally, we would like to get tests of this kind for all relocations, but
at the time of writing, this is not true. So, for now just fix this bug
and try to re-evaluate a way to test this in the future.

llvm-svn: 249359
2015-10-05 22:43:42 +00:00
Rafael Espindola 9c3e4d2af5 Handle a common symbol needing a R_X86_64_RELATIVE.
llvm-svn: 249357
2015-10-05 21:23:08 +00:00
Rafael Espindola 3c83e2bbfb Include existing addend when computing R_X86_64_RELATIVE.
llvm-svn: 249353
2015-10-05 21:09:37 +00:00
Rafael Espindola ae24400424 Create R_X86_64_RELATIVE when needed.
The dynamic relocation code needs refactoring, but it is probably better
to do it with this test passing.

llvm-svn: 249340
2015-10-05 19:30:12 +00:00
Rafael Espindola d1cf421bd5 Don't copy STT_SECTION from the inputs.
This matches the behavior of gold and bfd ld.

llvm-svn: 249326
2015-10-05 16:25:43 +00:00
Igor Kudrin 024c84c77c Remove an extra blank line.
llvm-svn: 249324
2015-10-05 16:05:18 +00:00
Rafael Espindola 4f674ed138 Include hidden and internal symbols in the regular symbol table.
This matches the behavior of bfd ld and gold. It is also convenient for
testing other changes.

llvm-svn: 249323
2015-10-05 15:24:04 +00:00
Igor Kudrin b1f2b51a89 [ELF2] Add DT_INIT and DT_FINI dynamic table entries
The entries are added if there are "_init" or "_fini" entries in
the symbol table respectively. According to the behavior of ld,
entries are inserted even for undefined symbols.

Symbol names can be overridden by using -init and -fini command
line switches. If used, these switches neither add new symbol table
entries nor require those symbols to be resolved.

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

llvm-svn: 249297
2015-10-05 10:29:46 +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
Davide Italiano df88f968e3 [ELF2/AArch64] Add support for AARCH64_ABS{16,32,64} relocations.
I saw these in the wild while trying to link shared libraries.

llvm-svn: 249254
2015-10-04 00:59:16 +00:00
Davide Italiano 0b6974bfe0 [ELF/AArch64] Support R_AARCH64_ADR_PREL_PG_H121 relocation.
llvm-svn: 249246
2015-10-03 19:56:07 +00:00
Ed Maste 2c86fb4bde Accept --dynamic-linker in addition to -dynamic-linker.
This matches what bfd ld accepts.

llvm-svn: 249234
2015-10-03 09:32:48 +00:00
Ed Maste 21e4e148c6 Add -rpath= alias for -rpath
llvm-svn: 249230
2015-10-03 06:54:24 +00:00
Davide Italiano d9b5be4c83 [ELF/AArch64] Fix a couple of typos. My bad, sorry.
llvm-svn: 249201
2015-10-02 22:17:09 +00:00
Rui Ueyama 5713b8d0db ELF2: Use less templates so that we can use struct assignment. NFC.
llvm-svn: 249200
2015-10-02 22:17:07 +00:00
Davide Italiano 318ca22914 [ELF2/AArch64] Add comment and change name to match the one of the ABI.
Fix style while I'm here.

llvm-svn: 249198
2015-10-02 22:13:51 +00:00
Davide Italiano 1f31a2c11c [ELF2/AArch64] Add support for R_AARCH64_ADR_PREL_PG_H121
llvm-svn: 249195
2015-10-02 22:00:42 +00:00
Michael J. Spencer ed3476b79f [elf2] Add STB_GNU_UNIQUE support.
llvm-svn: 249193
2015-10-02 21:57:52 +00:00
Rui Ueyama 04dae558f4 ELF2: Make Writer::assignAddress() a bit shorter. NFC.
llvm-svn: 249190
2015-10-02 21:23:17 +00:00
Rui Ueyama 0fb1ee0c77 Fix variable names.
llvm-svn: 249188
2015-10-02 21:13:19 +00:00
Ed Maste 75c2feb753 Rename alias definitions by both aliased and alias name
Differential Revision: http://reviews.llvm.org/D13397

llvm-svn: 249186
2015-10-02 21:01:59 +00:00
Rafael Espindola 7757224466 Add static initialization/finalization array support.
This adds entries in the dynamic table for .init_array, .fini_array and
.preinit_array.

llvm-svn: 249175
2015-10-02 19:37:55 +00:00
Rafael Espindola b2a5cafb37 Weak undefined symbols should not fetch archive members.
llvm-svn: 249160
2015-10-02 17:41:22 +00:00
Hal Finkel d26da9258f [ELF2] Fix mixed-Endian handling in DynamicSection<ELFT>::writeTo
Using the "raw" Elf64_Dyn or Elf32_Dyn structures in
DynamicSection<ELFT>::writeTo does not correctly handle mixed-Endian
situations. Instead, use the corresponding llvm::object::* structures which
have Endian-converting members (like the rest of the code).

This fixes all currently-failing elf2 tests when running on big-Endian
PPC64/Linux (I've added a big-Endian test case which should fail on
little-Endian machines in the same way that test/elf2/shared.s failed on
big-Endian machines prior to this change).

llvm-svn: 249150
2015-10-02 16:21:30 +00:00
Rafael Espindola 4876c886fc Ignore --version-script.
llvm-svn: 249149
2015-10-02 16:20:39 +00:00
Ed Maste 2dab6c9bcc Allow -soname arg in addition to -soname=arg
Differential Revision: http://reviews.llvm.org/D13387

llvm-svn: 249146
2015-10-02 15:45:26 +00:00
Ed Maste 9c95ac2946 Ignore --enable-new-dtags and --no-fatal-warnings
Found while testing a FreeBSD base system build with lld.  Ignored for
now while we continue to identify missing options and functionality.

llvm-svn: 249144
2015-10-02 15:29:31 +00:00
Rafael Espindola fc96a263a1 Ignore options used during a clang build.
llvm-svn: 249135
2015-10-02 14:25:26 +00:00
Rafael Espindola 327b178dd6 Accept some options with both -- and -.
This matches what both gold and bfd ld accept.

llvm-svn: 249134
2015-10-02 14:21:24 +00:00
Rui Ueyama 8c205d5394 ELF2: Merge duplicates using lambdas. NFC.
llvm-svn: 249118
2015-10-02 01:33:31 +00:00
Michael J. Spencer b660b61954 [elf2] Ignore --{start,end}-group.
llvm-svn: 249093
2015-10-01 22:54:37 +00:00
Rafael Espindola 8f13bef575 Ignore --no-add-needed.
llvm-svn: 249089
2015-10-01 22:31:38 +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
Michael J. Spencer 52bf0ebfdf [lld][elf2] Sort output sections.
Sort by:
ALLOC
ALLOC && NOBITS
ALLOC & EXEC
ALLOC & EXEC && NOBITS
ALLOC & WRITE
ALLOC & WRITE && NOBITS
<nothing> (ignoring NOBITS)

The dynamic section is finalized early because it adds strings to the dynamic string table, which comes before the dynamic table.

llvm-svn: 249071
2015-10-01 21:15:02 +00:00
Rafael Espindola 3e60379fd9 Don't crash on files with no symbol table.
Thanks to Roman Divacky for the test.

llvm-svn: 249066
2015-10-01 20:26:37 +00:00
George Rimar 57e40deb8d [ELF2] Implement --no-undefined flag.
llvm-svn: 249064
2015-10-01 20:14:45 +00:00
Rafael Espindola 6a3b5ded8a Don't include shared libraries multiple times.
llvm-svn: 249061
2015-10-01 19:52:48 +00:00
Rui Ueyama 7de3f3719a ELF2: Add -soname option.
llvm-svn: 249058
2015-10-01 19:36:04 +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 fd124db996 ELF2: Tidy up Options.td again.
llvm-svn: 249038
2015-10-01 17:33:38 +00:00