Commit Graph

472 Commits

Author SHA1 Message Date
Rui Ueyama 4b02ca99d0 ELF: Move utility functions from Driver to DriverUtils.
llvm-svn: 249966
2015-10-11 03:28:39 +00:00
Rui Ueyama cacf967ed5 ELF2: Simplify. NFC.
llvm-svn: 249965
2015-10-11 02:22:31 +00:00
Rui Ueyama a467240309 ELF2: Add --verbose.
It is currently not actually verbose but rather terse,
but that's intentional.

llvm-svn: 249964
2015-10-11 02:03:03 +00:00
Rui Ueyama b973256683 ELF2: Manage BumpPtrAllocator ownership better.
Previously, each ArgParser owned a BumpPtrAllocator, and arguments parsed
by an ArgParser would refer strings allocated using the BumpPtrAllocator
only when response files were used. This could cause a subtle bug because
such ownership was not obvious.

This patch moves the ownership from ArgParser to Driver and make the
ownership explicit.

llvm-svn: 249963
2015-10-11 01:53:07 +00:00
Rui Ueyama a47ee68d8e ELF2: Do not leak MemoryBuffers.
llvm-svn: 249962
2015-10-11 01:53:04 +00:00
Rui Ueyama 00f972728b ELF2: LinkerScript: Handle INPUT as a synonym for GROUP.
In our name resolution algorithm, --start-group and --end-group have
no special meaning.

llvm-svn: 249961
2015-10-11 01:31:57 +00:00
Rui Ueyama 31aa1f83de ELF2: LinkerScript: Implement INCLUDE directive.
llvm-svn: 249960
2015-10-11 01:31:55 +00:00
Rui Ueyama bdca0b1fac ELF2: Use memcpy to vector contents.
llvm-svn: 249959
2015-10-11 00:10:36 +00:00
Rui Ueyama 953c2c4b2d ELF2: Remove Writer member varaibles that are used only by one function.
llvm-svn: 249958
2015-10-10 23:59:57 +00:00
Rui Ueyama 69960baad5 ELF2: Write .interp section on the first page in the exectuable.
Previously, we reserved the first page for the program header, so no
sections would be written to very beginning of the output file.
FreeBSD requires .interp section be exist on the first page, so that
was not good.

This patch calculates the size of the program header and then assign
addresses to the sections. Now the first section is located next to
the program header. Because the first section is .interp, it's very
likely to be on the first page.

llvm-svn: 249957
2015-10-10 23:25:39 +00:00
Rui Ueyama 5bfd7d4e00 ELF2: Remove a variable to which always the same value is assigned.
llvm-svn: 249956
2015-10-10 22:36:36 +00:00
Rui Ueyama 2f1b79fc3a ELF2: Remove ProgramHeader class and use Elf_Phdr directly. NFC.
llvm-svn: 249955
2015-10-10 22:34:30 +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
Rui Ueyama 6ccc8ca6d9 Simplify. NFC.
llvm-svn: 249895
2015-10-09 20:32:54 +00:00
Rui Ueyama d888d10cf4 ELF2: Reduce code repetition.
llvm-svn: 249882
2015-10-09 19:34:55 +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
Rafael Espindola 26fd69de90 Don't silently ignore an error.
Found by inspection.

llvm-svn: 249843
2015-10-09 16:15:57 +00:00
Rui Ueyama af311c1d01 ELF2: Call OutputSection::finalize() from createSections.
Previously, we did this in assignAddresses(), but finalization was
not part of assigning addresses, so this is a better place.

llvm-svn: 249842
2015-10-09 16:03:53 +00:00
Rui Ueyama bf3fd7c9a0 ELF2: Emit a PT_PHDR header as the first entry of the program header.
PT_PHDR entry points to the program header itself.

llvm-svn: 249839
2015-10-09 15:31:49 +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
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
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 fe7eeed585 ELF2: Sort. NFC.
llvm-svn: 249803
2015-10-09 02:46:28 +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
Rui Ueyama 964ffb3e11 Define --output= as an alias to -o.
llvm-svn: 249789
2015-10-09 00:33:44 +00:00
Rui Ueyama 5a9640be32 ELF2: Split Writer::createSections into small functions.
Also added a few comments.

llvm-svn: 249781
2015-10-08 23:49:30 +00:00
Rui Ueyama 00851fdf4c Use uintX_t instead of unsigned int to fix potential cross-linking issue.
llvm-svn: 249765
2015-10-08 22:43:55 +00:00
Hal Finkel e3c2626aa4 [ELF2] Make the system page size a target-dependent property
The required page alignment is different on different targets. On PowerPC, for
example, we need 64K pages (the loader won't set different permissions on a
finer granularity than that). I've set the existing targets to what I believe
to be the correct values, and have updated the regression tests accordingly.

llvm-svn: 249760
2015-10-08 22:23:54 +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 4729064a1c Revert: r249728 - Roll back r249726 and r249723 because they broke buildbots.
Reapply r249726 (and r249723), hopefully with the correct test fixups this time.

Original commit message:

Address a FIXME in ELF/Writer.cpp: Make VAStart a target-dependent property.
I've set the values for the existing targets to what I believe to be the
correct values, and updated the regression tests accordingly.

