Commit Graph

634 Commits

Author SHA1 Message Date
Rui Ueyama f1894fe37e Move code to improve readability. NFC.
llvm-svn: 332995
2018-05-22 16:19:38 +00:00
Rui Ueyama 47055bb197 Simplify. NFC.
We can directly assign to a std::pair without std::tie.

llvm-svn: 332994
2018-05-22 16:16:09 +00:00
Rui Ueyama 0dd56dcdd4 Handle --plugin-opt= options as alias options.
Previously, we had a loop to iterate over options starting with
`--plugin-opt=` and parse them by hand. But we can make OptTable
do that job for us.

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

llvm-svn: 332935
2018-05-22 02:53:11 +00:00
Rumeet Dhindsa d2eb089a0e Add support for ThinLTO plugin option thinlto-object-suffix-replace
Differential Revision: https://reviews.llvm.org/D46608

llvm-svn: 332527
2018-05-16 21:04:08 +00:00
Peter Smith dbef8cc67c [ELF] Implement --keep-unique option
The --keep-unique <symbol> option is taken from gold. The intention is that
<symbol> will be prevented from being folded by ICF. Although not
specifically mentioned in the documentation <symbol> only matches
global symbols, with a warning if the symbol is not found.

The implementation finds the Section defining <symbol> and removes it from
the set of sections considered for ICF.

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

llvm-svn: 332332
2018-05-15 08:57:21 +00:00
Sriraman Tallam be01d2e3de New option -z keep-text-section-prefix to keep text sections with prefixes separate.
Separate output sections for selected text section prefixes to enable TLB optimizations and for readablilty.

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

llvm-svn: 331823
2018-05-08 23:19:50 +00:00
Rumeet Dhindsa b5b7d6e19c Add support for LTO plugin option obj-path
Differential Revision: https://reviews.llvm.org/D46598

llvm-svn: 331817
2018-05-08 22:37:57 +00:00
Rui Ueyama ac403ef7f0 Improve error message for --plugin-opt=thinlto-prefix-replace.
llvm-svn: 331700
2018-05-07 23:24:25 +00:00
Rui Ueyama d432f216d1 Rename Config::ThinLTOIndexOnlyObjectFiles -> Config::ThinLTOIndexOnlyArg.
llvm-svn: 331699
2018-05-07 23:24:16 +00:00
Rumeet Dhindsa 4fb5119215 Add support for thinlto option ( thinlto-emit-imports-files) to emit import files for thinlink.
Differential Revision: https://reviews.llvm.org/D46400

llvm-svn: 331696
2018-05-07 23:14:12 +00:00
Rui Ueyama 554adb2e97 Do not call exit() directly from lld.
Our promise is that as long as there's no fatal error (i.e. broken
file is given to the linker), our main function returns to the caller.
So we can't use exit() in the regular code path.

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

llvm-svn: 331690
2018-05-07 22:11:34 +00:00
Rui Ueyama 4454b3d1eb Parse --thinlto-prefix-replace early so that we don't need to parse it later. NFC.
llvm-svn: 331657
2018-05-07 17:59:43 +00:00
Peter Smith 2689d9f4f0 [ELF][AArch64] Add aarch64_elf64_le_vec emulation
Android AOSP has started specifying -m aarch64_elf64_le_vec as supported
by gold and BFD. This is a simple change to add the emulation so that LLD
doesn't immediately error when used as a linker in an AOSP build.

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

llvm-svn: 331521
2018-05-04 14:28:29 +00:00
Rumeet Dhindsa d366e36bbf Added support for ThinLTO plugin options : thinlto-index-only and thinlto-prefix-replace
Differential Revision: https://reviews.llvm.org/D46034

llvm-svn: 331405
2018-05-02 21:40:07 +00:00
Rafael Espindola f1652d4c60 Split .eh_frame sections in parellel.
We can now split them in the same spot we split merge sections.

llvm-svn: 331064
2018-04-27 18:17:36 +00:00
Rafael Espindola 9bf1006278 Split merge sections early.
Now that getSectionPiece is fast (uses a hash) it is probably OK to
split merge sections early.

The reason I want to do this is to split eh_frame sections in the same
place.

This does mean that we have to decompress early. Given that the only
compressed sections are debug info, I don't think we are missing much.

It is a small improvement: 0.5% on the geometric mean.

llvm-svn: 331058
2018-04-27 16:29:57 +00:00
Rafael Espindola 047f857642 Also demote lazy symbols.
This is not a big simplification right now, but the special cases for
lazy symbols have been a common source of bugs in the past.

