Commit Graph

4302 Commits

Author SHA1 Message Date
Chris Bieneman 03c48b01bf [CMake] Don't include the lld test directory if LLVM_INCLUDE_TESTS is Off
This matches the behavior of LLVM and Clang.

llvm-svn: 249050
2015-10-01 18:17:47 +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
Rui Ueyama 47d4f9496c Remove trailing whitespaces.
llvm-svn: 249037
2015-10-01 17:33:36 +00:00
George Rimar ee05828261 [ELF2] Implement --allow-shlib-undefined as default behavior.
We ignore --{no,}allow-shlib-undefined options and always allow undefined
symbols if we are building a DSO.

llvm-svn: 249036
2015-10-01 17:24:24 +00:00
Igor Kudrin d912ee9595 [ELF2] Add -Bstatic and -Bdynamic command line switches
Summary:
These switches affect library searching for '-l' which follow them. Synonym forms are also supported:
* -dy and -call_shared for -Bdynamic switch
* -dn, -non_shared and -static for -Bstatic switch 

Reviewers: rafael, ruiu

Subscribers: emaste, llvm-commits

Projects: #lld

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

llvm-svn: 249029
2015-10-01 16:42:03 +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 bd35d75e42 ELF2: Linker scripts can refer other linker scripts. Test that.
This did not work before r249023.

llvm-svn: 249024
2015-10-01 15:45:41 +00:00
Rui Ueyama 983ed2b749 ELF2: Define Driver::addFile() as a one-stop place to open a file.
Opening a file and dispatching to readLinkerScript() or createFile()
is a common operation. We want to use that at least from Driver and
from LinkerScript. In COFF, we had the same problem. This patch
resolves the problem in the same way as we did for COFF.

Now, if you have a path that you want to open, just call
Driver->addFile(StringRef). That function opens the file and handles
that as if that were given by command line. This function is the
only place we call identify_magic().

llvm-svn: 249023
2015-10-01 15:23:09 +00:00
Rui Ueyama 44f5d91af9 ELF2: Rename undefError -> reportUndefined.
The new name starts with a verb, and it does not imply that it errors
out and exit (it acutally can just emit a warning depending on settings.)

llvm-svn: 249016
2015-10-01 14:46:54 +00:00
Rui Ueyama 1c8092c915 ELF2: Tidy up Options.td.
Fix indentation and sort options alphabetically.

llvm-svn: 248969
2015-10-01 00:33:02 +00:00
Rui Ueyama 5d8ef2cbd8 ELF2: Ignore some command line argument that clang passes to the linker.
llvm-svn: 248967
2015-10-01 00:24:54 +00:00
Rui Ueyama 819f7127c0 ELF2: Move tests for linker script from basic.s to linkerscript.s.
llvm-svn: 248961
2015-09-30 23:15:35 +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
Davide Italiano c02fcafef6 [ELF2] Expand test comment a little bit, use reloc name as section name.
llvm-svn: 248930
2015-09-30 19:44:30 +00:00
Rui Ueyama 7971152589 ELF2: Do not set default values that will always be overwritten.
These member variables are overwritten unconditionally by Driver,
so setting default values would be confusing.

llvm-svn: 248922
2015-09-30 17:26:13 +00:00
Rui Ueyama f7c5fbb1ca ELF2: Create LinkerScript.cpp and move code from DriverUtils to there.
llvm-svn: 248920
2015-09-30 17:23:26 +00:00
Rui Ueyama bf506b7d48 ELF2: LinkerScript: Handle quoted tokens.
llvm-svn: 248919
2015-09-30 17:15:29 +00:00
Rui Ueyama f5c4aca98f ELF2: Add basic linker script support.
This linker script parser and evaluator is powerful enough to read
Linux's libc.so, which is (despite its name) a linker script that
contains OUTPUT_FORMAT, GROUP and AS_NEEDED directives.

The parser implemented in this patch is a recursive-descendent one.
It does *not* construct an AST but consumes directives in place and
sets the results to Symtab object, like what Driver is doing.
This should be very fast since less objects are allocated, and
this is also more readable.

http://reviews.llvm.org/D13232

llvm-svn: 248918
2015-09-30 17:06:09 +00:00
Rafael Espindola 3c412e14cc Expand a comment a bit.
llvm-svn: 248894
2015-09-30 12:30:58 +00:00
George Rimar 431f94c8e0 test commit
llvm-svn: 248890
2015-09-30 11:42:29 +00:00
Igor Kudrin f03d2b4d1c [ELF2] Simplify buildSysrootedPath()
Reviewed by: rafael

llvm-svn: 248885
2015-09-30 10:39:37 +00:00
Rui Ueyama 82d705e6d9 Remove unused declaration and forward declaration.
llvm-svn: 248877
2015-09-30 03:31:05 +00:00
Rui Ueyama d0e5aebf3a Expand `auto` whose real type is not obvious from context.
llvm-svn: 248876
2015-09-30 02:42:27 +00:00
Rui Ueyama 90b3daaa5c Remove `else` after `return`.
llvm-svn: 248875
2015-09-30 02:37:51 +00:00
Rui Ueyama 294b136db4 Remove `explicit` from constructors that take more than one parameter.
llvm-svn: 248873
2015-09-30 02:06:17 +00:00
Rui Ueyama 5ba3ac4f10 Simplify switch statements. NFC.
llvm-svn: 248871
2015-09-30 01:40:08 +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
Rui Ueyama e3fbc89c44 ELF2: Do not use host pointer size to calculate x86_64 relocation addresses.
Previous code had a potential portability issue because intptr_t is
not guaranteed to be 64 bit.

llvm-svn: 248856
2015-09-29 23:25:21 +00:00
Rafael Espindola 9a0db7cbef Fix typo.
llvm-svn: 248855
2015-09-29 23:23:53 +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
Rui Ueyama 85bbe0c46b Remove the dependency to 'test' command.
llvm-svn: 248849
2015-09-29 23:13:40 +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
Rui Ueyama 1500a90093 ELF2: Do not create ArrayRefs and use const arrays instead. NFC.
llvm-svn: 248844
2015-09-29 23:00:47 +00:00
Rui Ueyama 511631975d ELF2: Make default-output.s test idempotent.
This test failed if being run more than once because of the
remaining file of the last run.

