Commit Graph

1324 Commits

Author SHA1 Message Date
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 1b348a68e5 [elf2] Add basic archive file support.
llvm-svn: 246886
2015-09-04 22:28:10 +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
Rui Ueyama 6295b27184 COFF: /delayload:<DLLNAME> is case-insensitive.
llvm-svn: 246770
2015-09-03 14:49:47 +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 06c3a6d676 Start recording st_other (i.e. visibility).
llvm-svn: 246577
2015-09-01 19:42:38 +00:00
Ed Maste 6194363b31 Exclude COFF/export-exe.test on non-Windows
llvm-svn: 246559
2015-09-01 17:26:33 +00:00
Rui Ueyama 100ffacf2c COFF: .exe files should be able to export functions.
In r246424, I made a change that disables non-DLL to export
symbols. It turned out that the change was not correct. Both
DLLs and executables are able to export symbols (although the
latter is relatively rare). This change restores the feature.

llvm-svn: 246537
2015-09-01 09:15:58 +00:00
Rui Ueyama dfff2542b8 COFF: Make import libraries compatible with MSVC link.
I have totally no idea why, but MSVC linker is sensitive about
file names of archive members. If we do not make import library
file names to the same as the DLL name, MSVC link *crashes*
when it is processing the library file. This patch is to set
the same name.

llvm-svn: 246535
2015-09-01 08:08:57 +00:00
Rui Ueyama 84f9218417 COFF: Set "Data" bit for data symbols in the import descriptor.
llvm-svn: 246533
2015-09-01 06:46:10 +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
Rui Ueyama f10a32014d COFF: Improve dllexported name mangling compatibility.
The rules for dllexported symbols are overly complicated due to
x86 name decoration, fuzzy symbol resolution, and the fact that
one symbol can be resolved by so many different names. The rules
are probably intended to be "intuitive", so that users don't have
to understand the name mangling schemes, but it seems that it can
lead to unintended symbol exports.

To make it clear what I'm trying to do with this patch, let me
write how the export rules are subtle and complicated.

 - x86 name decoration: If machine type is i386 and export name
   is given by a command line option, like /export:foo, the
   real symbol name the linker has to search for is _foo because
   all symbols are decorated with "_" prefixes. This doesn't happen
   on non-x86 machines. This automatic name decoration happens only
   when the name is not C++ mangled.

   However, the symbol name exported from DLLs are ones without "_"
   on all platforms.

   Moreover, if the option is given via .drectve section, no
   symbol decoration is done (the reason being that the .drectve
   section is created by a compiler and the compiler should always
   know the exact name of the symbol, I guess).

 - Fuzzy symbol resolution: In addition to x86 name decoration,
   the linker has to look for cdecl or C++ mangled symbols
   for a given /export. For example, it searches for not only
   _foo but also _foo@<number> or ??foo@... for /export:foo.

Previous implementation didn't get it right. I'm trying to make
it as compatible with MSVC linker as possible with this patch
however the rules are. The new code looks a bit messy to me, but
I don't think it can be simpler due to the ad-hoc-ness of the rules.

llvm-svn: 246424
2015-08-31 08:43:21 +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
Peter Collingbourne df5783b7a5 COFF: Implement parallel LTO code generation.
This is exposed via a new flag /opt:lldltojobs=N, where N is the number of
code generation threads.

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

llvm-svn: 246342
2015-08-28 22:16:09 +00:00
Simon Atanasyan e235d45026 [Mips] Support grouping of multiple consecutive relocations in case of N32 and 64-bit MIPS ABIs
llvm-svn: 246337
2015-08-28 21:39:21 +00:00
Simon Atanasyan 6d39140b6e [Mips] Initial support of the MIPS N32 ABI
llvm-svn: 246334
2015-08-28 21:39:00 +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 c20fee5dc5 Add a -target to this test.
Without it it fails on 32 bit windows.

llvm-svn: 246297
2015-08-28 13:15:05 +00:00
Rafael Espindola ad5ca2245e Remove irrelevant parts of the test.
llvm-svn: 246265
2015-08-28 02:53:05 +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
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
Tom Stellard 15d1fa1bcc ELF: Add AMDGPU ReaderWriter
This is a basic implementation that allows lld to emit binaries
consumable by the HSA runtime.

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

llvm-svn: 246155
2015-08-27 15:55:44 +00:00
Davide Italiano 21e1cd79d0 [LinkerScript] Enforce uniqueness of output object files...
... in order to avoid conflicts when tests are run in parallel.
This is an attempt to fix PR24591.

llvm-svn: 246153
2015-08-27 15:18:43 +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
Rui Ueyama d020c65d24 COFF: Attempt to unbreak buildbots.
This is an attempt to unbreak http://reviews.llvm.org/P122.

llvm-svn: 246000
2015-08-26 02:52:05 +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
Rui Ueyama 473aa4088d COFF: Add a test for ICF and circular references.
ICF is a feature to merge sections not by name (which is the regular
COMDAT merging) but by contents. If two or more sections have the
identical contents and relocations, ICF merges them to save space.
Accessors or templated functions tend to have the same contents, and
ICF can hold them.

If we consider sections as vertices and relocations as edges, the
problem is to find as many isomorphic graphs as possile from input
graphs. MSVC linker is smart enough to identify isomorphic graphs
even if they contain circles (GNU gold cannot handle circles
according to http://research.google.com/pubs/pub36912.html, so this
is impressive).

Circular references are not uncommon in COFF object files.
One example is .pdata. .pdata sections contain exception handler info
for functions, so they naturally have relocations for the functions.
The functions in turn have references to the .pdata sections so that
the functions and their .pdata are linked together. As a result, they
form circles.

This is a test case for circular graphs. LLD is not able to handle
this test case yet. I'll add code soon.

llvm-svn: 245827
2015-08-24 08:11:53 +00:00
Rui Ueyama 28103266c6 COFF: Update a test for ICF.
The old test files were just compiler outputs, so it was hard to
debug if something goes wrong. The new test file is carefully
hand-crafted to trigger ICF to avoid that.

llvm-svn: 245826
2015-08-24 07:52:08 +00:00
Davide Italiano b3c7fb7f24 [LinkerScript] Fix a crash when matching wildcards.
Submitted by:	  zan jyu via llvm-dev

llvm-svn: 245792
2015-08-22 20:36:19 +00:00
Simon Atanasyan 814b705984 [Mips] Use 'or' for move instead of [d]addu in PLT entries
Patch by Simon Dardis.

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

llvm-svn: 245491
2015-08-19 20:20:10 +00:00
Rui Ueyama 7171c82194 COFF: Allow forward reference for weak externals
Previously, weak external symbols could reference only symbols that
appeared before them. Although that covers almost all use cases
of weak externals, there are object files out there which contains
weak externals that have forward references.

This patch supports such weak externals.

llvm-svn: 245258
2015-08-17 23:35:43 +00:00
Rui Ueyama 27716bb9d9 COFF: Fix a broken test.
This test couldn't be run more than once because lib.exe does not work
if the files already exist.

llvm-svn: 245214
2015-08-17 11:06:21 +00:00
Rui Ueyama d157088adb COFF: Fix the order of the DLL import entry.
There are some DLLs whose initializers depends on other DLLs'
initializers. The initialization order matters for them.

MSVC linker uses the order of the libraries from the command line.
LLD used ASCII-betical order. So they were incompatible.
This patch makes LLD compatible with MSVC.

llvm-svn: 245201
2015-08-17 08:30:31 +00:00