llvm-svn: 249752
2015-10-08 21:25:04 +00:00
Rafael Espindola 6390d16fd1 Don't silently ignore an error.
Found by inspection.

llvm-svn: 249744
2015-10-08 20:43:19 +00:00
Rafael Espindola 98af66f9c5 Make this test a bit stricter.
The only way for SecIndex to be zero in here is for an extended section
number to be zero, which would be an error.

llvm-svn: 249736
2015-10-08 20:29:22 +00:00
Rui Ueyama af21d92320 ELF2: Do not pass GotVA because it's accessible as Out<ELFT>::Got->getVA().
llvm-svn: 249729
2015-10-08 20:06:07 +00:00
Rui Ueyama 7114f0597b Roll back r249726 and r249723 because they broke buildbots.
llvm-svn: 249728
2015-10-08 20:00:02 +00:00
Hal Finkel eb84ce8bd1 [ELF2] Make VAStart a target-dependent property
Address a FIXME in ELF/Writer.cpp: Make VAStart a target-dependent property.
I've set the values for the existing targets to what I believe to be the
correct values, and updated the regression tests accordingly.

llvm-svn: 249723
2015-10-08 19:36:39 +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
Davide Italiano 68a39a6565 [ELF2] Implement linker script SEARCH_DIR() directive.
llvm-svn: 249707
2015-10-08 17:51:41 +00:00
Simon Atanasyan 456bd05d97 [ELF2][mips] Support elf32ltsmip/elf32btsmip target emulation as the -m arguments
llvm-svn: 249683
2015-10-08 12:13:38 +00:00
Rafael Espindola d42f4e5389 Add a convenience variable. NFC.
llvm-svn: 249682
2015-10-08 12:02:38 +00:00
Denis Protivensky 90c5099e8a [ELF2] Add ENTRY command to the linker script
Set ENTRY as an entry point if -e is not specified.

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

llvm-svn: 249661
2015-10-08 06:48:38 +00:00
Rui Ueyama 10c415fd63 Remove a default which immediately breaks.
getID()'s return type is unsigned int, so I don't think we need this
default for -Wswitch-enum.

llvm-svn: 249650
2015-10-08 03:21:29 +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 e66e001c90 ELF2: Use the same name as COFF.
llvm-svn: 249635
2015-10-07 23:20:23 +00:00
Davide Italiano c3858ab82e [ELF2] Garbage collect or{16,64}le. They're now unused.
llvm-svn: 249628
2015-10-07 22:11:20 +00:00
Davide Italiano 06d843226b [ELF2/AArch64] _ABS* relocations don't read contents. Fix it.
Spotted by: Rafael Espindola.

llvm-svn: 249627
2015-10-07 22:10:02 +00:00
Rui Ueyama e1f91529c8 ELF2: Rename dupError() -> reportConflict().
llvm-svn: 249622
2015-10-07 21:37:24 +00:00
Rui Ueyama 0d0bcf7433 ELF2: Stop using SymbolTableSection as a container for SymbolTable.
`Symtab` is better than `Out<ELFT>::SymTab->getSymTable()`.

llvm-svn: 249619
2015-10-07 21:25:39 +00:00
Rui Ueyama 2cac5843a0 ELF2: Define a utility function to handle simple command line options.
llvm-svn: 249592
2015-10-07 19:34:51 +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
George Rimar 730c27894a [ELF2] - fix to use PLT/GOT for DSO function calls (X86TargetInfo)
Differential Revision: http://reviews.llvm.org/D13522

llvm-svn: 249588
2015-10-07 18:46:13 +00:00
Rui Ueyama 75230398c2 ELF2: De-templatize writeResult for simplicity.
llvm-svn: 249586
2015-10-07 18:29:51 +00:00
Rui Ueyama 58d7d704d8 Style fix.
llvm-svn: 249584
2015-10-07 18:22:46 +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 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
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 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
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
Rui Ueyama ee59282bfd ELF2: Implement OUTPUT() linker script directive.
llvm-svn: 249491
2015-10-07 00:25:09 +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
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
Davide Italiano aad4402097 [ELF2] Address r249428 post comit review. Style + test trim.
llvm-svn: 249451
2015-10-06 20:02:15 +00:00
Michael J. Spencer fcacad263a [elf2] Fix style.
llvm-svn: 249450
2015-10-06 19:57:05 +00:00
Rui Ueyama ee8c53bbe2 ELF2: Inline small functions.
llvm-svn: 249449
2015-10-06 19:57:01 +00:00
Rui Ueyama b5fb88584a ELF2: Update README.
llvm-svn: 249447
2015-10-06 19:21:13 +00:00
Davide Italiano ef4be6b4fe [ELF2/AArch64] Function names should start with a verb (lower case).
Pointed out by: Rafael Espindola.

llvm-svn: 249443
2015-10-06 19:01:32 +00:00
Rui Ueyama 87bc41bcee ELF2: Use shorter names before this file grows larger.
llvm-svn: 249441
2015-10-06 18:54:43 +00:00
Rui Ueyama 33bb1a23b3 ELF2: or{16,32,64}le should really do bitwise-OR.
llvm-svn: 249436
2015-10-06 18:11:18 +00:00
Rui Ueyama 190beb3144 ELF2: Define or{16,32,64}le that are analogous to add32le.
llvm-svn: 249435
2015-10-06 18:08:03 +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 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
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