llvm-svn: 248843
2015-09-29 22:57:22 +00:00
Rui Ueyama a7e628ff10 ELF2: Unbreak buildbot.
Subshell didn't work on Windows.

llvm-svn: 248840
2015-09-29 22:46:52 +00:00
Rui Ueyama 4993d0eb51 ELF2: Sort Config member variables. NFC.
llvm-svn: 248838
2015-09-29 22:33:21 +00:00
Rui Ueyama d7c417c03e ELF2: Assign bool values directly. NFC.
llvm-svn: 248837
2015-09-29 22:33:18 +00:00
Rui Ueyama 4eed0114c5 ELF2: Use 'a.out' as default output file name.
llvm-svn: 248831
2015-09-29 21:49:40 +00:00
Rafael Espindola 2d73648667 Update test to use invalid elf file in archives.
The code in driver is about to change so that the invalid files would no
longer be seen as ELF.

This makes sure that the error path will remain tested.

llvm-svn: 248820
2015-09-29 18:44:18 +00:00
Rui Ueyama 9d4c6d771b [ELF2] Implemented --entry flag.
Patch from George Rimar!

llvm-svn: 248806
2015-09-29 16:40:13 +00:00
Rafael Espindola 8acb95c7ab Add support for R_386_GOT32.
llvm-svn: 248799
2015-09-29 14:42:37 +00:00
Rafael Espindola be901e2dbc Don't apply a relocation if we create a dynamic reloc.
With RELA that is just wasteful, with REL the relocation gets applied
twice.

llvm-svn: 248795
2015-09-29 13:51:43 +00:00
Rafael Espindola 6d7fcdb518 Add R_386_GOTPC support.
llvm-svn: 248793
2015-09-29 13:36:32 +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
Cameron Esfahani e211e204da NFC: Fix spelling error in comment.
llvm-svn: 248768
2015-09-29 00:21:38 +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
Lang Hames 9a4c94ec5a [lld][MachO] Fix a think-o to get the twolevel/dynamic_lookup test passing.
llvm-svn: 248736
2015-09-28 20:52:21 +00:00
Rafael Espindola 4b2ca85c1a Implement --allow-multiple-definition.
Patch by George Rimar!

llvm-svn: 248733
2015-09-28 20:30:11 +00:00
Lang Hames 5c692009bc [lld][MachO] Initial implementation of -flat_namespace and -undefined.
This is a basic initial implementation of the -flat_namespace and
-undefined options for LLD-darwin. It ignores several subtlties,
but the result is close enough that we can now link LLVM (but not
clang) on Darwin and pass all regression tests.

llvm-svn: 248732
2015-09-28 20:25:14 +00:00
Rafael Espindola 085a8f5ea7 Don't include fully resolved relocations in the dynamic relocation table.
llvm-svn: 248731
2015-09-28 20:18:40 +00:00
Rafael Espindola 46e01554b1 Add support for got/ptl referring to symbols defined in .o files.
llvm-svn: 248730
2015-09-28 19:48:34 +00:00
Rafael Espindola dfc7200b18 Add support for local absolute symbols.
llvm-svn: 248726
2015-09-28 18:29:47 +00:00
Rui Ueyama c5e22d906b ELF2: Include file names in error messages.
llvm-svn: 248724
2015-09-28 18:20:41 +00:00
Igor Kudrin 1309fc0378 [ELF2] Add --sysroot command line switch
Reviewers: rafael, ruiu

Subscribers: llvm-commits

Projects: #lld

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

llvm-svn: 248715
2015-09-28 15:01:59 +00:00
Rafael Espindola eb990af31e Trying to fix the windows build.
llvm-svn: 248709
2015-09-28 13:11:36 +00:00
Rafael Espindola abb7b28686 Add support for -L and -l command line switches.
Patch by Igor Kudrin!

llvm-svn: 248708
2015-09-28 12:52:21 +00:00
Rafael Espindola 83af95d927 Enable the aarch64 tests.
llvm-svn: 248707
2015-09-28 12:22:25 +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 1d750a6fc3 [ELF2/AArch64] Support for R_AARCH64_ADR_PREL_LO21 relocation.
llvm-svn: 248679
2015-09-27 08:45:38 +00:00
NAKAMURA Takumi 00eecb88a4 lld/test/elf2/basic-aarch64.s should not REQUIRE x86.
FIXME: The feature "arm64" is not activated in lit.cfg.
llvm-svn: 248664
2015-09-26 09:21:58 +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
Davide Italiano f096e10a47 [ELF2] Spell llvm-readobj correctly.
llvm-svn: 248642
2015-09-26 00:43:49 +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
Tom Stellard d0626804fc ELF/AMDGPU: Text section should be called .hsatext
Reviewers: atanasyan, ruiu

Subscribers: llvm-commits

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

llvm-svn: 248621
2015-09-25 21:42:30 +00:00
Rafael Espindola 84aff152d9 Simplify enumeration definition.
Thanks to Rui for the suggestion.

llvm-svn: 248615
2015-09-25 21:20:23 +00:00
Rafael Espindola 551dfd8818 Implement --noinhibit-exec.
Patch by George Rimar!

llvm-svn: 248605
2015-09-25 19:24:57 +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 5b197f0620 Fix the typedef.
Thanks to David Blaikie for noticing.

llvm-svn: 248602
2015-09-25 18:32:09 +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
Rui Ueyama 548d22c073 COFF: ICF should not merge sectinos if their alignments are not the same.
There's actually a room to improve this patch. Instead of not merging
sections that have different alignements, we can choose the section that
has the largest alignment requirement among all sections that are otherwise
considered the same. Then all section alignments are satisfied, so we can
merge them.

I don't know if that improvement could make any difference for real-world
input, so I'll leave it alone. Would be interesting to revisit later.