llvm-svn: 330869
2018-04-25 20:46:08 +00:00
Rafael Espindola 61376d9bed Bring r329960 back.
The fix is to copy Used when replacing the symbol.

Original message:

Do not keep shared symbols created from garbage-collected eliminated DSOs.

If all references to a DSO happen to be weak, and if the DSO is
specified with --as-needed, the DSO is not added to DT_NEEDED.
If that happens, we also need to eliminate shared symbols created
from the DSO. Otherwise, they become dangling references that point
to non-exsitent DSO.

Fixes https://bugs.llvm.org/show_bug.cgi?id=36991

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

llvm-svn: 330788
2018-04-25 00:29:13 +00:00
Rui Ueyama 88fe5c9557 Add -z {combreloc,copyreloc,noexecstack,lazy,relro,text}.
Differential Revision: https://reviews.llvm.org/D45902

llvm-svn: 330482
2018-04-20 21:24:08 +00:00
Fangrui Song 2416d7fcb2 [ELF] --warn-backrefs: use the same GroupId for object files in the same --{start,end}-lib
Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 330443
2018-04-20 16:33:01 +00:00
Fangrui Song b72daf00f4 [ELF] Increase NextGroupId with --end-group
Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 330379
2018-04-19 23:23:23 +00:00
Michael J. Spencer b842725c1d [ELF] Add profile guided section layout
This adds profile guided layout using the Call-Chain Clustering (C³) heuristic
from https://research.fb.com/wp-content/uploads/2017/01/cgo2017-hfsort-final1.pdf .

RFC: [llvm-dev] [RFC] Profile guided section layout
     http://lists.llvm.org/pipermail/llvm-dev/2017-June/114178.html

Pass `--call-graph-ordering-file <file>` to read a call graph profile where each
line has the format:

    <from symbol> <to symbol> <call count>

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

llvm-svn: 330234
2018-04-17 23:30:05 +00:00
Reid Kleckner 9c86a31307 Revert r329960 "Do not keep shared symbols created from garbage-collected eliminated DSOs."
This is causing large numbers of Chromium test executables to crash on
shutdown. The relevant symbol seems to be __cxa_finalize, which gets
removed from the dynamic symbol table for some of the support libraries.

llvm-svn: 330164
2018-04-16 22:45:23 +00:00
Rui Ueyama 039d248778 Do not keep shared symbols created from garbage-collected eliminated DSOs.
If all references to a DSO happen to be weak, and if the DSO is
specified with --as-needed, the DSO is not added to DT_NEEDED.
If that happens, we also need to eliminate shared symbols created
from the DSO. Otherwise, they become dangling references that point
to non-exsitent DSO.

Fixes https://bugs.llvm.org/show_bug.cgi?id=36991

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

llvm-svn: 329960
2018-04-12 21:57:04 +00:00
Rui Ueyama 1d92aa7380 Add --warn-backrefs to maintain compatibility with other linkers
I'm proposing a new command line flag, --warn-backrefs in this patch.
The flag and the feature proposed below don't exist in GNU linkers
nor the current lld.

--warn-backrefs is an option to detect reverse or cyclic dependencies
between static archives, and it can be used to keep your program
compatible with GNU linkers after you switch to lld. I'll explain the
feature and why you may find it useful below.

lld's symbol resolution semantics is more relaxed than traditional
Unix linkers. Therefore,

  ld.lld foo.a bar.o

succeeds even if bar.o contains an undefined symbol that have to be
resolved by some object file in foo.a. Traditional Unix linkers
don't allow this kind of backward reference, as they visit each
file only once from left to right in the command line while
resolving all undefined symbol at the moment of visiting.

In the above case, since there's no undefined symbol when a linker
visits foo.a, no files are pulled out from foo.a, and because the
linker forgets about foo.a after visiting, it can't resolve
undefined symbols that could have been resolved otherwise.

That lld accepts more relaxed form means (besides it makes more
sense) that you can accidentally write a command line or a build
file that works only with lld, even if you have a plan to
distribute it to wider users who may be using GNU linkers.  With
--check-library-dependency, you can detect a library order that
doesn't work with other Unix linkers.

The option is also useful to detect cyclic dependencies between
static archives. Again, lld accepts

  ld.lld foo.a bar.a

even if foo.a and bar.a depend on each other. With --warn-backrefs
it is handled as an error.

Here is how the option works. We assign a group ID to each file. A
file with a smaller group ID can pull out object files from an
archive file with an equal or greater group ID. Otherwise, it is a
reverse dependency and an error.

A file outside --{start,end}-group gets a fresh ID when
instantiated. All files within the same --{start,end}-group get the
same group ID. E.g.

  ld.lld A B --start-group C D --end-group E

