Commit Graph

4374 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
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
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
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
Rui Ueyama d5135b7e99 Remove obsolete comment.
llvm-svn: 316520
2017-10-24 21:44:43 +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
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
Rafael Espindola 089dac7be1 Make Ctx a plain pointer again.
If a struct has a std::unique_ptr member, the logical interpretation
is that that member will be destroyed with the struct.

That is not the case for Ctx. It is has to be deleted earlier and its
lifetime is defined by the functions where the AddressState is
created.

llvm-svn: 316378
2017-10-23 21:12:19 +00:00
Konstantin Zhuravlyov 70abb6e204 LLD: Fix large integer implicitly truncated to unsigned type gcc warning
This fixes gcc warning.

Change by Brian Sumner

llvm-svn: 316365
2017-10-23 19:31:31 +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
Rui Ueyama d96724db42 Remove a fast lookup table from MergeInputSection.
We used to have a map from section piece offsets to section pieces
as a cache for binary search. But I found that the map took quite a
large amount of memory and didn't make linking faster. So, in this
patch, I removed the map.

This patch saves 566 MiB of RAM (2.019 GiB -> 1.453 GiB) when linking
clang with debug info, and the link time is 4% faster in that test case.

Thanks for Sean Silva for pointing this out.

llvm-svn: 316305
2017-10-22 23:02:07 +00:00
Rui Ueyama 53a9aff93e Simplify.
llvm-svn: 316281
2017-10-22 01:58:30 +00:00
Rui Ueyama 95bf509873 Assume that mergeable input sections are smaller than 4 GiB.
By assuming that mergeable input sections are smaller than 4 GiB,
lld's memory usage when linking clang with debug info drops from
2.788 GiB to 2.019 GiB (measured by valgrind, and that does not include
memory space for mmap'ed files). I think that's a reasonable assumption
given such a large RAM savings, so this patch.

According to valgrind, gold needs 3.54 GiB of RAM to do the same thing.

NB: This patch does not introduce a limitation on the size of
output sections. You can still create sections larger than 4 GiB.

llvm-svn: 316280
2017-10-21 23:20:13 +00:00
Rafael Espindola 849d499e6d Don't call buildSectionOrder multiple times.
This takes linking the linux kernel from 1.52s to 0.58s.

llvm-svn: 316251
2017-10-21 00:05:01 +00:00
Rafael Espindola 3558e24ae8 Remove unused argument.
llvm-svn: 316248
2017-10-20 23:28:19 +00:00
George Rimar 1c09dfe2bc [ELF] - Simplify. NFC.
llvm-svn: 316163
2017-10-19 15:03:59 +00:00
George Rimar da8808bf91 [ELF] - Removed outdated comment. NFC.
llvm-svn: 316078
2017-10-18 13:22:21 +00:00
George Rimar 0d6f30e80d [ELF] - Moved, fixed outdated comment. NFC.
It was at wrong place.

llvm-svn: 316077
2017-10-18 13:06:18 +00:00
George Rimar ee7c99b63a [ELF] - Make LinkerScript::assignOffsets private. NFC.
llvm-svn: 316073
2017-10-18 12:09:41 +00:00
George Rimar a4ca931336 [ELF] - Remove excessive helper. NFC.
Removes addRegular() helper that looks excessive from Writer.cpp.

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

llvm-svn: 316068
2017-10-18 08:36:47 +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
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