llvm-svn: 248581
2015-09-25 16:50:12 +00:00
Rui Ueyama c9e746b9e6 COFF: Fix local varaible type.
This is intended to be 64-bit integer, but size_t is not guranteed
to be the same or larger type than uint64_t.

llvm-svn: 248580
2015-09-25 16:38:13 +00:00
Rui Ueyama de88072a00 COFF: Rename Ptr -> Repl.
This pointer points to a replacement for this chunk. Ptr was not a good name.

llvm-svn: 248579
2015-09-25 16:20:24 +00:00
Rui Ueyama eeb22f8251 ELF2: Support reponse files.
http://reviews.llvm.org/D13148

llvm-svn: 248575
2015-09-25 15:37:33 +00:00
Rafael Espindola 38af127c6a Fix the parent class of SharedSymbol.
It is a defined symbol according to classof. Found by inspection.

llvm-svn: 248573
2015-09-25 15:34:03 +00:00
Rafael Espindola d13d9606fb Inline function into only use.
llvm-svn: 248572
2015-09-25 15:08:44 +00:00
Davide Italiano b558b79c88 [ELF2] Make buildbot happy again.
llvm-svn: 248560
2015-09-25 04:22:13 +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
Rui Ueyama 3f4ec66624 ELF2: Use lambdas instead of named functions.
They are short and used only once, so writing them where they are used
is better.

llvm-svn: 248558
2015-09-25 03:48:25 +00:00
Rui Ueyama 4c4993bba6 Remove dead code.
llvm-svn: 248557
2015-09-25 03:38:56 +00:00
Davide Italiano aa7c533ec3 [ELF2] Fix binaries so they actually run on FreeBSD.
Since FreeBSD 4.1, the kernel expects binaries to be marked with
ELFOSABI_FREEBSD in the ELF header to exec() them. LLD unconditionally 
sets OSABI to ELF_OSABINONE, and everything linked with it won't run 
on FreeBSD (unless explicitly rebranded).

Example:
% ./aarch64-hello
ELF binary type "0" not known.
zsh: exec format error: ./aarch64-hello

FreeBSD could be modified to accept ELF_OSABINONE, but that would break all
existing binaries, so the kernel needs to support both ABINONE and ABIFREEBSD.
I plan to push this change in FreeBSD one day, which, unfortunately, is 
not today. This code patches lld so it sets the header field correctly.

For completeness, the rationale of this change is explained in the FreeBSD 
commit message, and it's apparently to pleasee binutils maintainers at the time.
https://svnweb.freebsd.org/base?view=revision&revision=59342

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

llvm-svn: 248554
2015-09-25 01:59:13 +00:00
Chris Bieneman 77456efcb1 [CMake] Move LLD to the new style for symlink generation, and make the links list overridable.
Reviewers: lhames, rafael

Subscribers: llvm-commits

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

llvm-svn: 248544
2015-09-24 21:53:18 +00:00
Rui Ueyama c28a08b8d2 COFF: Remove duplicate parameter from hash value calculation.
llvm-svn: 248526
2015-09-24 19:00:42 +00:00
Rui Ueyama 1392d8b5fe Fix memory leak in FileArchive::find().
Patch from George Rimar!

llvm-svn: 248525
2015-09-24 18:59:26 +00:00
Rui Ueyama d5b5ab7638 [ELF2] Output of all unknown arguments instead of only one.
Patch from George Rimar!

llvm-svn: 248524
2015-09-24 18:55:33 +00:00
Davide Italiano bf37cdec28 [ELF2] Remove ignored options handling.
This was prematurely committed (and I take the blame for that).
Ideally, we want to support only ignored options that are really used
by somebody. Some of the options listed are not even supported by gold
(but only by ld.bfd), which says a lot about their "real-world" usefulness.

llvm-svn: 248503
2015-09-24 15:12:34 +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 e0f09fac78 Add a test covering ELFFile's constructor failing.
llvm-svn: 248498
2015-09-24 14:55:25 +00:00
Rafael Espindola 0872ea3954 Simplify with some ideas from COFF:
* add using namespace llvm::support::endian.
* create a add32le static helper.

Thanks to Rui for the suggestion.

llvm-svn: 248491
2015-09-24 14:16:02 +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 cdfecffd80 Add support for relocating R_X86_64_GOTPCREL.
llvm-svn: 248425
2015-09-23 20:08:25 +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
Davide Italiano aab93b59d4 [ELF2] - added ignored command line options for compatibility.
Patch by George Grimar.

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

llvm-svn: 248389
2015-09-23 15:46:44 +00:00
Rafael Espindola 6173f848b9 Print more information about undefined symbols.
llvm-svn: 248382
2015-09-23 14:37:01 +00:00
Rafael Espindola 8e5560d894 Don't complain about symbols showing up in multible shared libraries.
llvm-svn: 248381
2015-09-23 14:23:59 +00:00
Rafael Espindola 1a49e58181 Print more information about duplicated symbols.
llvm-svn: 248380
2015-09-23 14:10:24 +00:00
Davide Italiano a89d178a4f [ELF2] Add ASCII representation of the string table to test.
Requested by: rafael

llvm-svn: 248361
2015-09-23 01:56:26 +00:00
Davide Italiano e44456b1b9 [ELF2] Constify getStrTabSec().
llvm-svn: 248360
2015-09-23 01:50:53 +00:00
Rafael Espindola 1ab429bf49 Fix a last minuted edit that should not have been committed.
Sorry about that.

llvm-svn: 248349
2015-09-22 23:42:55 +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 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 3efa4e982e Add a token ppc64 reloc just to have a test showing that we handle BE.
llvm-svn: 248321
2015-09-22 21:12:55 +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 8c21fad1e8 Fix a merge problem.
r248289 got lots when I moved code to Target.cpp. Sorry about that.

llvm-svn: 248317
2015-09-22 20:06:19 +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
Davide Italiano 25423d42bd [MachO] Use llvm-readobj in lieu of macho-dump.
The latter will be removed from the tree anytime soon.

