Commit Graph

669 Commits

Author SHA1 Message Date
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
Rafael Espindola 26fd69de90 Don't silently ignore an error.
Found by inspection.

llvm-svn: 249843
2015-10-09 16:15:57 +00:00
Rafael Espindola d540919ff1 Revert "[ELF2] - Implemented rel[a].plt sections"
This reverts commit r249816.

It broke building llvm with lld:

$ ./bin/FileCheck
./bin/FileCheck: error while loading shared libraries: unexpected PLT reloc type 0x06

I think the only thing that is wrong with this patch is that it is too soon.

The plt we create (and its relocs) don't support lazy loading, so they have
to be relocated as ordinary dynamic relocations.

llvm-svn: 249835
2015-10-09 14:25:49 +00:00
George Rimar b352b9ce69 [ELF2] - Implemented rel[a].plt sections
.rela.plt contains list of elements in the PLT, which are liable to the relocation during the dynamic linking.

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

llvm-svn: 249816
2015-10-09 09:58:08 +00:00
Rui Ueyama 36f69229e6 Simplify expressions. NFC.
llvm-svn: 249793
2015-10-09 00:50:05 +00:00
Rui Ueyama 49c68a7cf7 Remove getters/setters that don't provide much abstraction.
llvm-svn: 249791
2015-10-09 00:42:06 +00:00
Hal Finkel 6c2a3b8368 [ELF2] Make the .plt entry size target dependent
The size of a .plt entry is different on different targets (it is,
specifically, much larger than 8 on all PPC ABIs). There is no functional
change here (later patches to create .plt entries for PPC64 will depend on this
change).

llvm-svn: 249756
2015-10-08 21:51:31 +00:00
Hal Finkel cbd21a6ad2 [ELF2] Use EntrySize, not 8, to advance the .plt buffer when writing
In preparation for making the size of a .plt entry target dependent, use the
existing EntrySize variable when writing (instead of a hard-coded value). NFC.

llvm-svn: 249720
2015-10-08 19:16:05 +00:00
Rui Ueyama 15ef5e174b ELF2: Make singleton output sections globally accessible.
Previously, output sections that are handled specially by the linker
(e.g. PLT or GOT) were created by Writer and passed to other classes
that need them. The problem was that because these special sections
are required by so many classes, the plumbing work became too much
burden.

This patch is to simply make them accessible from anywhere in the
linker to eliminate the plumbing work once and for all.

http://reviews.llvm.org/D13486

llvm-svn: 249590
2015-10-07 19:18:16 +00:00
Rui Ueyama b4908761f8 ELF2: Rename local variable name `Out` in preparation to define `Out` global var.
llvm-svn: 249568
2015-10-07 17:04:18 +00:00
Rui Ueyama 0db335fd5e ELF2: Move functions out of line.
llvm-svn: 249566
2015-10-07 16:58:54 +00:00
George Rimar 97aad172b8 [ELF2] -z now option implemented
When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called.

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

llvm-svn: 249551
2015-10-07 15:00:21 +00:00
Denis Protivensky 92aa1c02df [ELF2] Fix gcc build error
llvm-svn: 249524
2015-10-07 08:21:34 +00:00
Rafael Espindola cea0b3b45d Don't create dynamic relocations for weak undefined symbols.
llvm-svn: 249520
2015-10-07 04:22:55 +00:00
Rafael Espindola e782f673a8 Skip entries handled by the dynamic linker.
We were writing got entries in the first positions, not in the positions
corresponding to locally defined symbols.

llvm-svn: 249518
2015-10-07 03:56:05 +00:00
Rafael Espindola 52dca345db Create simpler dynamic relocations for local symbols in got.
If the symbol is not preemptable, we can use a R_X86_64_RELATIVE.

llvm-svn: 249496
2015-10-07 00:58:20 +00:00
Rafael Espindola 3378526f34 Fix typo.
llvm-svn: 249488
2015-10-07 00:15:43 +00:00
Rafael Espindola a662738e02 Don't create dynamic relocations when its known what the got points to.
llvm-svn: 249485
2015-10-06 23:56:53 +00:00
Davide Italiano c39c75dee4 [ELF2] Implement --{enable, disable}-new-dtags options.
llvm-svn: 249428
2015-10-06 16:20:00 +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
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
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
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
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
Rui Ueyama 8c205d5394 ELF2: Merge duplicates using lambdas. NFC.
llvm-svn: 249118
2015-10-02 01:33:31 +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
Rui Ueyama 7de3f3719a ELF2: Add -soname option.
llvm-svn: 249058
2015-10-01 19:36:04 +00:00
Rafael Espindola c8b158155c Copy DT_SONAME to DT_NEEDED.
If a shared library has a DT_SONAME entry, that is what should be included
in the DT_NEEDED of a program using it.

We don't implement -soname yet, so check in a .so for now.

llvm-svn: 249025
2015-10-01 15:47:50 +00:00
Rui Ueyama 2dfd74f758 ELF2: Add DT_REL{,A}ENT and DT_SYMENT.
According to the ELF specification, these dynamic array entries are mandatory.

http://reviews.llvm.org/D13303

llvm-svn: 248952
2015-09-30 21:57:53 +00:00
Rui Ueyama c55733e79c ELF2: Advance the buffer pointers right after we use them.
So that it is clear that we are incrementing the pointers for sure. NFC.

