Commit Graph

3811 Commits

Author SHA1 Message Date
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
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
Peter Collingbourne 402fbecc1a Core: Start using llvm/Support/thread.h to work around MSVC <thread> issues.
llvm-svn: 246219
2015-08-27 21:52:36 +00:00
Tom Stellard 8251f978d3 ELF/AMDGPU: Add more misssing: using namespace lld;
Hopefully, this will resolve the remaining windows bot errors.

llvm-svn: 246181
2015-08-27 18:43:12 +00:00
Tom Stellard 39b3d71177 ELF/AMDGPU: Add missing: using namespace lld; to try to fix windows bot
llvm-svn: 246179
2015-08-27 18:27:52 +00:00
Tom Stellard fbbbc01caa ELF/AMDGPU: Remove another unused private member variable
llvm-svn: 246164
2015-08-27 17:11:10 +00:00
Tom Stellard 36c6f6b874 ELF/AMDGPU: Remove unused private member variable
This should fix the one of the failing bots.

llvm-svn: 246160
2015-08-27 16:52:58 +00:00
Tom Stellard ff8dfbd965 ELF/AMDGPU: Attempt to fix windows bots
Broken by r246155.

llvm-svn: 246159
2015-08-27 16:48:46 +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
Martell Malone 2a9098e529 lld-link: revert r246139 from OUTPUT to POST_BUILD
llvm-svn: 246140
2015-08-27 05:37:08 +00:00
Martell Malone 895f9a7422 lld-link: Unify symlink code with llvm-lib
llvm-svn: 246139
2015-08-27 05:18:36 +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
Rui Ueyama c0c74e1b8a COFF: Print out module-definition files if /verbose is given.
This is useful for testing.

llvm-svn: 246032
2015-08-26 12:37:54 +00:00
Rui Ueyama 2caf407107 COFF: Show real command line options if /verbose is given.
llvm-svn: 246023
2015-08-26 07:12:08 +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
Peter Collingbourne 0bb50d92b6 COFF: Update for LTO API change.
llvm-svn: 245892
2015-08-24 22:22:58 +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 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
Rui Ueyama 6a883b086e COFF: Improve debug helper function.
SectionChunk::getDebugName crashed if the symbol was a nullptr.

llvm-svn: 245677
2015-08-21 07:01:10 +00:00