Commit Graph

3871 Commits

Author SHA1 Message Date
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
Rui Ueyama
3c28ba38de COFF: Split doICF(). No functionality change.
llvm-svn: 246934
2015-09-05 23:06:32 +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
Rui Ueyama
ef907ec82d COFF: Implement a better algorithm for ICF.
Identical COMDAT Folding is a feature to merge COMDAT sections
by contents. Two sections are considered the same if their contents,
relocations, attributes, etc, are all the same.

An interesting fact is that MSVC linker takes "iterations" parameter
for ICF because the algorithm they are using is iterative. Merging
two sections could make more sections to be mergeable because
different relocations could now point to the same section. ICF is
repeated until we get a convergence (until no section can be merged).
This algorithm is not fast. Usually it needs three iterations until a
convergence is obtained.

In the new algorithm implemented in this patch, we consider sections
and relocations as a directed acyclic graph, and we try to merge
sections whose outdegree is zero. Sections with outdegree zero are then
removed from the graph, which makes  other sections to have outdegree
zero. We repeat that until all sections are processed. In this
algorithm, we don't iterate over the same sections many times.

There's an apparent issue in the algorithm -- the section graph is
not guaranteed to be acyclic. It's actually pretty often cyclic.
So this algorithm cannot eliminate all possible duplicates.
That's OK for now because the previous algorithm was not able to
eliminate cycles too. I'll address the issue in a follow-up patch.

llvm-svn: 246878
2015-09-04 21:35:54 +00:00
Rui Ueyama
434de7a33f Remove unused variable.
llvm-svn: 246874
2015-09-04 21:05:30 +00:00
Rui Ueyama
2dcc23580e COFF: Use section content checksum for ICF.
Previously, we calculated our own hash values for section contents.
Of coruse that's slow because we had to access all bytes in sections.
Fortunately, COFF objects usually contain hash values for COMDAT
sections. We can use that to speed up Identical COMDAT Folding.

llvm-svn: 246869
2015-09-04 20:45:50 +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
Rui Ueyama
406c7d9540 COFF: Update windows_support.html.
llvm-svn: 246786
2015-09-03 17:01:18 +00:00
Rui Ueyama
31e66e32b4 COFF: Ignore /GUARDSYM option.
The option is added in MSVC 2015, and there's no documentation about
what the option is. This patch is to ignore the option for now, so that
at least LLD is usable with MSVC 2015.

llvm-svn: 246780
2015-09-03 16:20:47 +00:00
Rui Ueyama
6295b27184 COFF: /delayload:<DLLNAME> is case-insensitive.
llvm-svn: 246770
2015-09-03 14:49:47 +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
fb497d79f6 Remove an allocator which was used for just one allocation.
llvm-svn: 246662
2015-09-02 16:07:11 +00:00
Rui Ueyama
6f5ec97dc0 COFF: Attempt to fix a flaky test.
I don't understand why the previous code is pretty flaky and
the new code is at least less flaky, but the original test
occasionally failed on the second run of lib.exe.

My guess was that lib.exe was failing because the output of
the echo command executed immediately before lib.exe was not
flushed to a file, but as far as I can say, the file
descriptor is properly closed in TestRunner.py, so this's
probably not correct. Other theory is that, on Windows, file
output is not guaranteed to be visible to other processes even
if a process flushes file descriptors, but I'd think that's
unlikely. So honestly I don't know the cause yet.

llvm-svn: 246621
2015-09-02 08:10:37 +00:00
Rui Ueyama
bfbd277a1c COFF: Preserve original spelling of DLL file name.
This patch fixes a subtle incompatibility with MSVC linker.
MSVC linker preserves the original spelling of a DLL in the
import descriptor table. LLD previously converted all
characters to lowercase. Usually this difference is benign,
but if a program explicitly checks for DLL file names, the
program could fail.

llvm-svn: 246620
2015-09-02 07:27:31 +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