llvm-svn: 248868
2015-09-30 00:54:29 +00:00
Rui Ueyama b189b5c535 Make template instantiation code a bit shorter. NFC.
llvm-svn: 248866
2015-09-30 00:43:22 +00:00
Rui Ueyama 8ddfa812af ELF2: Split SymbolTableSection<ELFT>::writeTo into two smaller functions.
Also added brief comments.

llvm-svn: 248864
2015-09-30 00:32:10 +00:00
Rafael Espindola 3ef3a4c9ff Start adding support for static programs using dynamic libraries.
This is just enough for a hello world using a dynamic glibc.

llvm-svn: 248854
2015-09-29 23:22:16 +00:00
Rafael Espindola 6a78fd5f41 This reverts commit r248845 and r248848.
They broke elf2/basic-mips.s.

Revert "[elf2] Sort output sections."
Revert "[elf2] Fix build."

llvm-svn: 248851
2015-09-29 23:19:25 +00:00
Michael J. Spencer a0abcfd8e7 [elf2] Fix build.
llvm-svn: 248848
2015-09-29 23:12:50 +00:00
Michael J. Spencer fe07bd67fd [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: 248845
2015-09-29 23:05:40 +00:00
Rafael Espindola 2732235508 Try to fix gcc warning
llvm-svn: 248749
2015-09-28 22:12:54 +00:00
Rafael Espindola 5f19f1224c Delete dead code.
llvm-svn: 248747
2015-09-28 22:07:52 +00:00
Rafael Espindola dfc7200b18 Add support for local absolute symbols.
llvm-svn: 248726
2015-09-28 18:29:47 +00:00
Davide Italiano 6993ba4d3e [ELF2] Don't inline function and define it in OutputSection.cpp. NFC.
Reported/Requested by: Rafael Espindola

llvm-svn: 248643
2015-09-26 00:47:56 +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 cd076f0113 Move more logic to getSymVA to avoid code duplication.
llvm-svn: 248599
2015-09-25 18:19:03 +00:00
Rafael Espindola 25b0acb57e Move variables closer to use. NFC.
llvm-svn: 248590
2015-09-25 17:32:37 +00:00
Rafael Espindola 35c6af3c9c Move a few methods out of line. NFC.
llvm-svn: 248586
2015-09-25 17:19:10 +00:00
Davide Italiano 85121bbf24 [ELF2] Use static non-member function when it suffices.
Pointed out by Rui Ueyama.

llvm-svn: 248559
2015-09-25 03:56:11 +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
Davide Italiano d75d3b94fd [ELF2] Add support for -discard-none.
Differential Revision:	http://reviews.llvm.org/D13083

llvm-svn: 248499
2015-09-24 15:08:23 +00:00
Rafael Espindola c2d211994d Create the .bss section early so that we don't have to set it after the fact.
llvm-svn: 248412
2015-09-23 18:25:05 +00:00
Michael J. Spencer 2812aa82d0 [elf2] Pass BSSSec to the relocation handling code differently. Don't store it in the symbol.
llvm-svn: 248393
2015-09-23 16:57:31 +00:00
Rafael Espindola 05a3dd2cba Implement --export-dynamic.
llvm-svn: 248347
2015-09-22 23:38:23 +00:00
Rafael Espindola 7f07442bb6 Move the last remaining hard coded relocations to Target.
Unfortunately the i386 and x86_64 relocation have the same numerical value
and it is a probably a bit much to add got support for another architecture
just to test this.

llvm-svn: 248326
2015-09-22 21:35:51 +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 50534c2b6f Fix the creation of Elf_Rel sections.
We were always incrementing the output buffer pointer by sizeof(Elf_Rela).

llvm-svn: 248303
2015-09-22 17:49:38 +00:00
Rafael Espindola 454ca1c245 Use a signed value for Delta.
This fixes got.s on 32 bit windows.

Patch by Igor Kudrin!

llvm-svn: 248289
2015-09-22 17:08:25 +00:00
Denis Protivensky 67d01489b8 [ELF2] Fix gcc build
Remove explicit qualification in template instantiation.

llvm-svn: 248249
2015-09-22 08:14:46 +00:00
Rafael Espindola 7167585c94 Remove the Chunk terminology from ELF.
llvm-svn: 248229
2015-09-22 00:16:19 +00:00
Rafael Espindola 56f965ff5c More MSVC fixes.
llvm-svn: 248223
2015-09-21 22:48:12 +00:00
Rafael Espindola f68b707251 Trying to fix the MSVC build.
llvm-svn: 248219
2015-09-21 22:21:46 +00:00
Rafael Espindola 327b8e19b1 Remove unused includes.
llvm-svn: 248218
2015-09-21 22:14:55 +00:00
Rafael Espindola 4ea00210f2 Make InputSection able to relocate itself.
This matches the organization used in COFF.

llvm-svn: 248215
2015-09-21 22:01:00 +00:00
Rafael Espindola 5805c4f509 Move OutputSectionBase and derived classes out of Writer.cpp.
The file was getting a bit too big and OutputSection is a central enough
concept in ELF linking to justify its own file.

llvm-svn: 248214
2015-09-21 21:38:08 +00:00