llvm-svn: 248300
2015-09-22 17:31:01 +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
Rafael Espindola 503fe9408d Expose ELFFileBase::getEMachine. NFC.
I will use it in a followup patch.

llvm-svn: 248287
2015-09-22 16:53:55 +00:00
Rafael Espindola a794fd44a1 Add support for R_386_PC32.
llvm-svn: 248275
2015-09-22 13:47:45 +00:00
Rafael Espindola 21585757e6 Handle implicit addends in Elf_Rel.
llvm-svn: 248272
2015-09-22 13:35:00 +00:00
Rafael Espindola ec50eebefd Remove unnecessary parenthesis.
llvm-svn: 248270
2015-09-22 13:30:26 +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 9d06ab6ded Rename Chunks.(h|cpp) to InputSection.(h|cpp). NFC.
llvm-svn: 248226
2015-09-22 00:01:39 +00:00
Rui Ueyama 9640173e16 COFF: Add /nosymtab command line option.
This is an LLD extension to MSVC link.exe command line. MSVC linker
does not write symbol tables for executables. We do unless no /debug
option is given.

There's a situation that we want to enable debug info but don't want
to emit the symbol table. One example is when we are comparing output
file size. With this patch, you can tell the linker to not create
a symbol table by just specifying /nosymtab.

llvm-svn: 248225
2015-09-21 23:43:31 +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
Lang Hames c803442890 [LLD][MachO] Fix a FIXME: Subtract base address from atom address when building
export trie.

llvm-svn: 248217
2015-09-21 22:06:02 +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
Rui Ueyama 97d92736f5 COFF: Improve section hash value.
std::distance(C->Relocs.end(), C->Relocs.begin()) is the same as NumRelocs
which is already added to the hash value. What we are missing here is the
section size.

llvm-svn: 248202
2015-09-21 19:41:38 +00:00
Rui Ueyama 3cb1f5c860 COFF: Rename A.replaceWith(B) -> B.replace(A). NFC.
llvm-svn: 248197
2015-09-21 19:36:51 +00:00
Davide Italiano 8ca741d51d [ELF2] Support relocs for local symbols
Differential Revision:	 http://reviews.llvm.org/D12978

llvm-svn: 248196
2015-09-21 19:30:11 +00:00
Rui Ueyama 98a98cffb6 COFF: Do not call std::async with std::launch::async if multithreading is disabled.
llvm-svn: 248193
2015-09-21 19:12:36 +00:00
Rafael Espindola 53d5cea648 Rename SectionChunk to InputSection.
This is more consistent with OutputSection. This is also part of removing
the "Chunk" term from the ELF linker, since we just have input/output sections
and program headers.

llvm-svn: 248183
2015-09-21 17:47:00 +00:00
Rafael Espindola eb79273158 Start adding support for PLT.
For now this doesn't support lazy symbol resolution, but is enough to link
and run a program with

jmp foo@PLT

llvm-svn: 248165
2015-09-21 15:11:29 +00:00
Davide Italiano 1ab83f8d8e [ELF2] Accept -X/-x as alias for -discard-locals/-discard-all.
llvm-svn: 248134
2015-09-20 23:35:56 +00:00
Davide Italiano 5445b2de50 [ELF2] Implement support for -discard-locals.
This is not on by default, but it may make sense to change it in future.

llvm-svn: 248133
2015-09-20 21:58:12 +00:00
Rui Ueyama 5f38915624 COFF: Fix ICF regression.
This patch fixes a regression introduced by r247964. Relocations that
are referring the same symbol should be considered equal, but they
were not if they were pointing to non-section chunks.

llvm-svn: 248132
2015-09-20 20:19:12 +00:00
Rui Ueyama 997b357ac1 COFF: Run InputFile::parse() in background using std::async().
Previously, InputFile::parse() was run in batch. We construct a list
of all input files and call parse() on each file using parallel_for_each.
That means we cannot start parsing files until we get a complete list
of input files, although InputFile::parse() is safe to call from anywhere.

This patch makes it asynchronous. As soon as we add a file to the symbol
table, we now start parsing the file using std::async().

This change shortens self-hosting time (650 ms) by 28 ms. It's about 4%
improvement.

llvm-svn: 248109
2015-09-20 03:11:16 +00:00
Rui Ueyama f49712a853 COFF: Fix race condition.
NextID is updated inside parallel_for_each, so it needs mutual exclusion.

llvm-svn: 248106
2015-09-20 01:44:44 +00:00
Rui Ueyama 3cfd2bff1e Remove dead code.
llvm-svn: 248105
2015-09-20 01:19:36 +00:00
Rui Ueyama 1cce300843 COFF: Change Symbol::Body type from atomic pointer to regular pointer.
I made the field an atomic pointer in hope that we would be able to
parallelize the symbol resolver soon, but that's not going to happen
soon. This patch reverts that change for the sake of readability.

llvm-svn: 248104
2015-09-20 00:00:05 +00:00
Rui Ueyama 63bbe84b27 COFF: Make Chunk::writeTo() const. NFC.
This should improve code readability especially because this function
is called inside parallel_for_each.

llvm-svn: 248103
2015-09-19 23:28:57 +00:00
Rui Ueyama ebb0ebff4b COFF: Fix thread-safety bug.
LTOModule doesn't seem to be thread-safe, so guard that with mutex.

llvm-svn: 248102
2015-09-19 23:14:51 +00:00
Rui Ueyama a5f0f758d3 COFF: Move markLive() from Writer.cpp to its own file.
Conceptually, garbage collection is not part of Writer,
so move the function out of the file.

llvm-svn: 248099
2015-09-19 21:36:28 +00:00
Rui Ueyama 0652c59506 COFF: Actually parallelize InputFile::parse().
This is a follow-up patch to r248078.

llvm-svn: 248098
2015-09-19 21:33:26 +00:00
Rui Ueyama 27e9e6540c Remove unused #includes.
llvm-svn: 248081
2015-09-19 02:28:32 +00:00
Rui Ueyama f4d05d7a80 COFF: Parallelize InputFile::parse().
InputFile::parse() can be called in parallel with other calls of
the same function. By doing that, time to self-link improves from
741 ms to 654 ms or 12% faster.

