Commit Graph

141 Commits

Author SHA1 Message Date
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