Commit Graph

3780 Commits

Author SHA1 Message Date
Peter Collingbourne 6c55a70838 ELF: Remove DefinedCommon.
Common symbols are now represented with a DefinedRegular that points
to a BssSection, even during symbol resolution.

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

llvm-svn: 317447
2017-11-06 04:33:58 +00:00
George Rimar ddd2424929 [ELF] - Fix error reporting with --strip-debug/--strip-all.
Currently LLD tries to use information about functions and variables location
taking it from debug sections. When --strip-* is given we discard such sections
and that breaks error reporting.
Patch stops discarding such sections and just removes them from InputSections list.

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

llvm-svn: 317405
2017-11-04 08:20:30 +00:00
Petr Hosek 8c7e8cce99 [ELF] Support expressions with -defsym option
Fixes PR34948.

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

llvm-svn: 317396
2017-11-04 02:03:58 +00:00
Bob Haarman 3fae5a6179 Revert "[ELF] - Teach LLD to use information from .debug_str for error reporting."
This reverts commit 00b7acb8f6c8a4663bb7c8396d217c210209b562.

It was causing some links to execute llvm_unreachable.

llvm-svn: 317378
2017-11-03 22:23:19 +00:00
Martin Storsjo 068512dfb9 [MinGW] Output debug info by default, unless the -s parameter is passed
Differential Revision: https://reviews.llvm.org/D39541

llvm-svn: 317376
2017-11-03 22:10:37 +00:00
Martin Storsjo dc95dbfcab [COFF] Autoexport symbols as data if they don't point to an executable section
This was already taken care of for the output def file.

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

llvm-svn: 317367
2017-11-03 20:58:20 +00:00
George Rimar 8c825db25e [ELF] - Linkerscript: fixed non-determinism when handling MEMORY.
When findMemoryRegion do search to find a region for output section it
iterates over MemoryRegions which is DenseMap and so does not
guarantee iteration in insertion order. As a result selected region depends
on its name and not on its definition position
Testcase shows the issue, patch fixes it. Behavior after applying the patch
seems consistent with bfd.

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

llvm-svn: 317307
2017-11-03 08:21:51 +00:00
George Rimar cbed0e615b [ELF] - Teach LLD to strip .zdebug_* sections when --strip-debug/--strip-all is specified.
Currently we do not strip .zdebug_*, what looks wrong.
Also this simplifies the testcase we have for this options.

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

llvm-svn: 317306
2017-11-03 08:13:16 +00:00
George Rimar 5b262363b4 [ELF] - Teach LLD to use information from .debug_str for error reporting.
Recently we teached LLD to report line numbers for duplicate variables
definitions, though currently LLD is unable to do that for case when
strings are not built in .debug_info, but stored in .debug_str instead.
That is because out LLDDwarfObj does not handle .debug_str yet. 
Patch fixes that.

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

llvm-svn: 317305
2017-11-03 08:04:27 +00:00
Martin Storsjo 107b548368 [MinGW] Add an option -Xlink for passing options through to lld-link
Also move the -mllvm option to the right section of the options
list.

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

llvm-svn: 317302
2017-11-03 07:18:37 +00:00
George Rimar 82f0c42dad [ELF] - Teach LLD to report line numbers for data symbols.
This is PR34826.

Currently LLD is unable to report line number when reporting
duplicate declaration of some variable.

That happens because for extracting line information we always use
.debug_line section content which describes mapping from machine
instructions to source file locations, what does not help for
variables as does not describe them.

In this patch I am taking the approproate information about
variables locations from the .debug_info section.

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

llvm-svn: 317080
2017-11-01 07:42:38 +00:00
Rui Ueyama 700b1f8a56 Add --no-omagic and --no-print-gc-sections.
llvm-svn: 317068
2017-11-01 02:04:43 +00:00
Oleg Ranevskyy 0cf24ed9aa [lld] Fix --exclude-libs broken when --whole-archive is used
Summary:
**Problem**
`--exclude-libs` does not work for static libraries affected by the `--whole-archive` option.

**Description**
`--exclude-libs` creates a list of static library paths and does library lookups in this list.
`--whole-archive` splits the static libraries that follow it into separate objects. As a result, lld no longer sees static libraries among linked files and does no `--exclude-libs` lookups.

**Solution**
The proposed solution is to make `--exclude-libs` consider object files too. When lld finds an object file it checks whether this file originates from an archive and, if so, looks the archive up in the `--exclude-libs` list.

Reviewers: ruiu, rafael

Reviewed By: ruiu

Subscribers: asl, ikudrin, llvm-commits, emaste

Tags: #lld

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

llvm-svn: 316998
2017-10-31 13:51:06 +00:00
Jake Ehrlich 1128dc5e30 Give .note.gnu.build-id section alignment 4
All SHT_NOTE sections should have minimum alignment 4.

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