This is probably the last low hanging fruit in terms of parallelism.
Input file parsing and symbol table insertion takes 450 ms in total.
If we want to optimize further, we probably have to parallelize
symbol table insertion using concurrent hashmap or something.
That's doable, but that's not easy, especially if you want to keep
the exact same semantics and linking order. I'm not going to do that
at least soon.

Anyway, compared to r248019 (the change before the first attempt for
parallelism), we achieved 36% performance improvement from 1022 ms
to 654 ms. MSVC linker takes 3.3 seconds to link the same program.
MSVC's ICF feature is very slow for some reason, but even if we
disable the feature, it still takes about 1.2 seconds.
Our number is probably good enough.

llvm-svn: 248078
2015-09-19 01:48:26 +00:00
Michael J. Spencer acf5bdfd88 [elf2] Improve relocation-undefined-weak.s test.
llvm-svn: 248071
2015-09-19 00:15:38 +00:00
Rui Ueyama 8197a4e0bf COFF: Use parallel_sort in Writer::sortExceptionTable().
This patch saves 4 ms out of 5 ms. Very small improvement,
but maybe better than nothing.

llvm-svn: 248063
2015-09-18 23:17:34 +00:00
Rui Ueyama 49e72e69e5 Fix build error that std::atomic is not copy-constructible.
llvm-svn: 248061
2015-09-18 22:58:12 +00:00
Rui Ueyama e629a45531 COFF: Address review comments.
- Fix race condition of `Redo`
- Avoid std::distance

llvm-svn: 248058
2015-09-18 22:31:15 +00:00
Michael J. Spencer 9779535c5d [elf2] Relocate against undefined weak symbols.
llvm-svn: 248056
2015-09-18 22:26:13 +00:00
Michael J. Spencer 658dccd1c8 [elf2] Relocate against common symbols.
llvm-svn: 248054
2015-09-18 22:13:25 +00:00
Rui Ueyama e0e0796d83 COFF: Parallelize Writer::writeSections().
Self-hosting took 801 ms on my machine. Of which this function took
69 ms. Now it takes 37 ms. That is about 4% overall performance
improvement.

llvm-svn: 248052
2015-09-18 22:07:10 +00:00
Michael J. Spencer 9567495154 [elf2] Convert if/else cascade into a covered switch. NFC.
llvm-svn: 248049
2015-09-18 21:48:38 +00:00
Rui Ueyama e8d1c59756 Style fix to make it look consistent. NFC.
llvm-svn: 248044
2015-09-18 21:17:44 +00:00
Rui Ueyama aa95e5a4cc COFF: Parallelize ICF.
The LLD's ICF algorithm is highly parallelizable. This patch does that
using parallel_for_each.

ICF accounted for about one third of total execution time. Previously,
it took 324 ms when self-hosting. Now it takes only 62 ms.

Of course your mileage may vary. My machine is a beefy 24-core Xeon machine,
so you may not see this much speedup. But this optimization should be
effective even for 2-core machine, since I saw speedup (324 ms -> 189 ms)
when setting parallelism parameter to 2.

llvm-svn: 248038
2015-09-18 21:06:34 +00:00
Davide Italiano f7892a1f3a [ELF2] Constify member functions.
llvm-svn: 248019
2015-09-18 18:28:08 +00:00
Rafael Espindola 5c2310c30c Start adding support for creating the GOT.
With this a program can call into a shared library with

  jmp *foo@GOTPCREL(%rip)

llvm-svn: 247992
2015-09-18 14:40:19 +00:00
Rui Ueyama 603d51104b COFF: Reorder comparisons.
This change makes equalsConstant a bit faster (193ms -> 163ms).

llvm-svn: 247965
2015-09-18 02:40:54 +00:00
Rui Ueyama 8c73dfb6bf COFF: Remove useless micro-optimization.
This patch simplifies code by removing micro-optimization that doesn't
contribute to speed.

llvm-svn: 247964
2015-09-18 02:15:34 +00:00
Rui Ueyama c9a6e827bd COFF: Optimize ICF by not creating temporary vectors.
Previously, ICF created a vector for each SectionChunk. The vector
contained pointers to successors, which are namely associative sections
and COMDAT relocation targets. The reason I created vectors is because
I thought that that would make section comparison faster.

It did make the comparison faster. When self-linking, for example, it
saved about 10 ms on each iteration. The time we spent on constructing
the vectors was 124 ms. If we iterate more than 12 times, return from
the investment exceeds the initial cost.

In reality, it usually needs 5 iterations. So we shouldn't construct
the vectors.

llvm-svn: 247963
2015-09-18 01:51:37 +00:00
Rui Ueyama 7d8263bf1d COFF: Optimize ICF by comparing relocations before section contents.
equalsConstants() is the heaviest function in ICF, and that consumes
more than half of total ICF execution time. Of which, section content
comparison accounts for roughly one third.

Previously, we compared section contents at the beginning of the
function after comparing their checksums. The comparison is very
likely to succeed because when the control reaches that comparison,
their checksums are always equal. And because checksums are 64-bit
CRC, they are unlikely to collide.

We compared relocations and associative sections after that.
If they are different, the time we spent on byte-by-byte comparison
of section contents were wasted.

This patch moves the comparison at the end of function. If the
comparison fails, the time we spent on relocation comparison are
wasted, but as I wrote it's very unlikely to happen.

LLD took 1198 ms to link itself to produce a 27.11 MB executable.
Of which, ICF accounted for 536 ms. This patch cuts it by 90 ms,
which is 17% speedup of ICF and 7.5% speedup overall. All numbers
are median of ten runs.

llvm-svn: 247961
2015-09-18 01:30:56 +00:00
Davide Italiano b5b47b432b [ELF2] Fill up local symbols fields correctly.
Differential Revision:	http://reviews.llvm.org/D12944

