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
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
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
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
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
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
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
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
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
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
4b2ca85c1a
Implement --allow-multiple-definition.
...
Patch by George Rimar!
llvm-svn: 248733
2015-09-28 20:30:11 +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
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
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
cde9336717
[ELF2] Add initial AArch64 support.
...
Differential Revision: http://reviews.llvm.org/D13167
llvm-svn: 248641
2015-09-26 00:32:04 +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
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
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
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
e44456b1b9
[ELF2] Constify getStrTabSec().
...
llvm-svn: 248360
2015-09-23 01:50:53 +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
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
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
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
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
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
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
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
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
Rafael Espindola
8315b1c995
Remove dead member variable.
...
llvm-svn: 247949
2015-09-17 21:34:32 +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
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
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
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
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
Rafael Espindola
37ecff14f4
Remove redundant "protected:".
...
llvm-svn: 247797
2015-09-16 13:47:45 +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
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
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
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
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
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
d67bb26642
Add more information to a comment.
...
llvm-svn: 247408
2015-09-11 13:20:07 +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
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
Rafael Espindola
18173d420e
Start adding support for symbols in shared libraries.
...
llvm-svn: 247019
2015-09-08 15:50:05 +00:00
Rafael Espindola
4f624b9581
Simplify reporting of undefined symbols.
...
llvm-svn: 247016
2015-09-08 14:32:29 +00:00
Rafael Espindola
a4dd7c1d38
Revert "[elf2] Add 32S and 64 relocations (needed for musl)."
...
This reverts commit r246902. It had uncessary use of yaml.
llvm-svn: 247014
2015-09-08 13:52:31 +00:00
Michael J. Spencer
1b3fffa6e0
[elf2] Add 32S and 64 relocations (needed for musl).
...
It wasn't obvious what the assembly was to generate these relocations, so I did the test with yaml.
llvm-svn: 246902
2015-09-05 00:36:03 +00:00
Michael J. Spencer
baae538cc6
[elf2] Correctly handle sections with an alignment of 0. Spec says to treat it as an alignment of 1.
...
llvm-svn: 246901
2015-09-05 00:25:33 +00:00
Michael J. Spencer
f832541066
[elf2] Fix include order.
...
llvm-svn: 246892
2015-09-04 22:48:30 +00:00
Michael J. Spencer
1b348a68e5
[elf2] Add basic archive file support.
...
llvm-svn: 246886
2015-09-04 22:28:10 +00:00
Davide Italiano
ad6c81c628
[ELF2] Writer: Fold variables, use setVisibility(). NFCI.
...
llvm-svn: 246861
2015-09-04 19:42:14 +00:00
Rafael Espindola
824d1a975f
Add a template helper to avoid multiple switches over the ELF kind. NFC.
...
llvm-svn: 246823
2015-09-04 00:09:43 +00:00
Rafael Espindola
55eed7efcd
Avoid gcc warning.
...
llvm-svn: 246811
2015-09-03 22:25:11 +00:00
Davide Italiano
34812ba258
[ELF2] Don't allocate more SymbolBodies than needed.
...
Differential Revision: http://reviews.llvm.org/D12605
llvm-svn: 246802
2015-09-03 20:25:54 +00:00
Rafael Espindola
f98d6d84cd
Start adding support for shared libraries.
...
This just adds the types and enough support to detect incompatibilities among
shared libraries and object files.
llvm-svn: 246797
2015-09-03 20:03:54 +00:00
Rafael Espindola
8aeb13fec1
Add a helper function for getting the first object file.
...
Also preparation for shared objects. It will become the first ELF file.
llvm-svn: 246796
2015-09-03 19:13:13 +00:00
Rafael Espindola
222edc66d6
Make ObjectFiles private. NFC.
...
Just preparation for adding support for shared libraries.
llvm-svn: 246793
2015-09-03 18:56:20 +00:00
Rafael Espindola
8788e1a630
Make getSymbols non-virtual. NFC.
...
llvm-svn: 246731
2015-09-02 23:01:37 +00:00
Rafael Espindola
905ad3442d
Split out the ELF kind from the InputFile Kind.
...
There were at least two issues with having them together:
* For compatibility checks, we only want to look at the ELF kind.
* Adding support for shared libraries should introduce one InputFile kind,
not 4.
llvm-svn: 246707
2015-09-02 20:43:43 +00:00
Rafael Espindola
78471f0ec1
Merge visibility from all symbols with the same name.
...
The ELF spec says:
... if any reference to or definition of a name is a symbol with a
non-default visibility attribute, the visibility attribute must be
propagated to the resolving symbol in the linked object. If different
visibility attributes are specified for distinct references to or
definitions of a symbol, the most constraining visibility attribute
must be propagated to the resolving symbol in the linked object. The
attributes, ordered from least to most constraining, are:
STV_PROTECTED, STV_HIDDEN and STV_INTERNAL.
llvm-svn: 246603
2015-09-01 23:12:52 +00:00
Rafael Espindola
ee1364f7f6
Don't leave unused strings in the string table.
...
llvm-svn: 246593
2015-09-01 21:47:21 +00:00
Rafael Espindola
5b3942f54a
Don't include hidden or internal symbols in the symbol table.
...
llvm-svn: 246583
2015-09-01 20:36:51 +00:00
Rafael Espindola
7f37775e56
Every symbol now has an Elf_Sym. Simplify. NFC.
...
llvm-svn: 246581
2015-09-01 20:30:52 +00:00
Rafael Espindola
06c3a6d676
Start recording st_other (i.e. visibility).
...
llvm-svn: 246577
2015-09-01 19:42:38 +00:00
Rafael Espindola
f31f9617ca
Remember the maximum alignment used to refer to a common symbol.
...
llvm-svn: 246517
2015-09-01 01:19:12 +00:00
Rafael Espindola
b56cb9437f
Sort common symbols by alignment.
...
llvm-svn: 246511
2015-09-01 00:16:38 +00:00
Rafael Espindola
ce8c9c0548
Set the correct value for the common symbols.
...
In the relocatable object it is the alignment, but in the linked file it is
a regular address.
llvm-svn: 246505
2015-08-31 22:55:21 +00:00
Rafael Espindola
8b09d68447
Assign common symbols to the .bss output section.
...
llvm-svn: 246503
2015-08-31 22:33:21 +00:00
Rafael Espindola
0518574a73
Start allocating space for common symbols.
...
llvm-svn: 246496
2015-08-31 22:07:18 +00:00
Rafael Espindola
058f343246
Don't allocate space for SHT_NOBITS sections.
...
llvm-svn: 246480
2015-08-31 20:23:57 +00:00
Rafael Espindola
f7d45f0869
Delete SyntheticUndefined.
...
Now that resolved is templated anyway, we can use the regular Undefined.
llvm-svn: 246407
2015-08-31 01:46:20 +00:00
Rafael Espindola
daa92a6193
Keep the largest common symbol.
...
This requires templating some functions over ELFT, but that opens other cleanup
opportunities for future patches.
llvm-svn: 246405
2015-08-31 01:16:19 +00:00
Rafael Espindola
30e1797b38
Turn resolution.s into an exhaustive testcase.
...
Now that we print a symbol table and all symbol kinds are at least declared,
we can test all combinations that don't produce an error.
This also includes a few fixes to keep the test passing:
* Keep the strong symbol in a weak X strong pair
* Handle common symbols.
The common X common case will be finished in a followup patch.
llvm-svn: 246401
2015-08-30 23:17:30 +00:00
Davide Italiano
94f183a696
[ELFv2] Implement R_X86_64_32 relocation.
...
Differential Revision: http://reviews.llvm.org/D12436
llvm-svn: 246362
2015-08-29 13:15:42 +00:00
Rafael Espindola
51d4690b6e
Start adding support for common symbols.
...
For now this just recognizes the special section number.
llvm-svn: 246332
2015-08-28 21:26:51 +00:00
Rafael Espindola
3a63f3fb22
Add support for weak absolute symbols.
...
On ELF being weak is independent of what we call the kind of the symbol. So
this also makes the code simpler.
llvm-svn: 246326
2015-08-28 20:19:34 +00:00
Rafael Espindola
871765c321
Make sure we output symbols in the same order on 32 and 64 bit builds.
...
llvm-svn: 246264
2015-08-28 02:46:41 +00:00
Rafael Espindola
f2f41a9f97
Fix the gcc build:
...
InputFiles.h:98:53: error: invalid use of incomplete type ‘class lld::elf2::SymbolBody’
return SymbolBodies[SymbolIndex - FirstNonLocal]->getReplacement();
llvm-svn: 246262
2015-08-28 02:40:04 +00:00
Michael J. Spencer
67bc8d6b3f
[elf2] Add basic relocation support for x86-64.
...
This currently doesn't handle local symbols.
Differential Revision: http://reviews.llvm.org/D11612
llvm-svn: 246234
2015-08-27 23:15:56 +00:00
Rafael Espindola
0e0c1901c9
Start adding support for absolute symbols.
...
llvm-svn: 246147
2015-08-27 12:40:06 +00:00
Rafael Espindola
e11c6d2d6f
Set the symbol size in the symbol table.
...
llvm-svn: 246086
2015-08-26 21:46:24 +00:00
Rafael Espindola
034e2e7a8e
Define types close to use. NFC.
...
llvm-svn: 246085
2015-08-26 21:42:36 +00:00
Rafael Espindola
b85b4079f1
git-clang-format the constructor to reduce the diff in a merge.
...
llvm-svn: 246076
2015-08-26 20:46:55 +00:00
Rafael Espindola
f3837074cc
Set the symbol value in the symbol table.
...
llvm-svn: 245943
2015-08-25 15:53:17 +00:00
Rafael Espindola
5cd113df01
Diagnose symbols with invalid section indexes.
...
llvm-svn: 245884
2015-08-24 22:00:25 +00:00
Rafael Espindola
2034822981
Add support for reading files with more than 0xff00 sections.
...
llvm-svn: 245880
2015-08-24 21:43:25 +00:00
Rafael Espindola
832b93f219
Start recording the section of symbols in the symbol table.
...
Support for more than 64 K sections to follow shortly.
llvm-svn: 245868
2015-08-24 20:06:32 +00:00
Rafael Espindola
c5c82916e4
Read the alignment only when used.
...
The rest of the header was already read lazily, no point in having align be
special.
llvm-svn: 245863
2015-08-24 19:28:31 +00:00
Rafael Espindola
e6f52102a3
Remove a duplicated member variable. NFC.
...
This just makes it clear that, for now, there is only one symbol table.
llvm-svn: 245844
2015-08-24 14:48:18 +00:00
Rui Ueyama
570752c7ac
Do not use unique pointers. NFC.
...
These unique pointers have the exact same lifetime as automatic
variables, so use automatic variables instead.
llvm-svn: 245281
2015-08-18 09:13:25 +00:00
Rafael Espindola
1bd885aba4
ELF: Also record the type of undefined symbols.
...
Tested with a weak undefined. Testing with a plain undefined will have to wait
for support for -shared.
llvm-svn: 245069
2015-08-14 16:46:28 +00:00
Rafael Espindola
bd481b8f89
Fix the build with gcc.
...
llvm-svn: 245060
2015-08-14 15:20:34 +00:00
Rafael Espindola
c44d17ad45
Add the type of the symbols to the symbol table.
...
For now only defined symbols are covered. I will add undefined ones in the
next patch.
llvm-svn: 245057
2015-08-14 15:10:49 +00:00
Rafael Espindola
457c940835
Delete dead code.
...
llvm-svn: 245056
2015-08-14 14:58:57 +00:00
Rafael Espindola
4c3aa0f228
Delete unused forward declarations.
...
llvm-svn: 245055
2015-08-14 14:51:11 +00:00
Rafael Espindola
3bf356ee9c
Remove unused default values.
...
llvm-svn: 245053
2015-08-14 14:38:44 +00:00
Rafael Espindola
beee25e484
Make these headers as being c++.
...
llvm-svn: 245050
2015-08-14 14:12:54 +00:00
Rafael Espindola
383c323d4d
ELF: Set the correct symbol binding.
...
llvm-svn: 245049
2015-08-14 13:52:36 +00:00
Rafael Espindola
62b81b875a
Start populating the symbol table.
...
With this patch only the name is set. I will set the other fields shortly.
For now the table doesn't include local symbols. This is equivalent to using
--discard-all with gnu ld. This is OK for now since the symbols are not
needed for execution and for testing symbol resolution we only need the
global symbols.
llvm-svn: 245044
2015-08-14 13:07:05 +00:00
Rui Ueyama
8050d32b13
ELF2: Rename a function to make it the same as the COFF's counterpart.
...
llvm-svn: 245030
2015-08-14 05:17:30 +00:00
Rafael Espindola
f763ca3c9c
ELF: Create a symbol table.
...
For now it is empty. I will add the symbols in a followup patch.
llvm-svn: 245008
2015-08-14 02:42:20 +00:00
Rafael Espindola
83b0dc6392
ELF: Drop the Chunk base class.
...
With OutputSection being a virtual interface, each concrete OutputSection
handles only one type of chunk and we don't need a base Chunk class.
So for we have a class that handles input sections and one that handles
the string table, but this extends naturally for other outputs (symbol table,
merging of SHF_MERGE sections, etc.).
llvm-svn: 244972
2015-08-13 22:21:37 +00:00
Rafael Espindola
ebd2108215
Make OutputSection virtual and use that for creating the string table.
...
We were creating the string table in a completely ad hoc way. Now the
string table is an output section and gets its output offset set just like
any other section.
This opens the way for other linker created sections like the symbol table.
llvm-svn: 244969
2015-08-13 22:14:37 +00:00
Rafael Espindola
2db634d8f1
Correctly align output sections.
...
They don't need to be aligned to page boundaries. Only segments need that.
llvm-svn: 244942
2015-08-13 20:24:18 +00:00
Rafael Espindola
0160a281c2
Record the alignment of the output sections.
...
llvm-svn: 244941
2015-08-13 20:13:39 +00:00
Rafael Espindola
5d83ccd55b
Make getSectionName non virtual. NFC.
...
llvm-svn: 244939
2015-08-13 19:18:30 +00:00
Rafael Espindola
ea133eaa39
Delete dead code.
...
llvm-svn: 244938
2015-08-13 19:00:23 +00:00
Rafael Espindola
a175eb6ca6
Template OutputSection only over Is64Bit.
...
This is a bit more c++ code, but:
* It is less machine code: lld's text is 44688 bytes smaller.
* It should be a bit more efficient in the non native endian case.
* It should be a bit more efficient on architectures with slow unaligned access.
llvm-svn: 244934
2015-08-13 18:37:23 +00:00
Rafael Espindola
184d94e009
Define trivial methods inline. NFC.
...
llvm-svn: 244930
2015-08-13 18:25:47 +00:00
Rafael Espindola
64e888ba5f
Set the file offset of zero sized sections.
...
There is no reason not to do it and this matches what gold and bfd ld do.
llvm-svn: 244929
2015-08-13 18:23:43 +00:00
Rafael Espindola
29e8d343e4
Rename addSectionChunk to addChunk now that it can handle any Chunk.
...
llvm-svn: 244919
2015-08-13 17:35:13 +00:00
Rafael Espindola
375a508234
Pass the type and flags to the OutputSection constructor. NFC.
...
This will allow further cleanups.
llvm-svn: 244918
2015-08-13 17:32:30 +00:00
Rafael Espindola
a7471795ae
Take name, type and flags in consideration when concatenating sections.
...
This is mandated by the ELF spec.
llvm-svn: 244911
2015-08-13 17:04:50 +00:00
Rafael Espindola
674b5d570f
Store the offset in the output section, no in the file.
...
That is the value that is stable as the we layout the output sections.
llvm-svn: 244904
2015-08-13 15:54:36 +00:00
Rafael Espindola
ef1ac01c2e
Don't give an address to sections that are not allocated.
...
llvm-svn: 244900
2015-08-13 15:31:17 +00:00
Rafael Espindola
abad6186c3
Place SHF_ALLOC sections first in the output.
...
Having them in the middle of the file complicates the creation of segments.
llvm-svn: 244898
2015-08-13 15:23:46 +00:00
Rafael Espindola
25f51850a4
Delete dead code.
...
llvm-svn: 244896
2015-08-13 14:48:49 +00:00
Rafael Espindola
cde251370a
Include non-alloca sections in the link.
...
llvm-svn: 244895
2015-08-13 14:45:44 +00:00
Rafael Espindola
bdc8f2fb83
Update for llvm api change.
...
llvm-svn: 244849
2015-08-13 00:31:46 +00:00
Rafael Espindola
372889a8e6
Fix an use of uninitialized.
...
Should fix some tests on windows.
llvm-svn: 244834
2015-08-12 23:25:42 +00:00
Rafael Espindola
91009b3856
Fix the alignment of the section headers.
...
Thanks a lot to Rui for noticing it.
llvm-svn: 244711
2015-08-12 01:45:28 +00:00
Rafael Espindola
6b83b90b6a
ELF: Create a string table.
...
For now only the sections are in it, but it already makes the output easier
to read and test.
llvm-svn: 244702
2015-08-12 00:00:24 +00:00
Rui Ueyama
4f89fdad9f
ELF2: Make Defined{Regular,Weak} ctors look the same as other SymbolBody ctors.
...
llvm-svn: 244701
2015-08-11 23:37:25 +00:00
Rafael Espindola
021834046f
Template ELF's OutputSection.
...
This removes what I think is the last hard coded ELF64 structure.
llvm-svn: 244700
2015-08-11 23:34:29 +00:00
Rafael Espindola
52a0f1e8c6
Move more code that is local to Writer.cpp to an anonymous namespace.
...
llvm-svn: 244697
2015-08-11 23:22:24 +00:00
Rafael Espindola
5211c2a1a0
Delete dead code.
...
llvm-svn: 244696
2015-08-11 23:19:06 +00:00
Rafael Espindola
98f6bd09e4
Be a bit more consistent about using uintX_t for offsets and sizes. NFC.
...
llvm-svn: 244694
2015-08-11 23:14:13 +00:00
Rui Ueyama
880632c458
ELF2: Remove unused global variable.
...
A global variable "Driver" is to re-entry to the driver to parse a
.drectve section. Because the need is COFF-specific, we don't need
this variable for ELF.
llvm-svn: 244680
2015-08-11 21:45:55 +00:00
Reid Kleckner
f7b85e0ce2
Fix mismatched sign comparison
...
llvm-svn: 244653
2015-08-11 20:06:51 +00:00
Rafael Espindola
76e24ea955
Add support for weak undefined symbols.
...
llvm-svn: 244640
2015-08-11 17:57:05 +00:00
Rafael Espindola
791e9f9c59
Remove unused templating.
...
llvm-svn: 244639
2015-08-11 17:51:57 +00:00
Rafael Espindola
b13df6582a
Add support for weak symbols.
...
llvm-svn: 244636
2015-08-11 17:33:02 +00:00
Rafael Espindola
ae1b23bd61
Use real values for DefindeFirst and DefinedLast.
...
With this clang notices that switches are fully covered.
llvm-svn: 244632
2015-08-11 17:10:02 +00:00
Rafael Espindola
9247f165ff
Delete unused typedef.
...
llvm-svn: 244628
2015-08-11 16:55:28 +00:00
Rafael Espindola
7c388187c9
Don't report a conflict between two local symbols.
...
llvm-svn: 244624
2015-08-11 16:30:34 +00:00
Rafael Espindola
d8340dae0c
Don't depend on getDotSymtabSec. It is going away.
...
llvm-svn: 244451
2015-08-10 15:12:17 +00:00
Rafael Espindola
1a9344fa26
Use already available symbol tables. NFC.
...
llvm-svn: 244336
2015-08-07 17:16:28 +00:00
Rafael Espindola
df1e05a26c
Delete broken code.
...
This was using a hard coded string table and getting it for every symbol.
The symbol name was already available.
llvm-svn: 244220
2015-08-06 15:33:21 +00:00
Rafael Espindola
49a2ca6ddd
bar
...
llvm-svn: 244219
2015-08-06 15:33:19 +00:00
Rafael Espindola
192e1fa59d
Move the error handling functions to Error.h. NFC.
...
llvm-svn: 244216
2015-08-06 15:08:23 +00:00
Rui Ueyama
cb8474edae
COFF, ELF2: Pass output file path implicitly using Config global variable.
...
Various parameters are passed implicitly using Config global variable
already. Output file path is no different from others, so there was no
special reason to handle that differnetly.
This patch changes the signature of writeResult(SymbolTable *, StringRef)
to writeResult(SymbolTable *).
llvm-svn: 244180
2015-08-05 23:51:50 +00:00
Rui Ueyama
afff74e228
ELF2: Simplify Writer interface.
...
We are using Writer more like a function instead of a class.
This patch makes it a function to simplify the interface.
All details of Writer class is now hidden from other parts of the linker.
llvm-svn: 244169
2015-08-05 23:24:46 +00:00
Rafael Espindola
4b7c2fc64e
Add bare minimum to get a working i386 linux program.
...
llvm-svn: 244050
2015-08-05 15:08:40 +00:00
Rafael Espindola
e7a00e326a
For now we only have on Chunk type. Simplify.
...
The others we have in sight are
* common symbols.
* entries in SHF_MERGE sections.
They will have a substantially different treatment. It is not clear if it is
worth it putting them all in a single list just to dispatch based on the kind on
the other side.
I hope to implement common symbols soon, and then we will be in a position
to have a concrete discussion. For now this is simpler for the the implemented
features.
llvm-svn: 244042
2015-08-05 13:55:34 +00:00
Rafael Espindola
e3335d8a66
Delete dead code.
...
llvm-svn: 244040
2015-08-05 13:26:54 +00:00
Rafael Espindola
3c9cb4b3d3
lld elf2: Diagnose trying to mix incompatible files.
...
This is also a step in instantiating the writer with the correct template
argument.
llvm-svn: 244035
2015-08-05 12:03:34 +00:00
Rafael Espindola
87ee8dcb64
Use ELFOSABI_NONE. This matches both bfd ld and gold.
...
llvm-svn: 244033
2015-08-05 11:55:52 +00:00
Rafael Espindola
aefd5c1617
Create ObjectFile with the correct endian and word size.
...
The writer is still hard coded to 64 bits le, but with this we can test for
invalid ELF files.
llvm-svn: 243993
2015-08-04 15:45:54 +00:00
Rafael Espindola
e0a5c09a5c
Use make_unique. NFC.
...
llvm-svn: 243988
2015-08-04 15:06:36 +00:00
Rafael Espindola
2ffdd4d0e5
The SymbolTable doesn't need to be a template.
...
It was already using just code that is common to all object files.
llvm-svn: 243985
2015-08-04 14:29:01 +00:00
Rafael Espindola
602592a048
Remove a silly return.
...
llvm-svn: 243983
2015-08-04 14:08:11 +00:00
Rafael Espindola
30318518a5
This function never returns null, don't check it.
...
llvm-svn: 243982
2015-08-04 14:00:56 +00:00
Rafael Espindola
b89951457d
Remove SymbolTable::getChunks.
...
When we were using a std::sort over all the chunks we needed to put them in a
single storage.
Now that we just iterate over them and use a map to find the output section,
we can avoid allocating the temporary storage.
llvm-svn: 243980
2015-08-04 13:39:30 +00:00
Michael J. Spencer
44fc1c0a73
[ELF2] Templatize addChunk and handle section flags.
...
llvm-svn: 243579
2015-07-29 22:14:50 +00:00
Rui Ueyama
b4731a5847
ELF2: Use DenseMap instead of std::map for a symbol table.
...
We use DenseMap for COFF too.
llvm-svn: 243534
2015-07-29 16:30:40 +00:00
Michael J. Spencer
5a6f5f178e
[ELF2] Emit correct section types.
...
llvm-svn: 243509
2015-07-29 00:52:17 +00:00
Michael J. Spencer
8039dae26d
[ELF2] Emit section table.
...
llvm-svn: 243506
2015-07-29 00:30:10 +00:00
Michael J. Spencer
cdae0a4e2d
[ELF2] Devirtualize SymbolBody.
...
llvm-svn: 243496
2015-07-28 22:58:25 +00:00
Rui Ueyama
e44524de65
Use SmallDenseMap instead of std::map where we don't care about order of keys.
...
llvm-svn: 243358
2015-07-28 00:17:25 +00:00
Rui Ueyama
fdbbcdad87
ELF2: Inline very small functions.
...
llvm-svn: 243323
2015-07-27 20:39:04 +00:00
Rui Ueyama
a7ccb2926f
ELF2: Devirtualize SymbolBody::compare. NFC.
...
This is to make it consistent with COFF.
llvm-svn: 243321
2015-07-27 20:39:01 +00:00
Rui Ueyama
06d7bd2e42
ELF2: Avoid calling std::sort to make output deterministic.
...
llvm-svn: 243232
2015-07-26 00:50:15 +00:00
Rui Ueyama
179cd7b82a
ELF2: Remove dead code.
...
llvm-svn: 243231
2015-07-26 00:50:13 +00:00
Michael J. Spencer
84487f1174
[ELF2] Add a new ELF linker based on the new PE/COFF linker.
...
Differential Revision: http://reviews.llvm.org/D11188
llvm-svn: 243161
2015-07-24 21:03:07 +00:00
Michael J. Spencer
bae540e945
Revert ELF port. Posting to mailing list.
...
llvm-svn: 242118
2015-07-14 04:49:48 +00:00
Michael J. Spencer
50ed5308d1
Fix warnings.
...
llvm-svn: 242098
2015-07-14 01:02:37 +00:00
Michael J. Spencer
f754b1fe12
Put explicit template instantiations in the correct namespace.
...
llvm-svn: 242093
2015-07-14 00:22:00 +00:00
Michael J. Spencer
64661cdb4c
Remove commented out code.
...
llvm-svn: 242092
2015-07-14 00:11:38 +00:00
Michael J. Spencer
8a4145411f
Initial ELF port.
...
This is a direct port of the new PE/COFF linker to ELF.
It can take a single object file and generate a valid executable that executes at the first byte in the text section.
llvm-svn: 242088
2015-07-13 23:48:06 +00:00