A and B form group 0, C, D and their member object files form group
1, and E forms group 2. I think that you can see how this group
assignment rule simulates the traditional linker's semantics.

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

llvm-svn: 329636
2018-04-09 23:05:48 +00:00
Rumeet Dhindsa 682a417e51 Added support for LTO options: sample_profile, new_pass_manager and debug_pass_manager
Differential Revision: https://reviews.llvm.org/D45275

llvm-svn: 329598
2018-04-09 17:56:07 +00:00
George Rimar 4f98e0bc03 [ELF] - Revert r329060 "Simplify createFiles. NFCI."
Was requested during post commit review.

llvm-svn: 329155
2018-04-04 08:13:28 +00:00
Rui Ueyama cc013f62c1 Make fetchIfLazy only fetch an object file. NFC.
Previously, fetchIfLazy did more than the name says. Now, setting
to UsedInRegularObj is moved to another function.

llvm-svn: 329092
2018-04-03 18:01:18 +00:00
George Rimar 1ef746ba21 [ELF] - Eliminate Lazy class.
Patch removes Lazy class which
is just an excessive layer.

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

llvm-svn: 329086
2018-04-03 17:16:52 +00:00
George Rimar bfbeecdc5d [ELF] - Simplify createFiles. NFCI.
Groups paired options together.

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

llvm-svn: 329060
2018-04-03 12:06:29 +00:00
Rui Ueyama 5aab635e10 Improve error message for an unknown --plugin-opt.
Before:

  $ ld.lld --plugin-opt=-foo
  ld.lld: --Unknown command line argument '-abc'

After:

  $ ld.lld --plugin-opt=-foo
  ld.lld: --plugin-opt: ld.lld --Unknown command line argument '-abc'

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

llvm-svn: 328880
2018-03-30 17:22:44 +00:00
Rui Ueyama 5a67a6ec4a Re-implement --just-symbols as a regular object file.
I tried a few different designs to find a way to implement it without
too much hassle and settled down with this. Unlike before, object files
given as arguments for --just-symbols are handled as object files, with
an exception that their section tables are handled as if they were all
null.

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

llvm-svn: 328852
2018-03-30 01:15:36 +00:00
Rui Ueyama db46a62e2b Implement --cref.
This is an option to print out a table of symbols and filenames.
The output format of this option is the same as GNU, so that it can be
processed by the same scripts as before after migrating from GNU to lld.

This option is mildly useful; we can live without it. But it is pretty
convenient sometimes, and it can be implemented in 50 lines of code, so
I think lld should support this option.

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

llvm-svn: 327565
2018-03-14 20:29:45 +00:00
Fangrui Song 17208f1ef9 [ELF] Add elf64lppc emulation.
Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 327177
2018-03-09 22:11:46 +00:00
George Rimar 9e2c8a9db1 [ELF] - Support "INSERT AFTER" statement.
This implements INSERT AFTER in a following way:

During reading scripts it collects all insert statements.
After we done and read all files it inserts statements into script commands list.

With that:
* Rest of code does know nothing about INSERT.
* Approach is straightforward and have no visible limitations.
* It is also easy to support INSERT BEFORE (was seen in clang code once).
* Should work for PR35877 and similar cases.

Cons:
* It assumes we have "main" scripts that describes sections.

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

llvm-svn: 327003
2018-03-08 14:54:38 +00:00
Rui Ueyama 09fcd4c34c Implement --just-symbols.
Differential Revision: https://reviews.llvm.org/D39348

llvm-svn: 326835
2018-03-06 21:25:37 +00:00
Rui Ueyama 036ed36f0a Accept both `--foo bar` and `--foo=bar` styles options.
GNU linkers by convention supports both `--foo bar` and `--foo=bar` styles
for all long options that take arguments.

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

llvm-svn: 326506
2018-03-01 23:06:10 +00:00
Rafael Espindola 2e4bcb0095 Don't ingoned --enable-new-dtags.
llvm-svn: 326498
2018-03-01 22:23:51 +00:00
Rui Ueyama ee17371897 Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.
This should resolve the issue that lld build fails in some hosts
that uses case-insensitive file system.

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

llvm-svn: 326339
2018-02-28 17:38:19 +00:00
Rafael Espindola 3f4c673d38 Put undefined symbols from shared libraries in the symbol table.
With the recent fixes these symbols have more in common than not with
regular undefined symbols.

llvm-svn: 326242
2018-02-27 20:31:22 +00:00
Igor Kudrin 3345c9ac18 [ELF] Create and export symbols provided by a linker script if they referenced by DSOs.
It should be possible to resolve undefined symbols in dynamic libraries
using symbols defined in a linker script.

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