llvm-svn: 247960
2015-09-18 01:08:17 +00:00
Rui Ueyama 4151972c22 Enable extra LTO verification only when build type is debug.
llvm-svn: 247956
2015-09-17 22:54:08 +00:00
Rafael Espindola 8315b1c995 Remove dead member variable.
llvm-svn: 247949
2015-09-17 21:34:32 +00:00
Michael J. Spencer 879b597b9d [elf2] Extend program-header-layout.s to check that read only sections are correctly merged into the first PT_LOAD.
llvm-svn: 247947
2015-09-17 21:19:56 +00:00
Michael J. Spencer 55f56320c7 [elf2] Fix dynamic-reloc.s test.
The offset of the .rela.dyn section isn't the same between hosts because a path comes before it. This test doesn't care what the offset is.

llvm-svn: 247946
2015-09-17 21:13:41 +00:00
Michael J. Spencer 2f0082424f [elf2] Combine adjacent compatible OutputSections in PT_LOADs.
llvm-svn: 247925
2015-09-17 19:58:07 +00:00
Rafael Espindola 40102eb27f Use a MapVector to output symbols in a deterministic order.
We used to sort the symbols at the very end, but we need to know the order
earlier so that we can create reference to them in the dynamic relocations.

Thanks to Igor Kudrin for pointing out the problem.

llvm-svn: 247911
2015-09-17 18:26:25 +00:00
Rafael Espindola 67a5da60ed Add support of Elf_Rel dynamic relocations.
llvm-svn: 247888
2015-09-17 14:02:10 +00:00
Denis Protivensky 18add764f0 [ELF2] Fix typo in RelocationSection::hasRelocs method
llvm-svn: 247878
2015-09-17 09:54:29 +00:00
Rui Ueyama 63dd8766ab COFF: Remove DefinedSymbol::isLive() and markLive(). NFC.
Basically the concept of "liveness" is for sections (or chunks in LLD
terminology) and not for symbols. Symbols are always available or live,
or otherwise it indicates a link failure.

Previously, we had isLive() and markLive() methods for DefinedSymbol.
They are confusing methods. What they actually did is to act as a proxy
to backing section chunks. We can simplify eliminate these methods
and call section chunk's methods directly.

llvm-svn: 247869
2015-09-16 23:55:52 +00:00
Rui Ueyama 66c06ceaca COFF: ICF: Print out the number of iterations. NFC.
llvm-svn: 247868
2015-09-16 23:55:39 +00:00
Rafael Espindola eade07ba59 Start adding support for Elf_Rel.
I don't intend to add full i686 support right now, just make sure we have all
the infrastructure in place for it.

llvm-svn: 247858
2015-09-16 21:57:07 +00:00
Rui Ueyama 4dbff20c91 COFF: Fix bug that not all symbols were written to symtab if /opt:noref.
Only live symbols are written to the symbol table. Because isLive()
returned false if dead-stripping was disabled entirely, only
non-COMDAT sections were written to the symbol table. This patch fixes
the issue.

llvm-svn: 247856
2015-09-16 21:40:47 +00:00
Rui Ueyama 3b153e6541 COFF: Fix bug that /opt:noicf was ignored.
llvm-svn: 247854
2015-09-16 21:30:55 +00:00
Rui Ueyama 4bce7bcc88 COFF: Output messages for /verbose to stdout instead of stderr.
This patch also makes the message less verbose.

llvm-svn: 247853
2015-09-16 21:30:40 +00:00
Davide Italiano 6d328d3841 [ELF2] Initial support for local symbols.
Symbol table is now populated correctly, but some fields are missing,
they'll be added in the future. This patch also adds --discard-all
flag, which was the default behavior until now.

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

llvm-svn: 247849
2015-09-16 20:45:57 +00:00
Rafael Espindola 6569522f4b Relax the test to fix some bots.
The string table contains a file path, so addresses and offsets can be
different on some setups.

llvm-svn: 247839
2015-09-16 19:48:57 +00:00
Rafael Espindola 2b92d8f184 Move code computing NumEntries to finalize.
When DynamicSection is constructed we still don't know if there will be
any dynamic relocations or not.

llvm-svn: 247838
2015-09-16 19:26:31 +00:00
Rafael Espindola 3887ebfc21 Add DT_RELA and DT_RELASZ to the dynamic table.
llvm-svn: 247837
2015-09-16 18:52:42 +00:00
Rui Ueyama b02a320f5e COFF: Enable ICF by default.
MSVC linker enables ICF as long as /opt:ref is eanbled, so do we.

llvm-svn: 247817
2015-09-16 16:41:38 +00:00
Rui Ueyama c04d5dbf20 COFF: Rename /opt:lldicf -> /opt:icf.
Now that ICF is complete, we can rename this option so that
the driver accepts the MSVC-compatible command line option.

llvm-svn: 247816
2015-09-16 16:33:57 +00:00
Rafael Espindola 19e3889dba Start creating dynamic relocations.
For now we don't create got/plt and only Elf_Rela is supported.

llvm-svn: 247811
2015-09-16 15:54:15 +00:00
Rui Ueyama 92298d5418 COFF: Create ICF class to move code from SectionChunk to ICF. NFC.
This patch defines ICF class and defines ICF-related functions as
members of the class. By doing this we can move code that are
related only to ICF from SectionChunk to the newly-defined class.
This also eliminates a global variable "NextID".

llvm-svn: 247802
2015-09-16 14:19:10 +00:00
Rafael Espindola 37ecff14f4 Remove redundant "protected:".
llvm-svn: 247797
2015-09-16 13:47:45 +00:00
Simon Atanasyan 92480f9a20 [Mips] Rejects all --hash-style arguments except 'sysv' in case of MIPS target
MIPS ABI supports only --hash-style=sysv variant.

llvm-svn: 247796
2015-09-16 13:36:32 +00:00
Simon Atanasyan 49c67236f1 [Mips] Do not show an error if R_MIPS_GPREL32 relocation has a non-local target
This matches GNU linker behaviour.

