Commit Graph

9418 Commits

Author SHA1 Message Date
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
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
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 6f4e255219 lld::COFF: better behavior when using as a library
Previously, the COFF driver would call exit(0) when called
as a library.  Now it takes `ExitEarly` option, and if it
is false, it doesn't exit.  So it is now more library-friendly.

Furthermore, link() calls freeArena() before returning, to
clean up resources.

Based on an Andrew Kelley's patch.

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

llvm-svn: 316370
2017-10-23 20:03:32 +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
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 32fefef7fc [MinGW] Omit libc++/libc++abi/libunwind from autoexporting
Differential Revision: https://reviews.llvm.org/D39167

llvm-svn: 316318
2017-10-23 09:08:28 +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
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
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 3af5ffb538 [COFF] Avoid forward declaring StringSet, fix build
This should fix the build after SVN r316178, which worked fine
on GCC 5.4, but failed on clang with errors like these:

MinGW.h:26:3: error: too few template arguments for class template 'StringSet'
  StringSet<> ExcludeSymbols;
  ^
lld/Common/LLVM.h:28:30: note: template is declared here
  template<typename T> class StringSet;

Don't forward declare and add the using directive in the main
lld/Common/LLVM.h header, but just qualify the class name
in MinGW.h instead.

llvm-svn: 316180
2017-10-19 20:19:16 +00:00
Martin Storsjo e1f894d59e [COFF] Move MinGW specific functions/classes to a separate file. NFC.
Differential Revision: https://reviews.llvm.org/D39067

llvm-svn: 316178
2017-10-19 19:49:38 +00:00
George Rimar 1c09dfe2bc [ELF] - Simplify. NFC.
llvm-svn: 316163
2017-10-19 15:03:59 +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
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
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