Commit Graph

3854 Commits

Author SHA1 Message Date
Peter Smith f0c70f8d34 [ELF] Pre-create ThunkSections at Target specific intervals
When an OutputSection is larger than the branch range for a Target we
need to place thunks such that they are always in range of their caller,
and sufficiently spaced to maximise the number of callers that can use
the thunk. We use the simple heuristic of placing the
ThunkSection at intervals corresponding to a target specific branch range.
If the OutputSection is small we put the thunks at the end of the executable
sections.

Differential Revision: https://reviews.llvm.org/D34689

llvm-svn: 316751
2017-10-27 08:58:28 +00:00
Martin Storsjo 27af6b0082 [MinGW] Support --out-implib=name in addition to "--out-implib name"
Differential Revision: https://reviews.llvm.org/D39329

llvm-svn: 316692
2017-10-26 20:11:58 +00:00
Martin Storsjo c0e7e76fd7 [COFF] Add a test for def files with spaces between @ and ordinal
Differential Revision: https://reviews.llvm.org/D39328

llvm-svn: 316691
2017-10-26 20:11:54 +00:00
George Rimar d605f414db [ELF] - Dedupliсate FDEs when sections are ICFed.
When LLD do ICF for 2 identical sections it leaves 2 duplicate entries in .eh_frame
pointing to the same address. After that it fixes .eh_frame_header's header,
so that it says it contains single FDE, though section itself contains 2 
(it contains garbage data at tail).

As a result excessive entries in .eh_frame and excessive dummy data in .eh_frame_header
emited to output. Patch fixes that. This is PR34518.

Differential revision: https://reviews.llvm.org/D38998

llvm-svn: 316648
2017-10-26 09:13:19 +00:00
Igor Kudrin 85e68a6601 [lit] Respect LLVM_LIT_TOOLS_DIR when looking for 'tar' on Windows.
Changes in D38977 expect 'tar' to be found in one of PATH directories.
On Windows, one might opt to use LLVM_LIT_TOOLS_DIR rather than add MSYS
tools directory to the PATH. In that case, tests for lld failed on run.

Differential Revision: https://reviews.llvm.org/D39278

llvm-svn: 316635
2017-10-26 02:31:36 +00:00
Rui Ueyama 5ace35cba5 Fix SizeOfImage in the PE header.
IIUC, SizeOfImage is the distance from the end of the last section to
the image base, rounded up to the page size. So the previous code is
wrong.

Should fix https://bugs.llvm.org/show_bug.cgi?id=34949

(It is nice to know that lld is already being used to create Putty
distribution binaries.)

llvm-svn: 316626
2017-10-25 23:00:40 +00:00
George Rimar 9814d15136 [ELF] - Implement --orphan-handling option.
It is PR34946.