llvm-svn: 247795
2015-09-16 13:36:24 +00:00
Rafael Espindola 72373fb5b7 Fix test to actually test something.
llvm-svn: 247790
2015-09-16 12:50:32 +00:00
Rui Ueyama 9cb2870ce0 ICF: Improve ICF to reduce more sections than before.
This is a patch to make LLD to be on par with MSVC in terms of ICF
effectiveness. MSVC produces a 27.14MB executable when linking LLD.
LLD previously produced a 27.61MB when self-linking. Now the size
is reduced to 27.11MB. Note that without ICF the size is 29.63MB.

In r247387, I implemented an algorithm that handles section graphs
as cyclic graphs and merge them using SCC. The algorithm did not
always work as intended as I demonstrated in r247721. The new
algortihm implemented in this patch is different from the previous
one. If you are interested the details, you want to read the file
comment of ICF.cpp.

llvm-svn: 247770
2015-09-16 03:26:31 +00:00
Michael J. Spencer 141dd91ac5 [elf2] Simplify overflow checks.
llvm-svn: 247768
2015-09-16 02:02:04 +00:00
Michael J. Spencer 75e5fda3de [elf2] Add R_X86_64_32S.
llvm-svn: 247758
2015-09-16 00:24:19 +00:00
Michael J. Spencer dff84070da [elf2] Add error checking for the R_X86_64_32 relocation.
llvm-svn: 247745
2015-09-15 23:36:30 +00:00
Michael J. Spencer 3c1ac0a17a [elf2] Relocate absolute symbols.
llvm-svn: 247738
2015-09-15 23:12:02 +00:00
Duncan P. N. Exon Smith a11f81973a LTO: Adjust to LLVM r247735
Perhaps lld wants to disable the verifier sometimes during COFF LTO, but
for now just match behaviour from before r247735.

llvm-svn: 247736
2015-09-15 23:06:16 +00:00
Rui Ueyama c26bbfe6b6 COFF: Add a test for ICF which LLD cannot handle yet.
In this test, we have two functions, foo and bar. MSVC linker can
choose one and discard the other using ICF. LLD cannot. I add this
test as a TODO.

foo and bar are conceptually equivalent to the following:

  void foo() { foo(); }
  void bar() { foo(); }

foo and bar are effectively the same function. If foo and bar are
compiled to the same instructions, both their contents (foo and bar)
and relocation targets (foo) become the same, so from the ICF point
of view, they are reducible. But their graphs are not isomorphic!
LLD's ICF algorithm cannot handle this case yet.

llvm-svn: 247721
2015-09-15 21:17:12 +00:00
Rafael Espindola e6451d9e74 Replace isa+cast with dyn_cast. NFC.
llvm-svn: 247691
2015-09-15 14:08:11 +00:00
Rafael Espindola a5c97d9025 Add support for R_X86_64_64.
llvm-svn: 247688
2015-09-15 13:52:06 +00:00
Rafael Espindola d1062bbd89 Make this test a bit more robust in preparation to adding more cases.
The first test (call) is now the only test to use .text, which makes it
resistant to more tests being added.

llvm-objdump -d already prints the addresses of symbols. We can use that in the
tests.

llvm-svn: 247685
2015-09-15 13:30:08 +00:00
Rafael Espindola 7d4038dc5a Use the same typedef style for all Elf_* types.
llvm-svn: 247680
2015-09-15 12:43:09 +00:00
Rui Ueyama b73002fb4e ELF2: Simplify by removing temporary variables.
llvm-svn: 247652
2015-09-15 01:03:58 +00:00
Rui Ueyama c48f78ca5a Fix typo.
llvm-svn: 247645
2015-09-15 00:35:41 +00:00
Rui Ueyama 13563d8645 Fix style.
llvm-svn: 247644
2015-09-15 00:33:11 +00:00
Rafael Espindola c92d28d427 Simplify, NFC.
Thanks to Rui for the suggestion.

llvm-svn: 247637
2015-09-14 23:28:02 +00:00
Rafael Espindola 80faee82e6 Add content to the .hash section.
This also sets DT_HASH.

With this simple shared libraries created by lld can be loaded by the dynamic
linker.

llvm-svn: 247625
2015-09-14 22:08:55 +00:00
Rui Ueyama 9078f73fa0 Use C++11 member initializers. NFC.
llvm-svn: 247613
2015-09-14 20:32:41 +00:00
Rafael Espindola 601771ebc0 Start adding the .hash output section.
It is still empty. Content will be added in the next patch.

llvm-svn: 247609
2015-09-14 20:20:34 +00:00
Rafael Espindola bfcdfb32af Correctly align sections.
We have to align the start, not the end.

This should fix crashes on systems where memcpy enforces the expected
alignment.

llvm-svn: 247599
2015-09-14 19:00:35 +00:00
Rui Ueyama 8e186df2f5 COFF: Corrected error message if a section failed to load.
There is no sense to use Name in these lines as it is not initialized yet.

Patch from Igor Kudrin!

llvm-svn: 247531
2015-09-13 20:22:22 +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
Rafael Espindola 1d12ab3db1 Fix handling of _start being undefined.
We were crashing before.

llvm-svn: 247481
2015-09-11 21:44:55 +00:00
Rafael Espindola 92b6c15cce Fix a copy and paste error. Sorry about that.
llvm-svn: 247478
2015-09-11 21:26:42 +00:00
Rafael Espindola 2e9eac13c7 Implement -rpath.
llvm-svn: 247475
2015-09-11 21:18:56 +00:00
Rafael Espindola 7174dcfb0f Don't make assumptions about the size of the dynamic string table.
It contains pathnames, so it can be different in each machine.

llvm-svn: 247453
2015-09-11 19:12:37 +00:00
Rafael Espindola 7010776db7 Implement the -dynamic-linker option.
With this dynamic executables can be executed with just ./t instead of
/lib64/ld-2.20.so ./t