llvm-svn: 326176
2018-02-27 07:18:07 +00:00
Simon Dardis cd8758233e [mips][lld] Spectre variant two mitigation for MIPSR2
This patch provides migitation for CVE-2017-5715, Spectre variant two,
which affects the P5600 and P6600. It implements the LLD part of
-z hazardplt. Like the Clang part of this patch, I have opted for that
specific option name in case alternative migitation methods are required
in the future.

The mitigation strategy suggested by MIPS for these processors is to use
hazard barrier instructions. 'jalr.hb' and 'jr.hb' are hazard
barrier variants of the 'jalr' and 'jr' instructions respectively.

These instructions impede the execution of instruction stream until
architecturally defined hazards (changes to the instruction stream,
privileged registers which may affect execution) are cleared. These
instructions in MIPS' designs are not speculated past.

These instructions are defined by the MIPS32R2 ISA, so this mitigation
method is not compatible with processors which implement an earlier
revision of the MIPS ISA.

For LLD, this changes PLT stubs to use 'jalr.hb' and 'jr.hb'.

Reviewers: atanasyan, ruiu

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

llvm-svn: 325647
2018-02-20 23:49:17 +00:00
Sam Clegg f187c4d2e5 Consistent use of header file for ICF and MarkLive
Previously wasm used a separate header to declare markLive
and ELF used to declare ICF.  This change makes each backend
consistently declare these in their own headers.

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

llvm-svn: 325631
2018-02-20 22:09:59 +00:00
Rui Ueyama 7c9ad29304 Remove "--full-shutdown" and instead use an environment variable LLD_IN_TEST.
We are running lld tests with "--full-shutdown" option because we don't
want to call _exit() in lld if it is running tests. Regular shutdown
is needed for leak sanitizer.

This patch changes the way how we tell lld that it is running tests.
Now "--full-shutdown" is removed, and LLD_IN_TEST environment variable
is used instead.

This patch enables full shutdown on all ports, e.g. ELF, COFF and wasm.
Previously, we enabled it only for ELF.

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

llvm-svn: 325413
2018-02-16 23:41:48 +00:00
Peter Collingbourne 09e04af42f ELF: Stop collecting a list of symbols in ArchiveFile.
There seems to be no reason to collect this list of symbols.

Also fix a bug where --exclude-libs would apply to all symbols that
appear in an archive's symbol table, even if the relevant archive
member was not added to the link.

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

llvm-svn: 325380
2018-02-16 20:23:54 +00:00
Alexander Richardson cfb6093379 Ensure that Elf_Rel addends are always written for dynamic relocations
Summary:
This follows up on r321889 where writing of Elf_Rel addends was partially
moved to RelocationBaseSection. This patch ensures that the addends are
always written to the output section when a input section uses RELA but the
output is REL.

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

llvm-svn: 325328
2018-02-16 10:01:17 +00:00
Igor Kudrin 943f62d9d7 [ELF] Fix use after free in case of using --whole-archive.
Differential Revision: https://reviews.llvm.org/D34554

llvm-svn: 325313
2018-02-16 03:26:53 +00:00
Rui Ueyama 44a8471227 Fix an issue that lld drops symbol versions for -r.
When we are emitting a relocatable output, we should keep the original
symbol name including "@" part. Previously, we drop that part unconditionally
which resulted in dropping versions from symbols.

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

llvm-svn: 325204
2018-02-15 02:40:58 +00:00
Rui Ueyama 5e52022af6 Make --export-dynamic-symbol to add undefined symbols even if --export-dynamic is given.
This patch addresses a minor compatibility issue with GNU linkers.
Previously, --export-dynamic-symbol is completely ignored if you
pass --export-dynamic together.

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

llvm-svn: 325152
2018-02-14 18:38:33 +00:00
James Henderson de300e66bb [ELF] Add warnings for various symbols that cannot be ordered
There are a number of different situations when symbols are requested
to be ordered in the --symbol-ordering-file that cannot be ordered for
some reason. To assist with identifying these symbols, and either
tidying up the order file, or the inputs, a number of warnings have
been added. As some users may find these warnings unhelpful, due to how
they use the symbol ordering file, a switch has also been added to
disable these warnings.

The cases where we now warn are:

 * Entries in the order file that don't correspond to any symbol in the input
 * Undefined symbols
 * Absolute symbols
 * Symbols imported from shared objects
 * Symbols that are discarded, due to e.g. --gc-sections or /DISCARD/ linker script sections
 * Multiple of the same entry in the order file

Reviewed by: rafael, ruiu

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

llvm-svn: 325125
2018-02-14 13:36:22 +00:00