Spec (http://man7.org/linux/man-pages/man1/ld.1.html) tells about
--orphan-handling=MODE, option where MODE can be one of four:
"place", "discard", "warn", "error".
Currently we already report orphans when -verbose given,
what becomes excessive with option implemented.

Patch stops reporting orphans when -versbose is given,
and support "place", "warn" and "error" modes.
It is not yet clear that "discard" mode is useful so it is not supported.

Differential revision: https://reviews.llvm.org/D39000

llvm-svn: 316583
2017-10-25 15:20:30 +00:00
George Rimar f22ec9ddf6 [ELF] - Linkerscript: fix issue with SUBALIGN.
This is PR34886.

SUBALIGN command currently triggers failture if result expression
is zero. Patch fixes the issue, treating zero as 1, what is consistent with
other places and ELF spec it seems.

Patch also adds "is power of 2" check for this and other expressions
returning alignment.

Differential revision: https://reviews.llvm.org/D38846

llvm-svn: 316580
2017-10-25 14:50:51 +00:00
Peter Collingbourne f012360770 Try to fix test on windows.
llvm-svn: 316549
2017-10-25 05:33:28 +00:00
Peter Collingbourne acc3baaea1 COFF: Don't add /manifest* flags to the response file.
If /manifest:embed is enabled we're already creating a resource file
out of these flags and adding it to the linkrepro, and it doesn't
seem worth being able to repro side-by-side manifests.

Includes a test that covers this commit as well as r315948.

Differential Revision: https://reviews.llvm.org/D38975

llvm-svn: 316547
2017-10-25 05:00:54 +00:00
Shoaib Meenai b57e640f3a [COFF] Add support for /WX
link.exe supports this option to convert warnings into errors, and it's
useful to support in LLD as well.

Differential Revision: https://reviews.llvm.org/D39148

llvm-svn: 316502
2017-10-24 21:19:22 +00:00
Konstantin Zhuravlyov b71d1b8a54 LLD/ELF/AMDGPU: Process AMDGPU-specific e_flags
Differential Revision: https://reviews.llvm.org/D39140

llvm-svn: 316483
2017-10-24 19:05:32 +00:00
Reid Kleckner 8aa32ffbad [codeview] Fix handling of S_HEAPALLOCSITE
The type index is from the TPI stream, not the IPI stream. Fix the
dumper, fix type index discovery, and add a test in LLD.

Also improve the log message we emit when we fail to rewrite type
indices in LLD. That's how I found this bug.

llvm-svn: 316461
2017-10-24 17:02:40 +00:00
George Rimar f4ca4a6fa1 [ELF] - Do not collect SHT_REL[A] sections unconditionally when --gc-sections and --emit-relocs used together.
This is "Bug 34836 - --gc-sections remove relocations from --emit-relocs",

When --emit-relocs is used, LLD currently always drops SHT_REL[A] sections from
output if --gc-sections is present. Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D38724

llvm-svn: 316418
2017-10-24 08:26:32 +00:00
Reid Kleckner a50619bf84 [PDB] Add test for S_THUNK32 records
I locally reverted r316385 and confirmed that this test fails without
it.

Really fixes the cause of PR35014.

llvm-svn: 316392
2017-10-23 23:15:40 +00:00
Rafael Espindola 615a064e33 Document a change of behavior in r315552.
We used to reject this, but we now accept. The output seems
reasonable, so this is probably an OK extension over bfd/gold.

llvm-svn: 316376
2017-10-23 21:00:15 +00:00
Rui Ueyama a4cf97bc9c Add the --version option.
Differential Revision: https://reviews.llvm.org/D38972

llvm-svn: 316329
2017-10-23 14:57:53 +00:00
Martin Storsjo ddb094ad36 [COFF] Fix exporting of functions starting with underscores, etc
This fixes exporting functions in the following cases:
- functions starting with an underscore in def files
- functions starting with an underscore, via dllexport attributes, for mingw
- fastcall and vectorcall functions when declared undecorated in def files
- vectorcall functions when declared decorated in def files
- stdcall functions when declared decorated in def files for mingw

This still exports the stdcall functions with the wrong name
in the normal msvc/link.exe mode, if declared with decoration in
the def file though (this is not a regression though). Exporting
functions via def files including decoration is not something I
believe is routinely done though, but is tested to try to match
link.exe's behaviour as far as easily possible.

Differential Revision: https://reviews.llvm.org/D39170

llvm-svn: 316317
2017-10-23 09:08:24 +00:00
Petr Hosek 2fd533db9f [ELF] When placing orphans, handle case when last section is dead
r315292 introduced a change that's supposed to consistently ignore
"dead" output sections when placing orphans. Unfortunately, that
change doesn't handle the special case when the orphan section is
second to last section and the last section is dead (e.g. because
it's being discarded) introducing a regression in some cases.

This change handles this case by using the same predicate when
checking the last section.

Differential Revision: https://reviews.llvm.org/D39172

llvm-svn: 316307
2017-10-23 00:51:08 +00:00
Rui Ueyama 8faafa4fb1 Add R_PPC_ADDR16_HI relocation support
The support of R_PPC_ADDR16_HI improves ld compatibility and makes
things on par with RuntimeDyldELF that already implements this
relocation.

Patch by vit9696.

llvm-svn: 316306
2017-10-22 23:33:49 +00:00
Peter Collingbourne 75257bc2ec COFF: Add type server pdb files to linkrepro tar file.
Differential Revision: https://reviews.llvm.org/D38977

llvm-svn: 316233
2017-10-20 19:48:26 +00:00
Martin Storsjo b40ccc1c58 [COFF] Exclude certain static libraries and object files when exporting all symbols
This more or less matches what GNU ld does.

Differential Revision: https://reviews.llvm.org/D38937

llvm-svn: 316148
2017-10-19 06:56:04 +00:00
Rafael Espindola 06ea0ce1c9 Handle shared symbols in the gnu hash construction.
They are special in that they they need to be in the hash table iff we
are linking an executable that preempts them.

llvm-svn: 316065
2017-10-18 06:49:59 +00:00
NAKAMURA Takumi 8b6b9cbb33 Prune trailing linefeed.
llvm-svn: 316060
2017-10-18 04:45:09 +00:00
Rafael Espindola 3038c6beb5 Revert "Bring back the rest of r315721."
This reverts commit r316051.

It fails on a bot.

llvm-svn: 316058
2017-10-18 03:06:45 +00:00
Rafael Espindola 07412df152 Bring back the rest of r315721.
The original patch was reported to break a libcxx bot. Unfortunately I
could not reproduce the issue and the bot log is not available anymore.

This patch changes the handling of shared symbols. I will watch the
bot and see it breaks.

Original message:
--------------------------------------------------------------
Handle shared and lazy symbol in the gnu hash construction.

We were not considering those symbols undefined and they could end up
in the end of the dynamic symbol table.
--------------------------------------------------------------

llvm-svn: 316051
2017-10-18 01:10:05 +00:00
Rafael Espindola 14381cf5a6 Bring back part of r315721.
The original patch was reported to break a libcxx bot. Unfortunately
I could not reproduce the issue and the bot log is not available anymore.

This patch changes the handling of just lazy symbols. I will watch the
bot and see it breaks.

Original message:
--------------------------------------------------------------
Handle shared and lazy symbol in the gnu hash construction.

We were not considering those symbols undefined and they could end up
in the end of the dynamic symbol table.
--------------------------------------------------------------

llvm-svn: 316004
2017-10-17 15:29:11 +00:00
Peter Collingbourne 9362ac60bc COFF: Add resource files to linkrepro instead of the cvtres object file.
Now that we have our own implementation of cvtres, we can add resource
files directly to the linkrepro.

Differential Revision: https://reviews.llvm.org/D38974

llvm-svn: 315954
2017-10-16 23:15:04 +00:00
Tony Tye 394e1dde6e Add base relative relocation record that can be used for the following case (OpenCL example):
static __global int Var = 0; 
__global int* Ptr[] = {&Var};
...

In this case Var is a non premptable symbol and so its address can be used as the value of Ptr, with a base relative relocation that will add the delta between the ELF address and the actual load address. Such relocations do not require a symbol.

This also fixes LLD which was incorrectly generating a PCREL64 for this case.

Differential Revision: https://reviews.llvm.org/D38910

llvm-svn: 315936
2017-10-16 20:46:53 +00:00
Martin Storsjo cbf43f0b7b [COFF] Fix a typo in a comment in a test. NFC.
These chars are accidentally included vim commands.

llvm-svn: 315880
2017-10-15 21:09:50 +00:00
NAKAMURA Takumi 09c234f857 Revert rL315721, "Handle shared and lazy symbol in the gnu hash construction."
It broke check-libcxx with stage1-clang and stage1-lld.

llvm-svn: 315803
2017-10-14 12:21:49 +00:00
Rafael Espindola ea413cbacf Give shared symbols priority over lazy ones.
This matches the behavior of gold and bfd. It also matches lld's own
behavior when the shared symbol is seen first

llvm-svn: 315766
2017-10-13 21:52:33 +00:00
Rafael Espindola a7e3132d03 Handle shared symbols in --gc-sections.
We don't want to gc a section if it is used via __start_*, but we were
doing that if the same symbol was visible in a shared library.

llvm-svn: 315727
2017-10-13 18:32:16 +00:00
Rafael Espindola 8bf95e4678 Handle shared and lazy symbol in the gnu hash construction.
We were not considering those symbols undefined and they could end up
in the end of the dynamic symbol table.

llvm-svn: 315721
2017-10-13 18:07:11 +00:00
Rafael Espindola a2516bef9f Relax test.
These value are irrelevant for the test.

llvm-svn: 315720
2017-10-13 18:03:11 +00:00
Rafael Espindola af6c9edc4b Correctly handle shared and lazy symbols.
I will try to make this API a bit less error prone, but for now just
get another test passing.

llvm-svn: 315645
2017-10-13 00:06:38 +00:00
Zachary Turner ad5997e87a [lit] Raise the logic for enabling clang & lld substitutions to llvm.
This paves the way for other projects which might /use/ clang or
lld but not necessarily need to the full set of functionality
available to clang and lld tests to be able to have a basic set
of substitutions that allow a project to run the clang or lld
executables.

llvm-svn: 315627
2017-10-12 21:56:05 +00:00
Rafael Espindola 62222d04cd Update comment.
The number 131076 didn't show up anywhere in the test.

llvm-svn: 315588
2017-10-12 15:54:14 +00:00
Rafael Espindola d7d752ad33 Relax test.
The address of the .got section is not relevant for the test.

llvm-svn: 315585
2017-10-12 15:12:55 +00:00
Rafael Espindola 49419bb303 Use 0 as sh_link when we don't have a dynamic symbol table.
It doesn't make sense to link from an alloc section to a non alloc
one as we were doing.

This matches the behavior of both gold and bfd.

llvm-svn: 315584
2017-10-12 15:05:04 +00:00
George Rimar 81eca18df3 [ELF] - Linkerscript: Add `~` as separate math token.
Previously we did not support following:
foo = ~0xFF;
and had to add space before numeric value:
foo = ~ 0xFF

That was constistent with ld.bfd < 2.30, which shows:
script.txt:3: undefined symbol `~2' referenced in expression,
but inconsistent with gold.

It was fixed for ld.bfd 2.30 as well:
https://sourceware.org/bugzilla/show_bug.cgi?id=22267

Differential revision: https://reviews.llvm.org/D36508

llvm-svn: 315569
2017-10-12 08:40:12 +00:00
Martin Storsjo a84a47741a [MinGW] Hook up the --export-all-symbols and --output-def options
Differential Revision: https://reviews.llvm.org/D38761

llvm-svn: 315563
2017-10-12 05:37:18 +00:00
Martin Storsjo 7f71acdcd7 [COFF] Add support for automatically exporting all symbols
GNU ld automatically exports all symbols if no symbols have
been chosen to export via either def files or dllexport attributes.
The same behaviour can also be enabled via the GNU ld option
--export-all-symbols, in case some symbols are marked for export
via a def file or dllexport attribute.

The list of excluded symbols is from GNU ld, minus the
cygwin specific symbols.

Also add support for outputting the actual list of exported
symbols in a def file, as in the GNU ld option --output-def.

These options in GNU ld are documented in
https://sourceware.org/binutils/docs/ld/WIN32.html.

This currently exports all symbols from object files pulled in
from libmingw32 and libmingwex and other static libraries
that are linked in.

Differential Revision: https://reviews.llvm.org/D38760

llvm-svn: 315562
2017-10-12 05:37:13 +00:00
Martin Storsjo ea460a2d0c [COFF] Implement support for IMAGE_REL_ARM64_ADDR32NB
This is implemented in the same way as the other ADDR32NB relocations
for ARM and X64.

Differential Revision: https://reviews.llvm.org/D38815

llvm-svn: 315561
2017-10-12 05:37:06 +00:00
Rui Ueyama be85529d2b Remove one parameter from Target::getRelExpr.
A section was passed to getRelExpr just to create an error message.
But if there's an invalid relocation, we would eventually report it
in relocateOne. So we don't have to pass a section to getRelExpr.

llvm-svn: 315552
2017-10-12 03:14:06 +00:00
Davide Italiano db710f28e6 [ELF] Try to not emit weird diagnostics on undefined symbols.
Fixes PR34872.

Differential Revision:  https://reviews.llvm.org/D38712

llvm-svn: 315487
2017-10-11 18:37:24 +00:00
George Rimar 26fa916deb [ELF] - Do not set output section flags except SHF_{ALLOC,WRITE,EXECINSTR}.
This is PR34546.

Currently LLD creates output sections even if it has no input sections,
but its command contains an assignment.
Committed code just assigns the same flag that was used in previous
live section.
That does not work sometimes. For example if we have following script:

.ARM.exidx : { *(.ARM.exidx*) }
.foo : { _foo = 0; } }
Then first section has SHF_LINK_ORDER flag. But section foo should not.
That was a reason of crash in OutputSection::finalize(). LLD tried to calculate
Link value, calling front() on empty input sections list.
We should only keep access flags and omit all others when creating such sections.

Patch fixes the crash observed.

Differential revision: https://reviews.llvm.org/D37736

llvm-svn: 315441
2017-10-11 08:13:40 +00:00
Peter Collingbourne 8a40a7b15c COFF: When generating code for LTO, use static reloc model on 32-bit x86.
Fixes PR34306.

This is because it usually results in more compact code, and because
there are also known code generation bugs when using the PIC model
(see bug).

Based on a patch by Carlo Kok.

Differential Revision: https://reviews.llvm.org/D38769

llvm-svn: 315400
2017-10-11 00:46:58 +00:00
Rafael Espindola 97c57b9e7b Don't create a dummy __tls_get_addr.
We just don't need one with the current setup.

We only error on undefined references that are used by some
relocation.

If we managed to relax all uses of __tls_get_addr, no relocation uses
it and we don't produce an error.

This is less code and fixes the case were we fail to relax. Before we
would produce a broken output, but now we produce an error.

llvm-svn: 315334
2017-10-10 17:27:34 +00:00
James Henderson b5ca92ef73 [ELF] Set Dot initially to --image-base value when using linker scripts
When parsing linker scripts, LLD previously started with a '.' value of 0,
regardless of the internal default image base for the target, and regardless of
switches such as --image-base. It seems reasonable to use a different image base
value when using linker scripts and --image-base is specified, since otherwise the
switch has no effect. This change does this, as well as removing unnecessary
initialisation of Dot where it is not used.

The default image base should not be used when processing linker
scripts, because this will change the behaviour for existing linker script users,
and potentially result in invalid output being produced, as a subsequent assignment
to Dot could move the location counter backwards. Instead, we maintain the existing
behaviour of starting from 0 if --image-base is not specified.

Reviewers: ruiu

Differential Revision: https://reviews.llvm.org/D38360

llvm-svn: 315293
2017-10-10 10:09:35 +00:00
Andrew Ng 4d54a4b4f7 [LLD] Fix findOrphanPos to consistently ignore "dead" OutputSection's
When findOrphanPos does the reverse search to find the OutputSection
preceding the orphan's insertion point, look for a live OutputSection
and ignore "dead" OutputSection's. This matches the behaviour of the
forward search performed earlier in this function.

Added test which without the above fix fails as a result of an orphan
executable section being incorrectly placed in a non-executable segment.

Differential Review: https://reviews.llvm.org/D38690

llvm-svn: 315292
2017-10-10 10:05:52 +00:00
George Rimar 7e9c5610c9 [ELF] - Improve "has non-ABS reloc" error.
It did not contain information about relocation type and symbol.

Differential revision: https://reviews.llvm.org/D38623

llvm-svn: 315280
2017-10-10 07:55:07 +00:00
Martin Storsjo 67dd3415c0 [COFF] Don't error out on relocations to discarded sections in .eh_frame
This allows linking code with dwarf exception handling.

Differential Revision: https://reviews.llvm.org/D38681

llvm-svn: 315273
2017-10-10 06:05:29 +00:00
Rui Ueyama cc6738a439 Use error() instead of warn() to report undefined symbols.
I believe the reason why we used warn() instead of error() to report
undefined symbols is because the older implementation of error() exitted
immediately. Here, we want to find as many undefined symbols as we can,
so I chose to use warn() instead of error().

Now error() does not exit immediately, so it doesn't make sense to keep
them as warnings.

Differential Revision: https://reviews.llvm.org/D38652

llvm-svn: 315131
2017-10-06 23:43:54 +00:00
Peter Collingbourne d6924d7474 Reland r315114, "ELF: Export preempted symbols even if there is a dynamic list." which was reverted in r315116.
I hadn't synced past the change that changed the default hash style
to --hash-style=both, so my test had the symbols in the wrong order.

llvm-svn: 315119
2017-10-06 22:09:03 +00:00
Peter Collingbourne accab5908d Revert r315114, "ELF: Export preempted symbols even if there is a dynamic list."
For some reason the symbols get emitted in the wrong order on one of the
buildbots: http://bb9.pgr.jp/#builders/15/builds/180

llvm-svn: 315116
2017-10-06 21:48:39 +00:00
Peter Collingbourne 5a8928c605 ELF: Export preempted symbols even if there is a dynamic list.
Dynamic lists in an executable are additive, not restrictive, so we
must continue to export preempted symbols even with a dynamic list.

This fixes sanitizer interception of libc symbols (and should also fix
symbol preemption by users of sanitizers).

Differential Revision: https://reviews.llvm.org/D38647

llvm-svn: 315114
2017-10-06 21:33:59 +00:00
Rafael Espindola 469350810a Refine our --wrap implementation.
Before this patch we would copy foo into real_foo and wrap_foo into
foo. The net result is that __wrap_foo shows up twice in the symbol
table.

With this patch we:

* save a copy of __real_foo before copying foo.
* drop one of the __wrap_foo from the symbol table.
* if __real_foo was not undefined, add a *new* symbol with that content to
  the symbol table.

The net result is that

Anything using foo now uses __wrap_foo
Anything using __real_foo now uses foo.
Anything using __wrap_foo still does.

And the symbol table has foo, __wrap_foo and __real_foo (if defined).

Which I think is the desired behavior.

llvm-svn: 315097
2017-10-06 20:09:34 +00:00
Zachary Turner 96b04b68ed [lit] Improve tool substitution in lit.
This addresses two sources of inconsistency in test configuration
files.

1. Substitution boundaries.  Previously you would specify a
   substitution, such as 'lli', and then additionally a set
   of characters that should fail to match before and after
   the tool.  This was used, for example, so that matches that
   are parts of full paths would not be replaced.  But not all
   tools did this, and those that did would often re-invent
   the set of characters themselves, leading to inconsistency.
   Now, every tool substitution defaults to using a sane set
   of reasonable defaults and you have to explicitly opt out
   of it.  This actually fixed a few latent bugs that were
   never being surfaced, but only on accident.

2. There was no standard way for the system to decide how to
   locate a tool.  Sometimes you have an explicit path, sometimes
   we would search for it and build up a path ourselves, and
   sometimes we would build up a full command line.  Furthermore,
   there was no standardized way to handle missing tools.  Do we
   warn, fail, ignore, etc?  All of this is now encapsulated in
   the ToolSubst class.  You either specify an exact command to
   run, or an instance of FindTool('<tool-name>') and everything
   else just works.  Furthermore, you can specify an action to
   take if the tool cannot be resolved.

Differential Revision: https://reviews.llvm.org/D38565

llvm-svn: 315085
2017-10-06 17:54:46 +00:00
Zachary Turner c981448063 Run pyformat on lit code.
llvm-svn: 315084
2017-10-06 17:54:27 +00:00
Alexander Richardson f52a3b94e1 [ELF][MIPS] Check for overflow when writing R_MIPS_CALL16 and R_MIPS_TLS_GOTTPREL
Summary:
These are 16 bit relocations and not part of a HI/LO pair so we need to
check that they don't overflow.

Reviewers: atanasyan

Reviewed By: atanasyan

Subscribers: ruiu, llvm-commits, emaste, sdardis

Tags: #lld

Differential Revision: https://reviews.llvm.org/D38614

llvm-svn: 315073
2017-10-06 16:15:59 +00:00
George Rimar 8f3a6c8143 [ELF] - Do not produce broken .dynamic section with --no-rosegment
LLD produces broken .dynamic section when --no-rosegment and at least
one of following options is present:
  1) -z rodynamic is given.
  2) MIPS target.

That happens because code that writes .dynamic assumes target buffer
is zero-filled, what can be not true after LLD fills it with trap
instructions. With one of two options above, .dynamic becomes
SHF_ALLOC section, so can be affected.

Differential revision: https://reviews.llvm.org/D38580

llvm-svn: 315054
2017-10-06 10:06:13 +00:00
George Rimar 2727ce2c1f [ELF] - Do not produce broken .dynsym with --no-rosegment.
We produce broken output currently.
Code that writes .dynsym assumes output buffer is zero-filled,
though that is not always true. When --no-rosegment is given,
buffer can be filled with trap instructions. Patch fixes the issue.

It is relative with PR34705.

Differential revision: https://reviews.llvm.org/D38579

llvm-svn: 315053
2017-10-06 09:56:24 +00:00
George Rimar 148d75d8d5 [ELF] - Fix BB after r315051.
Testcase has "zlib" requirement, which is unsupported on
windows, so that it was not run locally for me.

llvm-svn: 315052
2017-10-06 09:46:04 +00:00
George Rimar d46753e421 [ELF] - Do --hash-style=both by default.
Its PR34712,

GNU linkers recently changed default values to "both" of "sysv".
Patch do the same for all targets except MIPS, where .gnu.hash
section is not yet supported.

Code suggested by Rui Ueyama.

Differential revision: https://reviews.llvm.org/D38407

llvm-svn: 315051
2017-10-06 09:37:44 +00:00
Alexander Richardson 6651820a72 [ELF] Add missing REQUIRES: mips to the test added in r315035
llvm-svn: 315038
2017-10-05 23:48:29 +00:00
Alexander Richardson b9aa9a5500 [ELF] Don't crash when parsing a file with out-of-bounds version references
Summary:
We were crashing when linking telnetd in FreeBSD because lld was emitting
corrupted output files for --norosegment. In this file the version index of some symbols
was set to 9 but lld only found 8 version definitions.

I am not sure how to create a minimal .so file that also exposes this behaviour so I just added the one that initially caused the error to Inputs/

This partially addresses https://bugs.llvm.org/show_bug.cgi?id=34705

Reviewers: ruiu, rafael, pcc, grimar

Reviewed By: ruiu

Subscribers: emaste, krytarowski

Tags: #lld

Differential Revision: https://reviews.llvm.org/D38397

llvm-svn: 315036
2017-10-05 23:28:34 +00:00
Alexander Richardson 57f089775b [ELF] Don't crash when parsing a file with external version definition references
Summary:
We were crashing when linking telnetd in FreeBSD because lld was emitting
corrupted output files for --norosegment. In this file the version index of some symbols
was set to 9 but lld only found 8 version definitions.

I am not sure how to create a minimal .so file that also exposes this behaviour so I just added the one that initially caused the error to Inputs/

This partially addresses https://bugs.llvm.org/show_bug.cgi?id=34705

Reviewers: ruiu, rafael, pcc, grimar

Reviewed By: ruiu

Subscribers: emaste, krytarowski

Tags: #lld

Differential Revision: https://reviews.llvm.org/D38397

llvm-svn: 315035
2017-10-05 23:28:29 +00:00
Rafael Espindola c29b24d524 Refactor duplicated code.
Since VisibleToRegularObj is weaker than LinkerRedefined, this should
have no functionality change.

llvm-svn: 314954
2017-10-05 00:35:47 +00:00
George Rimar 11632a9cfb [ELF] - Get rid of precompiled input objects from testcases.
We have verneed1.so, verneed2.so files and verneed.so.sh script
to produce them. They were committed long time ago when LLD
was not yet able to produce some sections for versioning
(".gnu.version_r" I think).

There is no point to have them as binaries anymore. Patch
creates asm inputs instead based on verneed.so.sh content.

Differential revision: https://reviews.llvm.org/D38505

llvm-svn: 314889
2017-10-04 09:46:53 +00:00
Shoaib Meenai e631c566e0 [ELF] Fix buildbots
Mark a test as requiring zlib.

llvm-svn: 314868
2017-10-04 00:38:14 +00:00
Shoaib Meenai 50d7b36f5e [ELF] Decompress debug info sections early
When reporting a symbol conflict, LLD parses the debug info to report
source location information. Sections have not been decompressed at this
point, so if an object file contains zlib compressed debug info, LLD
ends up passing this compressed debug info to the DWARF parser, which
causes debug info parsing failures and can trigger assertions in the
parser (as the test case demonstrates).

Decompress debug sections when constructing the LLDDwarfObj to avoid
this issue. This doesn't handle GNU-style compressed debug info sections
(.zdebug_*), which at present are simply ignored by LLDDwarfObj; those
can be done in a follow-up.

Differential Revision: https://reviews.llvm.org/D38491

llvm-svn: 314866
2017-10-04 00:19:41 +00:00
Hans Wennborg 6b1be121c0 Update test expectation after r314821
llvm-svn: 314827
2017-10-03 18:46:57 +00:00
Simon Atanasyan f8db45361e [MIPS] Generate thunks for microMIPS code
If symbol has the STO_MIPS_MICROMIPS flag and requires a thunk to perform
call PIC from non-PIC functions, we need to generate a thunk with microMIPS
code.

llvm-svn: 314797
2017-10-03 13:30:02 +00:00
Igor Kudrin fb7f8befec [ELF] Avoid promoting an undefined weak entry symbol to global.
Without this patch, lld emits "error: undefined symbol: _start"
if it encountered only weak references to that symbol.

llvm-svn: 314790
2017-10-03 12:23:46 +00:00
Igor Kudrin 66b0ad91f6 [ELF] Keep symbols specified by '-u' over LTO.
Differential Revision: https://reviews.llvm.org/D38348

llvm-svn: 314789
2017-10-03 12:17:59 +00:00
Simon Atanasyan 649e4d328f [MIPS] Fix PLT entries generation in case of linking regular and microMIPS code
Currently LLD calls the `isMicroMips` routine to determine type of PLT entries
needs to be generated: regular or microMIPS. This routine checks ELF
header flags in the `FirstObj` to retrieve type of linked object files.
So if the first file does not contain microMIPS code, LLD will generate
PLT entries with regular (non-microMIPS) code only.

Ideally, if a PLT entry is referenced by microMIPS code only this entry
should contain microMIPS code, if a PLT entry is referenced by regular
code this entry should contain regular code. In a "mixed" case the PLT
entry can be either microMIPS or regular, but each "cross-mode-call" has
additional cost.

It's rather difficult to implement this ideal solution. But we can
assume that if there is an input object file with microMIPS code, the
most part of the code is microMIPS too. So we need to deduce type of PLT
entries based on finally calculated ELF header flags and do not check
only the first input object file.

This change implements this.
  - The `getMipsEFlags` renamed to the `calcMipsEFlags`. The function
    called from the `LinkerDriver::link`. Result is stored in
    the Configuration::MipsEFlags field.
  - The `isMicroMips` and `isMipsR6` routines access the `MipsEFlags`
    field to get and check calculated ELF flags.
  - New types of PLT records created when necessary.

Differential revision: https://reviews.llvm.org/D37747

llvm-svn: 314675
2017-10-02 14:56:41 +00:00
Rui Ueyama daf5adc6c1 Update for LLVM change.
r314639 ([X86] Change register&memory TEST instructions from MRMSrcMem
to MRMDstMem) broke the test.

llvm-svn: 314645
2017-10-02 02:09:58 +00:00
Rui Ueyama 46557f94d0 Fix 32-bit buildbots.
The result of hash_value(StringRef) depends on sizeof(size_t).
That causes lld to create different mergeable table contents on
32-bit machines.

This patch is to use xxHash64 so that we get the same hash values
on 32-bit machines.

llvm-svn: 314603
2017-09-30 21:28:49 +00:00
Rui Ueyama c97a70c6f5 Parallelize string merging.
String merging is one of the most time-consuming functions in lld.
This patch parallelize it to speed it up. On my 2-socket 20-core
40-threads Xeon E5-2680 @ 2.8 GHz machine, this patch shorten the
clang debug build link time from 7.11s to 5.16s. It's a 27%
improvement and actually pretty noticeable. In this test condition,
lld is now 4x faster than gold.

Differential Revision: https://reviews.llvm.org/D38266

llvm-svn: 314588
2017-09-30 11:46:26 +00:00
Rafael Espindola 1f0fe88a1b Fix header location with PHDR.
We were not subtracting its size, causing it to overlap with section
data.

Fixes PR34750.

llvm-svn: 314440
2017-09-28 18:12:13 +00:00
Rafael Espindola 100247fde4 Add a test.
This would have found the issues with r313697.

The problem was that that commit mixed the content of different
.eh_frame sections. Unfortunately we had no tests looking inside the
fdes.

llvm-svn: 314433
2017-09-28 17:15:02 +00:00
George Rimar 0b4d10c8b3 [ELF] - Change error message text. NFC.
As suggested in review comments of D38170.

llvm-svn: 314392
2017-09-28 09:29:03 +00:00
George Rimar 5375f4e6a8 [ELF] - Remove wrong comment from testcase.
It was introduced by me in D37059.
Comment was saying that Weak binding is incorrect
for 'foo' symbol and that should be true for symbol in final output.
But at that place LTO temporarily file was checked,
where Weak binding for 'foo' is fine as LTO changes binding for
'LinkerRedefined' symbols internally to prevent IPO.

Binding for 'foo' in final output is correctly set to Global
and that tested just few lines below in the same testcase.

llvm-svn: 314204
2017-09-26 13:35:00 +00:00
George Rimar 347c70d782 [ELF] - Report orphan sections if -verbose given.
When -verbose is specified, patch outputs names of each input orphan section
assigned to output.

Differential revision: https://reviews.llvm.org/D37517

llvm-svn: 314098
2017-09-25 09:41:32 +00:00
George Rimar d28c26bbdd [ELF] - LTO: do not optimize away symbols accessed from linkerscript.
Previously when BC file had global variable that was accessed from script,
it was optimized away or inlined by IPO. 
In this patch I add symbols at left side of assignment expression as LinkerRedefined,
what prevents optimization for them.

Differential revision: https://reviews.llvm.org/D37059

llvm-svn: 314097
2017-09-25 09:31:43 +00:00
Rui Ueyama 8f222b8158 Fix off-by-one error.
llvm-svn: 314093
2017-09-25 03:40:45 +00:00
Rui Ueyama bbc477c9b6 Do not use StringTableBuilder to build symbol table for .gdb_index.
Previously, we had two levels of hash table lookup. The first hash
lookup uses CachedHashStringRefs as keys and returns offsets in string
table. Then, we did the second hash table lookup to obtain GdbSymbol
pointers. But we can directly map strings to GDbSymbols.

One test file is updated in this patch because we no longer have a '\0'
byte at the start of the string pool, which was automatically inserted
by StringTableBuilder.

This patch speeds up Clang debug build (with -gdb-index) link time by
0.3 seconds.

llvm-svn: 314092
2017-09-25 02:29:51 +00:00
Zachary Turner 0aa02c08a7 Resubmit "[lit] Refactor out some more common lit configuration code."
There were two issues, one Python 3 specific related to Unicode,
and another which is that the tool substitution for lld no longer
rejected matches where a / preceded the tool name.

llvm-svn: 313928
2017-09-21 22:16:40 +00:00
Zachary Turner 5f2fd9b783 Revert "[lit] Refactor out some more common lit configuration code."
This is breaking several bots.  I have enough information to
investigate, so I'm reverting to green until I get it figured
out.

llvm-svn: 313922
2017-09-21 21:45:45 +00:00
Zachary Turner 0d36b657b9 [lit] Refactor out some more common lit configuration code.
debuginfo-tests has need to reuse a lot of common configuration
from clang and lld, and in general it seems like all of the
projects which are tightly coupled (e.g. lld, clang, llvm, lldb,
etc) can benefit from knowing about one other.  For example,
lldb needs to know various things about how to run clang in its
test suite.  Since there's a lot of common substitutions and
operations that need to be shared among projects, sinking this
up into LLVM makes sense.

In addition, this patch introduces a function add_tool_substitution
which handles all the dirty intricacies of matching tool names
which was previously copied around the various config files.  This
is now a simple straightforward interface which is hard to mess
up.

Differential Revision: https://reviews.llvm.org/D37944

llvm-svn: 313919
2017-09-21 21:27:31 +00:00
Shoaib Meenai 75d616b13f [ELF] Fix edge condition in thunk offset calculation
For ARM thunks, the `movt` half of the relocation was using an incorrect
offset (it was off by 4 bytes). The original intent seems to have been
for the offset to have been relative to the current instruction, in
which case the difference of 4 makes sense. As the code stands, however,
the offset is always calculated relative to the start of the thunk
(`P`), and so the `movw` and `movt` halves should use the same offset.
This requires a very particular offset between the thunk and its target
to be triggered, and it results in the `movt` half of the relocation
being off-by-one.

The tests here use ARM-Thumb interworking thunks, since those are the
only ARM thunks currently implemented. I actually encountered this with
a range extension thunk (having Peter's patches cherry-picked locally),
but the underlying issue is identical.

Differential Revision: https://reviews.llvm.org/D38112

llvm-svn: 313915
2017-09-21 21:04:42 +00:00
Zachary Turner bbe23ae675 [lit] Rename lld and clang lit configs to end in .py
This follows in line with a previous patch of renaming LLVM's.

Working on these files is difficult in certain operating systems
and/or environments that don't like handling python code with a
non .py file extension.

llvm-svn: 313892
2017-09-21 17:38:13 +00:00
Simon Atanasyan 6810367610 [MIPS] Restore checking of the disassembler output. NFC
llvm-svn: 313864
2017-09-21 04:55:27 +00:00
Davide Italiano bb0690e486 [AArch64] Properly check alignment for AARCH64_LD_PREL_LO19.
Follow-up suggested by Peter Smith.

llvm-svn: 313850
2017-09-21 00:26:28 +00:00
Davide Italiano 6fb3b428a4 [AArch64] Include test for out of range LD_PREL_LO19.
llvm-svn: 313846
2017-09-21 00:16:29 +00:00
Davide Italiano f681a8fa3a [AArch64] Implement R_AARCH64_ LD_PREL_LO19.
Fixes PR34660.

Differential Revision:  https://reviews.llvm.org/D38053

llvm-svn: 313841
2017-09-20 23:49:50 +00:00
Rafael Espindola 9e50291065 Include thin --whole-archive members in --reproduce.
We were only including the thin archive members used via a lazy symbol
before.

llvm-svn: 313832
2017-09-20 22:59:50 +00:00
Rafael Espindola 23be5e8d70 Consider ForceAbsolute again in moveAbsRight.
This patch goes back to considering ForceAbsolute in moveAbsRight, but
only if the second argument is not already absolute.

With this we can handle "foo + ABSOLUTE(foo)" and "ABSOLUTE(foo) + foo".

llvm-svn: 313800
2017-09-20 19:24:57 +00:00
Rafael Espindola 01a409520b Consider only A.Sec in moveAbsRight.
The idea of this function is to simplify the implementation of binary
operators like add.

A value might be absolute because of an ABSOLUTE expression, but it
still depends on the value of a section and we might not be able to
evaluate it early. We should keep such values on the LHS, so that we
can delay the evaluation.

We can now handle both "1 + ABSOLUTE(foo)" and "ABSOLUTE(foo) + 1".

llvm-svn: 313794
2017-09-20 18:56:08 +00:00
Rafael Espindola 9be24cf516 Fix assigning to _gp in linker scripts.
The previous logic was to try to detect if a linker script defined _gp
by checking !ElfSym::MipsGp->Value. That doesn't work in all cases as
the assigned value can be 0.

We now just always defined it Writer.cpp and always overwrite it
afterwards if needed.

llvm-svn: 313788
2017-09-20 18:30:57 +00:00
Rafael Espindola 8b250344e9 Add a special case for trivial alignment.
Normally to find the offset of a value in a section, we have to
compute the value since the alignment is defined on the final address.

If the alignment is trivial, we can skip the value computation. This
allows us to know the offset even in cases where we cannot yet know
the value.

llvm-svn: 313777
2017-09-20 17:43:44 +00:00
Rafael Espindola e4bad83edb Don't try to compute a value that is known to fail.
We try to evaluate expressions early when possible, but it is not
possible to evaluate them early if they are based on a section.

Before we would get this wrong on ABSOLUTE expressions.

llvm-svn: 313764
2017-09-20 16:42:56 +00:00
Shoaib Meenai 4aa7f8a30f [COFF] Check for sections larger than 4 GiB
Sections are limited to 4 GiB. Error out early if a section exceeds this
size, rather than overflowing the section size and getting confusing
assertion failures/segfaults later.

Differential Revision: https://reviews.llvm.org/D38005

llvm-svn: 313699
2017-09-19 23:58:05 +00:00
Rafael Espindola aad64e0a1c Tweak orphan section placement.
Given a linker script that ends in

.some_sec { ...} ;
__stack_start = .;
. = . + 0x2000;
__stack_end = .;

lld would put orphan sections like .comment before __stack_end,
corrupting the intended meaning.

The reason we don't normally move orphans past assignments to . is to
avoid breaking

rx_sec : { *(rx_sec) }
. = ALIGN(0x1000);
/* The RW PT_LOAD starts here*/

but in this case, there is nothing after and it seems safer to put the
orphan section last. This seems to match bfd's behavior and is
convenient for writing linker scripts that care about the layout of
SHF_ALLOC sections, but not of any non SHF_ALLOC sections.

llvm-svn: 313646
2017-09-19 17:29:58 +00:00
George Rimar 072a43b501 [ELF] - Do not merge sections from SHT_GROUP when -relocatable
This is PR34506.

Imagine we have 2 sections the same name but different COMDAT groups:

.section        .foo,"axG",@progbits,bar,comdat
.section        .foo,"axG",@progbits,zed,comdat
When linking relocatable we do not merge SHT_GROUP sections. But still would merge
both input sections .foo into single output section .foo.
As a result we will have 2 different SHT_GROUPs containing the same section, what
is wrong.

Patch fixes the issue, preventing merging SHF_GROUP sections with any others.

Differential revision: https://reviews.llvm.org/D37574

llvm-svn: 313621
2017-09-19 09:40:31 +00:00
George Rimar af52534e8a [ELF] - Don't crash when --emit-relocs is used with --gc-sections
We crashed when --emit-relocs was used
and relocated section was collected by GC.

Differential revision: https://reviews.llvm.org/D37561

llvm-svn: 313620
2017-09-19 09:28:03 +00:00
Zachary Turner d4401d354a [lit] Update clang and lld to use new config helpers.
NFC intended here, this only updates clang and lld's lit configs
to use some helper functionality in the lit.llvm submodule.

llvm-svn: 313579
2017-09-18 22:26:48 +00:00
Rui Ueyama eef6b2a5c9 Revert r303378: Set IMAGE_DLL_CHARACTERISTICS_NO_BIND.
r303378 was submitted because r303374 (Merge IAT and ILT) made lld's
output incompatible with the Binding feature. Now that r303374 was
reverted, we do not need to keep this change.

Pointed out by pcc.

llvm-svn: 313414
2017-09-15 22:49:13 +00:00
Zachary Turner ce92db13ea Resubmit "[lit] Force site configs to run before source-tree configs"
This is a resubmission of r313270.  It broke standalone builds of
compiler-rt because we were not correctly generating the llvm-lit
script in the standalone build directory.

The fixes incorporated here attempt to find llvm/utils/llvm-lit
from the source tree returned by llvm-config.  If present, it
will generate llvm-lit into the output directory.  Regardless,
the user can specify -DLLVM_EXTERNAL_LIT to point to a specific
lit.py on their file system.  This supports the use case of
someone installing lit via a package manager.  If it cannot find
a source tree, and -DLLVM_EXTERNAL_LIT is either unspecified or
invalid, then we print a warning that tests will not be able
to run.

Differential Revision: https://reviews.llvm.org/D37756

llvm-svn: 313407
2017-09-15 22:10:46 +00:00
Rafael Espindola e05e2f8b34 Keep some relocations with undefined weak symbols.
This fixes pr34301.

As the bug points out, we want to keep some relocations with undefined
weak symbols. This means that we cannot always claim that these
symbols are not preemptible as we do now.

Unfortunately, we cannot also just always claim that they are
preemptible. Doing so would, for example, cause us to try to create a
plt entry when we don't even have a dynamic symbol table.

What almost works is to say that weak undefined symbols are
preemptible if and only if we have a dynamic symbol table. Almost
because we don't want to fail the build trying to create a copy
relocation to a weak undefined.

llvm-svn: 313372
2017-09-15 18:05:02 +00:00
Zachary Turner 83dcb68468 Revert "[lit] Force site configs to run before source-tree configs"
This patch is still breaking several multi-stage compiler-rt bots.
I already know what the fix is, but I want to get the bots green
for now and then try re-applying in the morning.

llvm-svn: 313335
2017-09-15 02:56:40 +00:00
Rafael Espindola 056190c348 Don't make _gp absolute.
_gp points to a position in the file, so it is not really absolute. It
is also simpler to not force it to be absolute, so if there is no
strong ABI requirement we should not do it.

llvm-svn: 313333
2017-09-15 01:49:01 +00:00
Rui Ueyama 0e69bd3c3a Add tests for -out-implib.
llvm-svn: 313289
2017-09-14 19:45:22 +00:00
Rui Ueyama 1f4cdcfec9 Accept not only --foo but also -foo.
GNU ld manual says that multi-letter long option can be prefixed with
either -- or -. Therefore, we should accept not only --subsystem but
also -subsystem, for example.

There is one exception. If an option starts with "o", it should only be
prefixed with -- to avoid ambiguity with -o<filename> option.

Differential Revision: https://reviews.llvm.org/D37825

llvm-svn: 313286
2017-09-14 18:33:21 +00:00
Rui Ueyama b359263011 Filenames are case-insensitive on Windows, so .DEF is the same as .def.
Differential Revision: https://reviews.llvm.org/D37823

llvm-svn: 313285
2017-09-14 18:33:09 +00:00
Zachary Turner a0e55b6403 [lit] Force site configs to be run before source-tree configs
This patch simplifies LLVM's lit infrastructure by enforcing an ordering
that a site config is always run before a source-tree config.

A significant amount of the complexity from lit config files arises from
the fact that inside of a source-tree config file, we don't yet know if
the site config has been run.  However it is *always* required to run
a site config first, because it passes various variables down through
CMake that the main config depends on.  As a result, every config
file has to do a bunch of magic to try to reverse-engineer the location
of the site config file if they detect (heuristically) that the site
config file has not yet been run.

This patch solves the problem by emitting a mapping from source tree
config file to binary tree site config file in llvm-lit.py. Then, during
discovery when we find a config file, we check to see if we have a
target mapping for it, and if so we use that instead.

This mechanism is generic enough that it does not affect external users
of lit. They will just not have a config mapping defined, and everything
will work as normal.

On the other hand, for us it allows us to make many simplifications:

* We are guaranteed that a site config will be executed first
* Inside of a main config, we no longer have to assume that attributes
  might not be present and use getattr everywhere.
* We no longer have to pass parameters such as --param llvm_site_config=<path>
  on the command line.
* It is future-proof, meaning you don't have to edit llvm-lit.in to add
  support for new projects.
* All of the duplicated logic of trying various fallback mechanisms of
  finding a site config from the main config are now gone.

One potentially noteworthy thing that was required to implement this
change is that whereas the ninja check targets previously used the first
method to spawn lit, they now use the second. In particular, you can no
longer run lit.py against the source tree while specifying the various
`foo_site_config=<path>` parameters.  Instead, you need to run
llvm-lit.py.

Differential Revision: https://reviews.llvm.org/D37756

llvm-svn: 313270
2017-09-14 16:47:58 +00:00
Martin Storsjo 2ba37d4b3e [MinGW] Only apply -Bstatic to following libraries
This is how the flag is documented in GNU binutils ld; -Bstatic
only applies to -l options after it, until the next -Bdynamic.

Differential Revision: https://reviews.llvm.org/D37794

llvm-svn: 313175
2017-09-13 19:29:44 +00:00
Martin Storsjo 31fe4cd25d [MinGW] Support dllexport on i386
In MinGW configurations (GCC, or clang with a *-windows-gnu target),
the -export directives in the object file contains the undecorated
symbol name, while it is decorated in MSVC configurations. (On the
command line, link.exe takes an undecorated symbol name for the
-export argument though.)

Differential Revision: https://reviews.llvm.org/D37772

llvm-svn: 313174
2017-09-13 19:29:39 +00:00
Martin Storsjo 064b0fac93 [MinGW] Support creating DLLs with a def file
Differential Revision: https://reviews.llvm.org/D37761

llvm-svn: 313125
2017-09-13 07:28:13 +00:00
Martin Storsjo 32e1626a2e [MinGW] Add support for the options --[no-]whole-archive
Differential Revision: https://reviews.llvm.org/D37769

llvm-svn: 313124
2017-09-13 07:28:09 +00:00
Martin Storsjo 8278ba51d3 [COFF] Add support for the -wholearchive option
This fixes PR31824.

Differential Revision: https://reviews.llvm.org/D37709

llvm-svn: 313123
2017-09-13 07:28:03 +00:00
Rafael Espindola 7415819186 Handle lazy symbols is Symbol::includeInDynsym.
This should fix the lto bootstrap.

It is somewhat hard to remember about lazy symbols deep down in the
link. It might be worth it replacing them with undefined symbols once
we are done adding files.

llvm-svn: 313103
2017-09-13 00:47:06 +00:00
Rui Ueyama 28ebaf39cb Add test cases for the -l option.
llvm-svn: 313094
2017-09-12 23:42:26 +00:00
Ben Dunbobbin 0b95d3784a [ELF] Handle references to garbage collected common symbols
https://reviews.llvm.org/rL312796 meant that references to garbage collected common symbols would cause a segfault.

This change fixes the behaviour for references to stripped common symbols.

Differential Revision: https://reviews.llvm.org/D37718

llvm-svn: 313086
2017-09-12 22:41:45 +00:00
Martin Storsjo 6d8dace438 [MinGW] Pass the undecorated entry point name to the COFF linker
On i386, the --entry parameter to GNU ld is supposed to be a decorated
symbol name, while it is an undecorated name in link.exe.

Differential Revision: https://reviews.llvm.org/D37710

llvm-svn: 313066
2017-09-12 19:23:54 +00:00
Rui Ueyama a54ed0a407 Simplify MinGW test.
Differential Revision: https://reviews.llvm.org/D37708

llvm-svn: 313045
2017-09-12 16:29:07 +00:00
Simon Atanasyan b04eee5236 [MIPS] Check raw binary file content instead of disassembled code. NFC
For now LLD does not setup the least-significant bit for microMIPS
symbols. llvm-objdump does not like that. In attempt to fix
sanitizer-x86_64-linux-fast build-bot let's temporarily check the raw
binary file content.

llvm-svn: 313040
2017-09-12 16:09:42 +00:00
Simon Atanasyan 4f70b30d6f [MIPS] Initial support of microMIPS code linking
The patch implements initial support of microMIPS code linking:
  - Handle microMIPS specific relocations.
  - Emit both R1-R5 and R6 microMIPS PLT records.

For now linking mixed set of regular and microMIPS object files is not
supported. Also the patch does not handle (setup and clear) the
least-significant bit of an address which is utilized as the ISA mode
bit and allows to make jump between regular and microMIPS code without
any thunks.

Differential revision: https://reviews.llvm.org/D37335

llvm-svn: 313028
2017-09-12 13:08:24 +00:00
Rafael Espindola a6acd23c53 Align addresses, not offsets.
This fixes two more cases where we were aligning the offset in a
section, instead of the final address.

llvm-svn: 312983
2017-09-12 00:06:00 +00:00
Rafael Espindola b7147ad3dd Correct ALIGN expression when inside a section.
When given

foobar = ALIGN(., 0x100);

my expectation from what the manual says is that the final address of
foobar will be aligned. It seems that bfd aligns the offset in the
section, which causes some odd results if the section is not 0x100
aligned. Gold aligns the address.

This changes lld to align the final address.

llvm-svn: 312979
2017-09-11 23:44:53 +00:00
Adrian Prantl dcf890598c Update testcases for llvm-dwarfdump command line interface change
llvm-svn: 312976
2017-09-11 23:34:12 +00:00
Adrian Prantl 65b79a544f Update testcases for llvm-dwarfdump command line interface change
llvm-svn: 312974
2017-09-11 23:28:21 +00:00
Martell Malone 0d17638b89 LLD: Add -mllvm flag to the MinGW driver.
This adds support for passing LTO flags to the MINGW driver
in GNU LD style i.e. -mllvm flag -> /mllvm:flag

Reviewers: ruiu, mstorsjo

Differential Revision: https://reviews.llvm.org/D37712

llvm-svn: 312956
2017-09-11 21:36:37 +00:00
Martin Storsjo a79762a32d [MinGW] Map the -verbose option, implement -### for showing the produced parameters
Pass the -verbose option through to the COFF linker, and show the
arguments passed to it. If the -### option is specified, just show
the produced argument list and exit, just like in clang.

Replace the first argument with "lld-link" in order to produce a
correct command line.

Differential Revision: https://reviews.llvm.org/D37706

llvm-svn: 312944
2017-09-11 20:43:39 +00:00
Rui Ueyama e298e5e9c5 Remove cross-target test dependency.
Tests for MinGW shouldn't depend on files under test/COFF/Inputs.

llvm-svn: 312931
2017-09-11 18:00:03 +00:00
Martell Malone 894dbbe8eb LLD: Introduce a GNU LD style driver for COFF
When building COFF programs many targets such as mingw prefer
to have a gnu ld frontend. Rather then having a fully fledged
standalone driver we wrap a shim around the LINK driver.

Extra tests were provided by mstorsjo

Reviewers: mstorsjo, ruiu

Differential Revision: https://reviews.llvm.org/D33880

llvm-svn: 312926
2017-09-11 17:02:59 +00:00
James Henderson 4c2a3ec33b [ELF] Fix issue with test when build path contains '@'
'@' is a valid character in file paths, but the linker script tokenizer treats it
as a separate token. This was leading to an unexpected test failure, on our local
builds. This patch changes the test to quote the path to prevent this happening.

An alternative would have been to add '@' to the list of "unquoted tokens" in
ScriptLexer.cpp, but ld.bfd has the same behaviour as the current LLD.

Reviewers: ruiu

Differential Revision: https://reviews.llvm.org/D37689

llvm-svn: 312922
2017-09-11 15:55:54 +00:00
Rafael Espindola 8016bdfd93 Handle empty dynamic lists.
llvm-svn: 312820
2017-09-08 18:53:43 +00:00
Rafael Espindola ee6a352a8d Handle lazy symbols is computeIsPreemptible.
llvm-svn: 312812
2017-09-08 18:41:49 +00:00
Rafael Espindola d72d97b3be If --dynamic-list is given, only those symbols are preemptible.
This allows combining --dynamic-list and version scripts too. The
version script controls which symbols are visible, and
--dynamic-list controls which of those are preemptible.

Unlike previous versions, undefined symbols are still considered
preemptible, which was the issue breaking the cfi tests.

This fixes pr34053.

llvm-svn: 312806
2017-09-08 18:16:59 +00:00
Dmitry Mikulin 1e30f07ce7 Currently lld creates a single section to collect all commons. There is no way
to separate commons based on file name patterns. The following linker script
construct does not work because commons are allocated before section placement
is done and the only synthesized BssSection that holds all commons has no file
associated with it:
SECTIONS { .common_0 : { *file0.o(COMMON) }}

This patch changes the allocation of commons to create a section per common
symbol and let the section logic do the layout.

Differential revision: https://reviews.llvm.org/D37489

llvm-svn: 312796
2017-09-08 16:22:43 +00:00
George Rimar 113a5ca029 [ELF] - Simplify and improve symbols.s testcase.
There is no need to check anything excepr that
symbol is not in output.
Previously additional iformation like symbol values
or flags were checked, that was not correct.
For example if we would provide symbol with different
value/visibility/type for case when should not provide 
symbol at all, testcase would not fail.

llvm-svn: 312779
2017-09-08 09:31:01 +00:00
George Rimar 5f37541c73 [ELF] - Linkerscript: implement REGION_ALIAS.
REGION_ALIAS(alias, region)

Alias names can be added to existing memory regions created with
the MEMORY command. Each name corresponds to at most one
memory region.

Differential revision: https://reviews.llvm.org/D37477

llvm-svn: 312777
2017-09-08 08:23:15 +00:00
Rafael Espindola 0ff545c018 Revert "Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible""
This reverts commit r312757.

Evgenii Stepanov reports that it broke some tests.

llvm-svn: 312771
2017-09-08 01:09:52 +00:00
Peter Collingbourne 052e855e2b COFF: Implement ThinLTO cache and cache pruning support.
Differential Revision: https://reviews.llvm.org/D37607

llvm-svn: 312770
2017-09-08 00:50:50 +00:00
Rui Ueyama 721b71d532 Replace CRLF.
llvm-svn: 312765
2017-09-07 23:54:32 +00:00
Rui Ueyama d63ac33948 Remove a stale comment.
llvm-svn: 312763
2017-09-07 23:54:20 +00:00
Rafael Espindola b7d0be5896 Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible"
If --dynamic-list is given, only those symbols are preemptible.

This allows combining --dynamic-list and version scripts too. The
version script controls which symbols are visible, and --dynamic-list
controls which of those are preemptible.

This fixes pr34053.

llvm-svn: 312757
2017-09-07 23:19:09 +00:00
Rui Ueyama e2f52eb22f Add -no-gdb-index which negates -gdb-index option.
llvm-svn: 312753
2017-09-07 22:40:54 +00:00