llvm-svn: 247446
2015-09-11 18:49:42 +00:00
Rafael Espindola 5723fcd015 Make this test a bit more resistant to section number changes.
llvm-svn: 247439
2015-09-11 17:53:01 +00:00
Rafael Espindola d67bb26642 Add more information to a comment.
llvm-svn: 247408
2015-09-11 13:20:07 +00:00
Rui Ueyama 5b93aa51de COFF: Teach ICF to merge cyclic graphs.
Previously, LLD's ICF couldn't merge cyclic graphs. That was unfortunate
because, in COFF, cyclic graphs are not exceptional at all. That is
pretty common.

In this patch, sections are grouped by Tarjan's strongly connected
component algorithm to get acyclic graphs. And then we try to merge
SCCs whose outdegree is zero, and remove them from the graph. This
makes other SCCs to have outdegree zero, so we can repeat the
process until all SCCs are removed. When comparing two SCCs, we handle
cycles properly.

This algorithm works better than previous one. Previously, self-linking
produced a 29.0MB executable. It now produces a 27.7MB. There's still some
gap compared to MSVC linker which produces a 27.1MB executable for the
same input. So the gap is narrowed, but still LLD is not on par with MSVC.
I'll investigate that later.

llvm-svn: 247387
2015-09-11 04:29:03 +00:00
David Blaikie 947bf5e0bb [opaque pointer type] update test cases for explicit pointee types on global aliases
llvm-svn: 247379
2015-09-11 03:22:12 +00:00
Rafael Espindola 243d90f549 Add a DT_SYMTAB entry in the dynamic section.
With this a trivial shared binary runs with the glibc dynamic linker:

LD_LIBRARY_PATH=.  /lib64/ld-2.20.so ./t

llvm-svn: 247370
2015-09-11 01:14:39 +00:00
Rafael Espindola fb815282d5 Create a dynamic symbol table.
For now it includes every symbol in the regular table. Since we don't
create dynamic relocations yet, we don't have a good way of knowing which
symbols are actually needed.

llvm-svn: 247365
2015-09-11 00:30:13 +00:00
Rafael Espindola 24d07fdd27 Cache the bss output section in the writer, not in the symbol table.
There is soon going to be two symbol tables, but there will still be only one
output bss.

llvm-svn: 247363
2015-09-11 00:10:11 +00:00
Rafael Espindola dd34a4d3c5 Make a few details of the string and symbol table private.
This is in preparation to adding a dynamic string table.

llvm-svn: 247355
2015-09-10 22:49:06 +00:00
Rafael Espindola 65db630fe7 Fix a warning when building with gcc.
It was

/Writer.cpp:119:45: warning: enumeral and non-enumeral type in conditional expression

llvm-svn: 247330
2015-09-10 20:02:22 +00:00
Rui Ueyama 9071e4a6fa Fix Clang-tidy misc-use-override warnings, other minor fixes.
Patch from Eugene Zelenko!

llvm-svn: 247323
2015-09-10 18:51:36 +00:00
Rafael Espindola 0a2e211ace Create a PT_LOAD program header for the start of the file.
With this a trivial dynamic program works with the musl dynamic linker:

LD_LIBRARY_PATH=.  ~/musl/lib/libc.so ./t

llvm-svn: 247290
2015-09-10 15:41:34 +00:00
Rafael Espindola 60252d8feb Change the load addr into something that works on linux x86_64.
With this simple static programs run again.

llvm-svn: 247205
2015-09-09 22:53:55 +00:00
Michael J. Spencer 1d299a8a9d [elf2] Assign output sections to PHDRs.
This is a minimal implementation to produce legal output. Future patches will combine multiple compatible PT_LOADs.

llvm-svn: 247185
2015-09-09 20:48:09 +00:00
Rafael Espindola 778562fc78 Add the DT_NEEDED entries to the dynamic table.
llvm-svn: 247181
2015-09-09 20:26:23 +00:00
Rui Ueyama d5004e1c69 Fix indentation.
llvm-svn: 247169
2015-09-09 18:02:23 +00:00
Rui Ueyama 6666f6ad73 ELF2: Reduce nesting by returning early. NFC.
llvm-svn: 247168
2015-09-09 17:55:09 +00:00
Rui Ueyama 7da94a58a0 ELF2: Return early. NFC.
llvm-svn: 247165
2015-09-09 17:40:51 +00:00
Rafael Espindola 3f4228f613 Start adding content to the dynamic section.
With this patch we create a dynamic string table (it is allocated, unlike
the regular one) and the dynamic section has a DT_STRTAB pointing to it.

llvm-svn: 247155
2015-09-09 15:33:08 +00:00
Rafael Espindola e438e07856 Create a dynamic segment.
It is still empty. I will add content next.

llvm-svn: 247097
2015-09-08 22:55:28 +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 18608a0a55 Simplify using namespaces and typedefs. NFC.
llvm-svn: 247079
2015-09-08 21:57:31 +00:00
Rafael Espindola b9fe03d4a9 Revert "[lld][elf2] Fix hard coded entry address."
This reverts commit r247073.

It broke

    lld :: elf2/basic32be.s
    lld :: elf2/basic64be.s

llvm-svn: 247077
2015-09-08 21:32:44 +00:00
Michael J. Spencer 8be15899b4 [lld][elf2] Fix hard coded entry address.
llvm-svn: 247073
2015-09-08 21:11:25 +00:00
Michael J. Spencer 88f0d63bea [lld][elf2] Fix style.
llvm-svn: 247064
2015-09-08 20:36:20 +00:00
Rafael Espindola 740fafe54d Start creating the .dynamic section.
For now it is always empty.

llvm-svn: 247056
2015-09-08 19:43:27 +00:00
Rafael Espindola 57b2592ace Don't treat the string table index specially. NFC.
We assign the string table section an index like every other section, we can
use it from there.

llvm-svn: 247051
2015-09-08 19:23:30 +00:00
Rafael Espindola b01b57486d Bug fix: Assign output section indexes *after* sorting them.
llvm-svn: 247037
2015-09-08 18:08:57 +00:00
Rafael Espindola 5f55387251 Every output section should be added to the OutputSecitons vector.
Simplify.

llvm-svn: 247032
2015-09-08 17:39:39 +00:00