Commit Graph

3841 Commits

Author SHA1 Message Date
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
Ed Maste 6194363b31 Exclude COFF/export-exe.test on non-Windows
llvm-svn: 246559
2015-09-01 17:26:33 +00:00
Davide Italiano 491d3bfd43 [COFF] Remove dead private field. Also fixes build with -Werror.
llvm-svn: 246553
2015-09-01 16:05:53 +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
Rui Ueyama 6b0af3c832 Fix -Wcovered-switch-default warnings.
llvm-svn: 246419
2015-08-31 06:46:00 +00:00
Rui Ueyama 692f8683d7 ELF: Fix "not all control paths return a value" warning.
llvm-svn: 246417
2015-08-31 06:32:25 +00:00
Rui Ueyama a41a367056 Attempt to unbreak buildbots.
It is currently failing with "'__uncaught_exception': identifier not found"
error. I guess it is due to r246219 because after that change, eh.h is
included only when threading is enabled.

llvm-svn: 246416
2015-08-31 06:19:01 +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
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 9638d7d162 [Mips] Support two more MIPS linking emulation options elf32btsmipn32/elf32ltsmipn32
llvm-svn: 246336
2015-08-28 21:39:13 +00:00
Simon Atanasyan f12120cfe9 [Mips] Make "emulation" option less dependent on the "-target" option.
Now it is possible to have mips-linux-gnu-ld executable and link MIPS 64-bit
little-endian binaries providing -melf64ltsmip command line argument.

llvm-svn: 246335
2015-08-28 21:39:06 +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
Rui Ueyama 40f4d86f5f COFF: Create short import files instead of using lib.exe.
lib.exe has a feature to create import library files (which contain
short import files) from module-definition files. Previously, we were
using that feature, but it turned out that the feature is not complete
for us.

There seems no way to specify "Import Types" in module-definition file.
lib.exe always adds "_" to given symbols and specify IMPORT_NAME_UNDECORATE.
We need more fine-grainded control on that value.

This patch teaches LLD to create short import files itself.
We are still using lib.exe, but the use of the tool is limited to create
empty import library files. We then create short import files and add them
to the empty files as new members.

This patch does not intend to change the functionality. LLD produces
the same import libraries as before. I'll make another change to create
different import libraries in a follow-up patch.

llvm-svn: 246292
2015-08-28 10:52: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