Commit Graph

9445 Commits

Author SHA1 Message Date
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
George Rimar 96b1157814 [ELF] - Simplify reporting of garbage collected sections.
This moves reporting of garbage collected sections right after
we do GC. That simplifies things.

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

llvm-svn: 316759
2017-10-27 11:32:22 +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
Peter Smith 4a8e11595c [ELF] Record created ThunkSections in InputSectionDescription [NFC].
Instead of maintaining a map of the std::vector to ThunkSections, record the
ThunkSections directly in InputSectionDescription.

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

llvm-svn: 316750
2017-10-27 08:56:20 +00:00
Rui Ueyama 0f46e45b03 Simplify logic to find the last executable segment. NFC.
llvm-svn: 316742
2017-10-27 05:08:39 +00:00
Rui Ueyama df15559c80 Fix typo.
llvm-svn: 316741
2017-10-27 04:59:33 +00:00
Rui Ueyama f9c66e4b80 Remove a boolean flag `Create`. NFC.
llvm-svn: 316738
2017-10-27 04:15:28 +00:00
Rui Ueyama 79048e4c5c Define a file-local write32 as a wrapper for endian::write32.
llvm-svn: 316736
2017-10-27 03:59:34 +00:00
Rui Ueyama 25f30880f5 Do not use InputSection::getFile<ELFT>() if InputSection::File suffices. NFC.
llvm-svn: 316735
2017-10-27 03:25:04 +00:00
Rui Ueyama 02551abdca De-template EhFrameHdr. NFC.
llvm-svn: 316734
2017-10-27 03:14:24 +00:00
Rui Ueyama 8629752c04 De-template EhReader. NFC.
llvm-svn: 316733
2017-10-27 03:14:09 +00:00
Rui Ueyama d6b7a390d8 De-template elf::getObjMsg. NFC.
llvm-svn: 316732
2017-10-27 03:13:54 +00:00
Rui Ueyama 572247f22e De-template EhFrameSection. NFC.
llvm-svn: 316731
2017-10-27 03:13:39 +00:00
Rui Ueyama c055225c6b Make EhFrameHdr pull data from EhFrameSection. NFC.
Previously, EhFrameSection pushes data to EhFrameHdr by calling addFde
function. By making EhFrameHdr pull data from EhFrameSection, we can
eliminate a member from EhFrameHdr.

llvm-svn: 316730
2017-10-27 03:13:24 +00:00
Rui Ueyama 076e2bb10e De-template a few functions. NFC.
llvm-svn: 316729
2017-10-27 03:13:09 +00:00
Rui Ueyama 88f0568ce5 Include an error code when getRandomBytes failed.
In a rare situation, the function can fail (e.g. it fails if it cannot
open /dev/urandom.)

llvm-svn: 316726
2017-10-27 01:25:29 +00:00
Rui Ueyama ed55e6c64f Remove an unnecessary inheritance.
llvm-svn: 316716
2017-10-26 23:54:00 +00:00
Rui Ueyama bfa84325ee Simplify.
Because of the same reason as r316600, I don't think we need a guard
against empty relocations.

llvm-svn: 316710
2017-10-26 22:30:25 +00:00
Rui Ueyama 6e5fda9db8 Move bit operations to a new file, ELF/Bits.h.
llvm-svn: 316707
2017-10-26 21:37:17 +00:00
Martin Storsjo ab9c98c70d [MinGW] Ignore the --enable-auto-import flag
In GNU ld, this option is enabled by default, but can be set
to reduce some warnings.

For lld, ignore the flag (for now); in case linking still succeeds
everything should be fine, if not, it should be clear to the user
what part failed (possibly requiring adjusting the user project
to not rely on this feature), instead of straight out failing due to
an unknown flag.

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

llvm-svn: 316693
2017-10-26 20:12:01 +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
Bob Haarman b8a59c8aa5 [lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits

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

llvm-svn: 316624
2017-10-25 22:28:38 +00:00
Rui Ueyama 8e38ea8b9e Unassign sections if they are "assigned" to /DISCARD/.
"/DISCARD/" is a special section name in the linker script to discard
input sections. Previously, we handled it as if it were a real section,
so an input section can be assigned but dead. However, allowing sections
to be

 - assigned and alive (will be emitted),
 - not assigned and dead (removed), or
 - assigned but dead (???)

feels logically wrong and practically error-prone. This patch removes
the last combination of the states.

llvm-svn: 316622
2017-10-25 22:03:21 +00:00
Rui Ueyama cfa171d68c Simplify.
ArrayRef<T>() equals to ArrayRef<T>(nullptr, 0), so it looks like
we don't need to handle size 0 as a special case.

llvm-svn: 316600
2017-10-25 18:09:54 +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
Rui Ueyama d5135b7e99 Remove obsolete comment.
llvm-svn: 316520
2017-10-24 21:44:43 +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
Shoaib Meenai 59bf362974 [COFF] Clean up boolean flag handling
LLD's handling of boolean flags is suboptimal:
* All boolean flags have a corresponding `:no` flag to turn the flag
  off, and the linker should scan for both the non-suffixed and suffixed
  flags (and the last one should win), but right now it only scans for
  either the suffixed or non-suffixed flag (depending on the default
  flag value).
* The `B` multiclass only allows specifying help text for the suffixed
  (`:no`) flag, but for some flags (e.g. `/appcontainer`) the help text
  should be associated with the non-suffixed flag instead.

Extend the `B` multiclass to have help text for both non-suffixed and
suffixed flag variants, and alter the existing help text accordingly in
some cases. Scan for both the non-suffixed and suffixed variants in the
driver and set config values accordingly.

This should mostly have no behavior change, apart from the added help
text and the modified argument scanning. Some flags are handled slightly
differently now, however; for example, LLD would previously always treat
64-bit images as large address aware, whereas `/largeaddressaware:no` is
now respected for 64-bit images (which is also how link.exe behaves).

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

llvm-svn: 316501
2017-10-24 21:17:16 +00:00
Rui Ueyama ac7aaeb770 Use ArgList::hasFlag().
I just didn't know that ArgList had that function.

llvm-svn: 316499
2017-10-24 20:59:55 +00:00
Rui Ueyama f8f4620dc6 Move comment to the place where it makes more sense.
llvm-svn: 316491
2017-10-24 20:11:07 +00:00
Rui Ueyama 7b4eddf0ea Improve comment.
llvm-svn: 316489
2017-10-24 19:53:51 +00:00
Rui Ueyama 51f604ce66 Simplify.
llvm-svn: 316486
2017-10-24 19:40:03 +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
Konstantin Zhuravlyov e7f1734f1a LLD/ELF: Allow targets to set e_flags
Differential Revision: https://reviews.llvm.org/D39139

llvm-svn: 316460
2017-10-24 17:01:40 +00:00
Rafael Espindola 9c8f853ca9 Refactor duplicated comment. NFC.
llvm-svn: 316455
2017-10-24 16:27:31 +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
Reid Kleckner 5d82f68d17 [PDB] Fix logging of bad type indices
llvm-svn: 316386
2017-10-23 22:44:51 +00:00