llvm-svn: 316961
2017-10-30 22:08:11 +00:00
Rafael Espindola 458173e802 Use 64 bits for the shared symbol size again.
We might want to drop support for such large symbols, but that should
be an explicit decision with a testcase.

llvm-svn: 316931
2017-10-30 17:43:16 +00:00
Rafael Espindola 566dbdc2fd Skip abs symbols when handling copy reloc aliases.
Since we now only check st_value, we have to consider the case where
the section index is special.

llvm-svn: 316928
2017-10-30 17:26:12 +00:00
Peter Collingbourne e662436114 ELF: Correctly set edata if there are no .bss sections.
edata needs to be set to the end of the last mapped initialized
section. We were previously mishandling the case where there were no
non-mapped sections by setting it to the end of the last section in
the output file.

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

llvm-svn: 316877
2017-10-29 22:31:48 +00:00
Rui Ueyama f405b11224 Simplify error handling.
I don't think we have to aim for precise bug compatibility.
We can return a nullptr if a section is consumed by the linker, and
the rest should naturally work.

llvm-svn: 316817
2017-10-28 00:05:12 +00:00
Rui Ueyama 8f6e8ed9dd Remove trailing whitespace.
llvm-svn: 316787
2017-10-27 19:23:12 +00:00
Rafael Espindola bc2b1650d7 Handle all symbol types in --trace.
One case I was not sure was lazy symbols. bfd skips them completely,
but that is probably an artifact of how they implement archives.

llvm-svn: 316782
2017-10-27 18:30:11 +00:00
Peter Collingbourne 5c54f15c55 ELF: Add support for emitting dynamic relocations in the Android relocation packing format.
The Android relocation packing format is a more compact
format for dynamic relocations in executables and DSOs
that is based on delta encoding and SLEBs. An overview
of the format can be found in the Android source code:
https://android.googlesource.com/platform/bionic/+/refs/heads/master/tools/relocation_packer/src/delta_encoder.h

This patch implements relocation packing using that format.

This implementation uses a more intelligent algorithm for compressing
relative relocations than Android's own relocation packer. As a
result it can generally create smaller relocation sections than
that packer. If I link Chromium for Android targeting ARM32 I get a
.rel.dyn of size 174693 bytes, as compared to 371832 bytes with gold
and the Android packer.

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

llvm-svn: 316775
2017-10-27 17:49:40 +00:00
George Rimar 90dacc256f [ELF] - Ignore non-absolute R_386_GOTPC relocation in debug sections.
This is for PR34852.

GCC 8.0 or earlier have a bug that it emits R_386_GOTPC relocations
against _GLOBAL_OFFSET_TABLE for .debug_info. The bug seems to have
been fixed in 2017: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630,
but we do not want LLD to report errors for such inputs.
In this patch we ignore such relocations.

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

llvm-svn: 316761
2017-10-27 11:49:24 +00:00
George Rimar 3396bf07a2 [ELF] - Stop naming relocation sections with first input section name.
It was reported (https://reviews.llvm.org/D38724#902841) that when we use 
-ffunction-sections --emit-relocs build, REL[A] output section receives the name of first
input section, like .rela.text.first_function_in_text rather than .rela.text.

It is probably not really an issue as sh_info still points to correct target section, but
it does not look clean in output and allows internal section name to leak there,
what at least looks confusing and is not consistent with ld.bfd.

Patch changes this behavior so that target output section name is used as a base.

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

llvm-svn: 316760
2017-10-27 11:38:31 +00:00
Peter Smith 7f92294e9b [ELF][ARM] Add missing REQUIRES: arm to tests
My apologies I missed REQUIRES: arm from a couple of Arm specific tests.

llvm-svn: 316755
2017-10-27 09:16:46 +00:00
Peter Smith 6c9df3fce5 [ELF] Add support for multiple passes to createThunks()
This change allows Thunks to be added on multiple passes. To do this we must
merge only the thunks added in each pass, and deal with thunks that have
drifted out of range of their callers.

A thunk may end out of range of its caller if enough thunks are added in
between the caller and the thunk. To handle this we create another thunk.

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

llvm-svn: 316754
2017-10-27 09:07:10 +00:00
Peter Smith 75030b6d56 [ELF] Introduce range extension thunks for ARM
This change adds initial support for range extension thunks. All thunks must
be created within the first pass so some corner cases are not supported. A
follow up patch will add support for multiple passes.

With this change the existing tests arm-branch-error.s and
arm-thumb-branch-error.s now no longer fail with an out of range branch.
These have been renamed and tests added for the range extension thunk.

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

llvm-svn: 316752
2017-10-27 09:04:11 +00:00
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