Commit Graph

1535 Commits

Author SHA1 Message Date
Rui Ueyama f43d15009c Fix comments.
The original comments were separated by new code that is irrelevant to
the comment. This patch moves the comment to the right place and update it.

llvm-svn: 264816
2016-03-30 00:43:49 +00:00
Davide Italiano 49fe4eda4c [LTO] Add a comment to explain how we handle @llvm.used.
Requested by: Rui Ueyama.

llvm-svn: 264809
2016-03-29 23:57:22 +00:00
Rafael Espindola 163974dd33 Simplify AHL handling.
This simplifies a few things

* Read the value as early as possible, instead of passing a pointer to
  the location.
* Print the warning for missing pair close to where we find out it is
  missing.
* Don't pass the value to relocateOne.

llvm-svn: 264802
2016-03-29 23:05:59 +00:00
Davide Italiano 47c33f0387 [ELF] Drive-by cleanup, make LTO.cpp clang-format clean.
llvm-svn: 264791
2016-03-29 21:48:25 +00:00
Davide Italiano 86f2bd5ca1 [LTO] Teach LTO about @llvm.used global.
If a symbol appears in @llvm.used, the linker is forced to treat
the symbol as there's a reference to it.

llvm-svn: 264790
2016-03-29 21:46:35 +00:00
Rui Ueyama 319d7304c3 Simplify. NFC.
llvm-svn: 264785
2016-03-29 20:53:21 +00:00
Rui Ueyama 4e62db4167 Replace a FIXME with a regular comment.
Because it doesn't have to be fixed even though it is probably
better to do.

llvm-svn: 264772
2016-03-29 19:19:03 +00:00
Rui Ueyama 01ddc06484 Make BitcodeCompiler::compile a non-template function. NFC.
llvm-svn: 264770
2016-03-29 19:08:46 +00:00
Rafael Espindola cba3e8b4b5 Change how we handle R_MIPS_LO16.
Mips aligns PT_LOAD to 16 bits (0x10000). That means that the lower 16
bits are always the same, so we can, effectively, say that the
relocation is relative.

llvm-svn: 264761
2016-03-29 18:18:19 +00:00
Simon Atanasyan d2980d3e20 [ELF][MIPS] Reduce number of redundant entries in the local part of MIPS GOT
Local symbol which requires GOT entry initialized by "page" address.
This address is high 16 bits of sum of the symbol value and the relocation
addend. In the relocation scanning phase final values of symbols are unknown
so to reduce number of allocated GOT entries do the following trick. Save
all output sections referenced by GOT relocations during the relocation
scanning phase. Then later in the `GotSection::finalize` method calculate
number of "pages" required to cover all saved output sections and allocate
appropriate number of GOT entries. We assume the worst case - each 64kb
page of the output section has at least one GOT relocation against it.

Differential Revision: http://reviews.llvm.org/D18349

llvm-svn: 264730
2016-03-29 14:07:22 +00:00
George Rimar 1e4b39f184 [ELF, PR27091] - Implemented -t/--trace option
-t/--trace
Print the names of the input files as ld processes them.
This fixes https://llvm.org/bugs/show_bug.cgi?id=27091.

Differential revision: http://reviews.llvm.org/D18517

llvm-svn: 264708
2016-03-29 08:45:40 +00:00
George Rimar 86971050cb [ELF] - Error out when R_X86_64_PC32/R_X86_64_32 are used against preemptible symbol when linking shared object.
When R_X86_64_PC32/R_X86_64_32 relocations are
used against preemptible symbol and output is position independent,
error should be generated.

Differential revision: http://reviews.llvm.org/D18190

llvm-svn: 264707
2016-03-29 08:35:42 +00:00
Davide Italiano 3acdfeee11 [LTO] Don't internalize if --export-dynamic is passed.
We treat that in the same way we treat shared libraries.

llvm-svn: 264698
2016-03-29 04:34:09 +00:00
Davide Italiano f6523aecd7 Revert r264961. I didn't have asserts enable when testing.
llvm-svn: 264692
2016-03-29 02:20:10 +00:00
Davide Italiano a50e0b97f1 [LTO] Include bitcode symbol name in unreachable messages.
llvm-svn: 264691
2016-03-29 01:40:07 +00:00
Davide Italiano 04d6aa2b38 [LTO] Include in .symtab/.dynsym symbols introduced by optimizations.
Some optimizations, e.g. SimplifyLibCalls, can replace functions with
others as part of the lowering, e.g. printf => puts.
The new symbols don't have the isUsedInRegularObj flag set so they
don't get included in the final symbol table (and dynamic symbol
table), and the dynamic linker gets confused. Include  them as a fix.

Differential Revision: http://reviews.llvm.org/D18357

llvm-svn: 264688
2016-03-29 00:15:52 +00:00
Davide Italiano 828ac541ef [LTO] Internalize symbols.
IPO doesn't work very well across symbols referenced
by others TUs. The linker here tries to evaluate
which symbols are safe to internalize and switches
their linkage.

Differential Revision:  http://reviews.llvm.org/D18415

llvm-svn: 264585
2016-03-28 15:44:21 +00:00
Rafael Espindola 0727553405 R_AARCH64_PREL64 is relative.
llvm-svn: 264560
2016-03-28 01:31:11 +00:00
Davide Italiano 1460e9f1ca [ELF/LTO] Refactor to reduce indentation.
Suggested by: Rui Ueyama.

llvm-svn: 264518
2016-03-26 18:33:09 +00:00
Reid Kleckner 20e24193f3 Remove declaration of SymbolTable::codegen, this method was deleted in r264091
llvm-svn: 264441
2016-03-25 18:20:33 +00:00
Adhemerval Zanella 3db3f6d83a Simplify AArch64 isRelRelative
This patch simplifies the isRelRelative for AArch64 and add the missing
ones for bootstrap and test-suite.  It also adds more testing for
shared object creation.

llvm-svn: 264322
2016-03-24 19:12:14 +00:00
Rafael Espindola 5432287bad Make needsPlt a plain function instead of a template.
llvm-svn: 264267
2016-03-24 12:55:27 +00:00
Rafael Espindola 88a9d7608f Mark R_AARCH64_CONDBR19 as relative.
llvm-svn: 264262
2016-03-24 12:16:46 +00:00
Rui Ueyama 961f2ff21e ELF: Split BitcodeCompiler::compile.
http://reviews.llvm.org/D18410

llvm-svn: 264193
2016-03-23 21:19:27 +00:00
Davide Italiano bcd660a908 [LTO] Keep linkonce symbols when required.
Similarly to how we do with linkonce_odr symbols already, but
change their linkage to weak.

llvm-svn: 264181
2016-03-23 18:41:48 +00:00
Davide Italiano f20a55fcfd [LTO] Only change linkage if we keep the symbol.
llvm-svn: 264171
2016-03-23 17:59:07 +00:00
Rafael Espindola ffcad441fd Not every x86 relocation is relative.
Without this predicate we were not producing R_386_RELATIVE relocations.

llvm-svn: 264160
2016-03-23 14:58:25 +00:00
Simon Atanasyan bea20c3502 [ELF][MIPS] Add comment with MIPS GOT relocations handling description. NFC.
llvm-svn: 264145
2016-03-23 09:28:02 +00:00
Davide Italiano 7cd8e65187 [LTO] Remove dead code.
llvm-svn: 264133
2016-03-23 02:45:53 +00:00
Davide Italiano d4c2a03c32 [LTO] Keep linkonce_odr symbols when appropriate.
Ensure we keep the symbol we need to before it reaches
the Writer (and hit an assertion), changing its linkage
from linkonce_odr to weak. For a more detailed description
of the problem, see PR19901 where a similar problem was
fixed for the gold plugin. Thanks to Rafael for providing
a testcase.

llvm-svn: 264111
2016-03-22 22:31:34 +00:00
Sean Silva e32368fc6e Mark SymbolBody::getSymbol as `const`.
llvm-svn: 264094
2016-03-22 21:04:03 +00:00
Rui Ueyama 259924869b ELF: Create LTO.{cpp,h} and move LTO-related code to that file.
The code for LTO has been growing, so now is probably a good time to
move it to its own file. SymbolTable.cpp is for symbol table, and
because compiling bitcode files are semantically not a part of
symbol table, this is I think a good thing to do.

http://reviews.llvm.org/D18370

llvm-svn: 264091
2016-03-22 20:52:10 +00:00
Sean Silva 3baa23b50c [lto] Provide a file name for the combined LTO object.
Otherwise, we get diagnostics like:

    undefined symbol: foo in

Which isn't particularly useful.

llvm-svn: 264089
2016-03-22 20:25:32 +00:00
Rafael Espindola 26d239c293 Skip some relocations in scanRelocs.
When a tls access is optimized, a group of relocations is converted at a
time.

We were already skipping relocations that were optimized out in
relocate, but not in scanRelocs.

This is a small optimization. I got here while working on a patch that
will always keep scanRelocs and relocate in sync.

llvm-svn: 264048
2016-03-22 13:24:29 +00:00
George Rimar 9f8f4e3944 [ELF] - Process R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX relocations.
R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX relocations were added in latest ABI:
https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf

They should be generated instead of R_X86_64_GOTPCREL for cases 
when relaxation is possible. Currently this patch just process them in the 
same way like R_X86_64_GOTPCREL. That should work for now
and we can implement relaxations later.

There is no testcases provided as I think there is no way to generate
such relocations using llvm-mc atm.

Differential revision: http://reviews.llvm.org/D18301

llvm-svn: 264043
2016-03-22 12:15:26 +00:00
Simon Atanasyan f3ec3be178 [ELF][MIPS] Delete GotSection::addMipsLocalEntry method
Now local symbols have SymbolBody so we can handle all kind of symbols
in the GotSection::addEntry method. The patch moves the code from
addMipsLocalEntry to addEntry. NFC.

Differential Revision: http://reviews.llvm.org/D18302

llvm-svn: 264032
2016-03-22 08:36:48 +00:00
Davide Italiano 901de03fe2 [ELF] Simplify code a bit. No functional change.
llvm-svn: 263999
2016-03-21 22:44:24 +00:00
Rafael Espindola 0d2ad420df Revert "[ELF] SHF_MERGE section with 0 entsize is not fatal"
This reverts commit r263664.

The reason we were getting broken files was lld -r, and that has been
fixed.

llvm-svn: 263944
2016-03-21 14:57:20 +00:00
George Rimar 4f1dae295f [ELF] - ignore the -rpath-link option
Just ignore the -rpath-link command line
option in the same way like gold do.

Behavior of lld/gold differs from gnu ld here.
GNU ld tries to resolve undefined symbols in all
shared object files at link time.

Differential revision: http://reviews.llvm.org/D18269

llvm-svn: 263876
2016-03-19 11:15:54 +00:00
Davide Italiano 67e03a1ce6 [LTO] Ignore -plugin/-plugin-opt options.
This is required to get 'clang -flto' to work transparently
with lld. Please refer to the short comment in the code
for a more detailed explanation.

llvm-svn: 263862
2016-03-19 00:40:09 +00:00
Davide Italiano ac8737ac60 [ELF] Refactor run of LTO passes into an helper. NFC.
Requested by: Rui Ueyama.

llvm-svn: 263851
2016-03-18 23:22:40 +00:00
Rafael Espindola 69082f051d Revert "bar"
This reverts commit r263799.
It was a mistake. Sorry about that.

llvm-svn: 263801
2016-03-18 18:11:26 +00:00
Rafael Espindola 2f055f9881 The ELF lld doesn't depend on LTO.
Tested with a shared build.

llvm-svn: 263800
2016-03-18 18:09:35 +00:00
Rafael Espindola c2cfd9fa34 bar
llvm-svn: 263799
2016-03-18 18:09:32 +00:00
Jan Vesely 3ac9501c3f [ELF] Link with Analysis, IPO, and LTO
Fixes SHARED_LIB build broken by r263761

llvm-svn: 263796
2016-03-18 17:12:31 +00:00
George Rimar 0baa1d3dbe [ELF] - Set the sh_entsize for mergable sections
Previously sh_entsize field was not set for MergeOutputSection.
Patch fixes that.

That should resolve the https://llvm.org/bugs/show_bug.cgi?id=26975

Differential revision: http://reviews.llvm.org/D18248

llvm-svn: 263780
2016-03-18 09:28:39 +00:00
Rafael Espindola 8381c565c3 Make evaluation order explicit.
llvm-svn: 263762
2016-03-17 23:36:19 +00:00
Davide Italiano c20c061749 [LTO] Call the optimizer before invoking codegen.
This is the required plumbing needed to run the LTO passes.

Differential Revision:  http://reviews.llvm.org/D18235

llvm-svn: 263761
2016-03-17 23:35:34 +00:00
Simon Atanasyan a8e9cb38ae [ELF][MIPS] Support R_MIPS_TLS_DTPREL_HI16/LO16 and R_MIPS_TLS_TPREL_HI16/LO16 relocations
That is initial and the most trivial patch to support TLS for MIPS targets.

llvm-svn: 263712
2016-03-17 12:36:08 +00:00
George Rimar 177f7bcee8 Avoid using braces. NFC.
llvm-svn: 263707
2016-03-17 11:00:27 +00:00
George Rimar 786e866fea [ELF] - -pie/--pic-executable option implemented
-pie
--pic-executable

Create a position independent executable.  This is currently only
 supported on ELF platforms.  Position independent executables are
 similar to shared libraries in that they are relocated by the
 dynamic linker to the virtual address the OS chooses for them
 (which can vary between invocations).  Like normal dynamically
 linked executables they can be executed and symbols defined in the
 executable cannot be overridden by shared libraries.

Differential revision: http://reviews.llvm.org/D18183

llvm-svn: 263693
2016-03-17 05:57:33 +00:00
Davide Italiano 1568868044 [ELF] Use braces for muti-line if(s).
Reported by: Joerg Sonnenberg.

llvm-svn: 263690
2016-03-17 04:28:41 +00:00
Rafael Espindola 54bf9e1ca5 Don't pass SymbolBody to the relax* functions.
We already pass the symbol value.

llvm-svn: 263670
2016-03-16 23:01:56 +00:00
Rafael Espindola 48b9102a7a Don't create a got entry if we optimize it out.
llvm-svn: 263669
2016-03-16 22:43:36 +00:00
Ed Maste b321050a93 [ELF] SHF_MERGE section with 0 entsize is not fatal
For now just treat such sections as non-mergeable.

Resubmit r263660 with test fix.

Differential Revision:     http://reviews.llvm.org/D18225

llvm-svn: 263664
2016-03-16 21:12:53 +00:00
Ed Maste b30ce583df Revert r263660 as one of the tests is broken.
llvm-svn: 263661
2016-03-16 20:42:27 +00:00
Ed Maste 2e97115a61 [ELF] SHF_MERGE section with 0 entsize is not fatal
For now just treat such sections as non-mergeable.

Differential Revision:	http://reviews.llvm.org/D18222

llvm-svn: 263660
2016-03-16 20:32:32 +00:00
Rafael Espindola 89cc14fd46 Split relaxTls into one per relaxation type.
This reduces code duplication in each target.

llvm-svn: 263653
2016-03-16 19:03:58 +00:00
Davide Italiano 00a7cf9ffe [ELF] Ignore _GLOBAL_OFFSET_TABLE_ symbol in shared libs.
This fixes PR26705.

Differential Revision:  http://reviews.llvm.org/D18166

llvm-svn: 263594
2016-03-15 22:24:58 +00:00
Rui Ueyama 15fa035477 ELF: Fix use-after-free problem.
Fixes pr26908. This patch is based on Filipe Cabecinhas'
patch (http://reviews.llvm.org/D18167)

http://reviews.llvm.org/D18169

llvm-svn: 263569
2016-03-15 18:20:50 +00:00
George Rimar ca1d1fb2d6 Error/warning/log messages should start with lowercase letters.
llvm-svn: 263549
2016-03-15 14:00:22 +00:00
Rui Ueyama 9328b2cdde Use ELFT instead of ELFFile<ELFT>.
llvm-svn: 263510
2016-03-14 23:16:09 +00:00
Rui Ueyama f50e1d8358 Make getAlignment a non-member function. NFC.
This function did not rely on Writer class.

llvm-svn: 263502
2016-03-14 22:41:08 +00:00
Rui Ueyama 64bd8df458 Error messages should start with lowercase letters.
llvm-svn: 263496
2016-03-14 21:31:07 +00:00
Rui Ueyama 71a8686244 Revert r263366: Cosmetic change to reduce repetitions. NFC.
This reverts commit r263366 because it caused link errors in some linkers.

llvm-svn: 263471
2016-03-14 19:37:58 +00:00
George Rimar cbcda9e077 Remove dead code. NFC.
llvm-svn: 263433
2016-03-14 14:25:28 +00:00
George Rimar 343580097d [ELF] implement --warn-common/--no-warn-common
-warn-common
Warn when a common symbol is combined with another common symbol
or with a symbol definition.  Unix linkers allow  this  somewhat
sloppy  practice, but linkers on some other operating systems do
not.  This option allows you to  find  potential  problems  from
combining global symbols.

Differential revision: http://reviews.llvm.org/D17998

llvm-svn: 263413
2016-03-14 09:19:30 +00:00
Rui Ueyama 5bc2acd052 Print out newline in both cases.
llvm-svn: 263401
2016-03-13 23:07:42 +00:00
Rui Ueyama cc232d1f90 Simplify. NFC.
llvm-svn: 263398
2016-03-13 22:08:11 +00:00
Rui Ueyama 368e1eaa51 Remove uint32_X type.
This type is equivalent to Elf_Word type.

llvm-svn: 263397
2016-03-13 22:02:04 +00:00
Rui Ueyama e270c0a19a ELF: Split initializeSections and add comments.
llvm-svn: 263395
2016-03-13 21:52:57 +00:00
Rui Ueyama 2df72898c8 Remove `else` after `return`.
llvm-svn: 263392
2016-03-13 20:54:38 +00:00
Rui Ueyama 54945f692b Simplify. NFC.
llvm-svn: 263391
2016-03-13 20:34:34 +00:00
Rui Ueyama a0752a5b25 Remove unused #include.
llvm-svn: 263390
2016-03-13 20:28:29 +00:00
Rui Ueyama 98a4b8b05c Remove a local variable. NFC.
llvm-svn: 263389
2016-03-13 20:18:12 +00:00
Simon Atanasyan 0295bb42c0 [ELF][MIPS] Use TargetInfo::needsGot call to check necessity of GOT for local symbols. NFC.
llvm-svn: 263388
2016-03-13 20:13:24 +00:00
Rui Ueyama 6c5638b01a ELF: Add `Rela` member variable to Config.
The member is true if we want to create relocatin sections with RELA
instead of REL.

llvm-svn: 263387
2016-03-13 20:10:20 +00:00
Rui Ueyama c4466605d8 ELF: Redefine canBeDefined as a member function of SymbolBody.
We want to make SymbolBody the central place to query symbol information.
This patch also renames canBePreempted to isPreemptible because I feel that
the latter is slightly better (the former is three words and the latter
is two words.)

llvm-svn: 263386
2016-03-13 19:48:18 +00:00
Rui Ueyama 22b5d1f901 ELF: Set e_flags header only when MIPS.
The field is zero by default, so this is NFC.

llvm-svn: 263385
2016-03-13 19:29:17 +00:00
Simon Atanasyan d27e61c591 [ELF][MIPS] Add elf namespace name to the ObjectFile.
NFC. Follow-up to r263381.

llvm-svn: 263382
2016-03-13 15:48:41 +00:00
Simon Atanasyan 604aee134a [ELF][MIPS] Factor out SumVA adjustments into a couple of separate functions. NFC.
The patch does not reduce the size of the code but makes
InputSectionBase::relocate cleaner a bit.

Differential Revision: http://reviews.llvm.org/D18119

llvm-svn: 263381
2016-03-13 15:37:38 +00:00
Rui Ueyama 1e720b9c0c Cosmetic change. NFC.
llvm-svn: 263376
2016-03-13 06:50:34 +00:00
Rui Ueyama c63c1dbd6a Move an OutputSectionBase member function to the top.
llvm-svn: 263375
2016-03-13 06:50:33 +00:00
Rui Ueyama 614be59692 Simplify. NFC.
llvm-svn: 263373
2016-03-13 05:23:40 +00:00
Rui Ueyama fc467e77b8 Use RelTy instead of Elf_Rel_Impl<ELFT, isRela> for readability.
llvm-svn: 263368
2016-03-13 05:06:50 +00:00
Rui Ueyama a777e01f02 Cosmetic change to reduce repetitions. NFC.
llvm-svn: 263366
2016-03-13 04:40:17 +00:00
Rui Ueyama 7ede54310a Redefine isGnuIfunc as a member function of SymbolBody.
llvm-svn: 263365
2016-03-13 04:40:14 +00:00
Rui Ueyama cb8fd3ac68 Body can never be null in this context.
Because of the recent commit to allocate SymbolBodies for local symbols.

llvm-svn: 263364
2016-03-13 04:40:12 +00:00
Rui Ueyama 860b13fc02 Remove dead code.
llvm-svn: 263363
2016-03-13 04:25:43 +00:00
Rui Ueyama 6eafa7fb23 Do not return a bool value from error().
error returned true if there was an error. This allows us to replace
the code like this

  if (EC) {
    error(EC, "something failed");
    return;
  }

with

  if (error(EC, "something failed"))
    return;

I thought that that was a good idea, but it turned out that we only
have two places to use this pattern. So this patch removes that feature.

llvm-svn: 263362
2016-03-13 04:25:41 +00:00
Rui Ueyama b30f73568f The difference of getBss() and Out<ELFT>::Bss is subtle, so remove that function.
llvm-svn: 263361
2016-03-13 04:11:53 +00:00
Rui Ueyama a969218f91 Split addCopyRelSymbols. NFC.
llvm-svn: 263360
2016-03-13 04:05:42 +00:00
Rui Ueyama 84be8c5219 Remove redundant check.
The control reaches here only when linking MIPS binaries.

llvm-svn: 263359
2016-03-13 03:43:32 +00:00
Rui Ueyama 3ed2f06913 Fix spelling.
llvm-svn: 263358
2016-03-13 03:17:44 +00:00
Rui Ueyama 7f4a492f98 "Windows" is a product name, so it should be spelled correctly.
llvm-svn: 263357
2016-03-13 03:17:42 +00:00
Rui Ueyama 2039847062 Simplify findMipsPairedReloc function signature. NFC.
llvm-svn: 263356
2016-03-13 03:09:40 +00:00
Rui Ueyama 28286cdfc7 ELF: Include the build ID section in the first page.
At least Linux has the kernel configuration to include the first page
of the executable into core files. We want build ID section to be
included in core files to identify them.

Here is the link to the description about the kernel configuration.

097f70b3c4/fs/Kconfig.binfmt (L46)

llvm-svn: 263351
2016-03-13 01:54:48 +00:00
Simon Atanasyan 92a32559fd [ELF][MIPS] Put type of symbol (local/global) to the findMipsPairedReloc and call it from the single place. NFC.
llvm-svn: 263339
2016-03-12 11:58:15 +00:00
George Rimar 777f96304e Recommit of r263252, [ELF] - Change all messages to lowercase to be consistent.
which was reverted because included
unrelative changes by mistake.

Original commit message:

[ELF] - Change all messages to lowercase to be consistent.

That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

Differential revision: http://reviews.llvm.org/D18085

llvm-svn: 263337
2016-03-12 08:31:34 +00:00
Rui Ueyama 02aa766897 Update the documents of the new LLD.
This patch merges the documents for ELF and COFF into one
and puts it into docs directory.

llvm-svn: 263336
2016-03-12 06:06:40 +00:00
Rui Ueyama 634ddf0bec ELF: Implement --build-id.
This patch implements --build-id. After the linker creates an output file
in the memory buffer, it computes the FNV1 hash of the resulting file
and set the hash to the .note section as a build-id.

GNU ld and gold have the same feature, but their default choice of the
hash function is different. Their default is SHA1.

We made a deliberate choice to not use a secure hash function for the
sake of performance. Computing a secure hash is slow -- for example,
MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that.

As a result, if you pass --build-id to gold, then the linker becomes about
10% slower than that without the option. We observed a similar degradation
in an experimental implementation of build-id for LLD. On the other hand,
we observed only 1-2% performance degradation with the FNV hash.

Since build-id is not for digital certificate or anything, we think that
a very small probability of collision is acceptable.

We considered using other signals such as using input file timestamps as
inputs to a secure hash function. But such signals would have an issue
with build reproducibility (if you build a binary from the same source
tree using the same toolchain, the build id should become the same.)

GNU linkers accepts --build-id=<style> option where style is one of
"MD5", "SHA1", or an arbitrary hex string. That option is out of scope
of this patch.

http://reviews.llvm.org/D18091

llvm-svn: 263292
2016-03-11 20:51:53 +00:00
Rui Ueyama ebce18b6fc Remove obsolete comment.
llvm-svn: 263280
2016-03-11 19:04:56 +00:00
Rui Ueyama 6b074f5c9f Fix MSVC build.
llvm-svn: 263277
2016-03-11 18:56:05 +00:00
Rui Ueyama f714955402 Revert r263252: "[ELF] - Change all messages to lowercase to be consistent."
This reverts commit r263252 because the change contained unrelated changes.

llvm-svn: 263272
2016-03-11 18:46:51 +00:00
Rafael Espindola 2230483812 Now that it is trivial, fix pr26878.
llvm-svn: 263271
2016-03-11 18:33:48 +00:00
Rafael Espindola 7862097a45 Yet more MSVC fixes.
llvm-svn: 263253
2016-03-11 16:41:23 +00:00
George Rimar 96bcdae1a5 [ELF] - Change all messages to lowercase to be consistent.
That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

Differential revision: http://reviews.llvm.org/D18085

llvm-svn: 263252
2016-03-11 16:40:55 +00:00
Rafael Espindola 36a73d2deb More MSVC fixes.
llvm-svn: 263251
2016-03-11 16:32:46 +00:00
Rafael Espindola b20dcb1483 Trying to fix the MSVC build.
llvm-svn: 263249
2016-03-11 16:23:45 +00:00
Rafael Espindola 9b3acf9098 Avoid calling getNamedValue.
In lld we usually avoid hash lookups. In addition to that, IR names are
not fully mangled, so it is best to avoid using them whenever possible.

llvm-svn: 263248
2016-03-11 16:11:47 +00:00
Rafael Espindola 5d57fb823b Don't invent names for STT_SECTION symbols.
We should just copy the symbol names with -r.

llvm-svn: 263244
2016-03-11 14:57:33 +00:00
George Rimar 5761042db7 This reverts the r263125
It was discussed to make all messages be 
lowercase to be consistent with clang.
(also reverts the r263128 which fixed 
build bot fail after r263125)

Original commit message:
[ELF] - Consistent spelling for error/warning messages

Previously error and warnings were not consistent in lld.
Some of them started from lowercase letter, others from
uppercase. Also there was one or two which had a dot at the end.
This patch changes all messages to start from uppercase letter if
they were not before.

Differential revision: http://reviews.llvm.org/D18045

llvm-svn: 263240
2016-03-11 14:43:02 +00:00
Rafael Espindola 1f5b70f64f Represent local symbols with DefinedRegular.
llvm-svn: 263237
2016-03-11 14:21:37 +00:00
Simon Atanasyan 019049fca9 [ELF][MIPS] Update comment about creation local GOT entries for non-local symbols. NFC.
llvm-svn: 263236
2016-03-11 13:57:53 +00:00
Rafael Espindola 4e90611ed2 Remove a redundant cast.
llvm-svn: 263230
2016-03-11 13:17:15 +00:00
Rafael Espindola 38e5d4e73a Simplify now that local symbols can use getVA.
It is really odd that Mips differentiates symbols that are born local
and those that become local because of hidden visibility. I don't know
enough mips to known if this is a bug or not.

llvm-svn: 263228
2016-03-11 13:04:28 +00:00
George Rimar a4ab97d89c [ELF] - Early continue in InputSectionBase<ELFT>::relocate(). NFC.
llvm-svn: 263227
2016-03-11 12:57:52 +00:00
George Rimar 1d9738c2d1 [ELF] - Evaluate addend earlier and use it instead getAddend() calls. NFC.
llvm-svn: 263226
2016-03-11 12:53:17 +00:00
Rafael Espindola 87d9f10733 Compute value of local symbol with getVA.
llvm-svn: 263225
2016-03-11 12:19:05 +00:00
Rafael Espindola ccb8b4d4fe Remember the input section of locals.
This is already a simplification, but will allow much more.

llvm-svn: 263224
2016-03-11 12:14:02 +00:00
Rafael Espindola 67d72c02bc Create a SymbolBody for locals.
pr26878 shows a case where locals have to be in the got.

llvm-svn: 263222
2016-03-11 12:06:30 +00:00
George Rimar 56e0d53e92 [ELF] - Move initSymbols() to Driver.cpp. NFC.
That is followup for http://reviews.llvm.org/D18047
patch. initSymbols() moved to Driver.cpp and made static.

llvm-svn: 263214
2016-03-11 10:07:18 +00:00
Ismail Donmez 0ca63ab544 Fix linux build after r263190
llvm-svn: 263213
2016-03-11 09:55:06 +00:00
Sean Silva 905d349c47 Fix indentation.
Somehow this slipped by in r263197. Thanks to Rui for noticing.

llvm-svn: 263198
2016-03-11 05:48:04 +00:00
Sean Silva 4a0ff22d51 [lto] The previous testcase was not useful enough.
-shared was hiding the fact that the intrinsic wasn't being found.

llvm-svn: 263197
2016-03-11 05:42:34 +00:00
Rui Ueyama e98095026f ELF: Add --thread option and partially parallelize writeTo().
This patch adds --thread option and use parallel_for_each to write
sections in regular OutputSections.

This is the first patch to use more than one threads.

Note that --thread is off by default because it is experimental.
At this moment I still want to focus on single thread performance
because multi-threading is not a magic wand to fix performance
problems after all. It is generally very hard to make a slow program
faster by threads. Therefore, I want to make the linker as efficient
as possible first and then look for opportunity to make it even faster
using more than one core.

Here are some numbers to link programs with and without --threads
and using GNU gold. Numbers are in seconds.

Clang
  w/o --threads 0.697
  w --threads   0.528
  gold          1.643

Scylla
  w/o --threads 5.032
  w --threads   4.935
  gold          6.791

GNU gold
  w/o --threads 0.550
  w --threads   0.551
  gold          0.737

I limited the number of cores these processes can use to 4 using
perf command, so although my machine has 20 physical cores, the
performance gain I observed should be reproducible with a machine
which is not as beefy as mine.

llvm-svn: 263190
2016-03-11 04:23:12 +00:00
Sean Silva b1b5cc83f1 [lto] Make sure that ctors are added to the combined module.
Summary:
More generally, appending linkage is a special case that we don't want
to create a SymbolBody for.

Reviewers: rafael, ruiu

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D18012

llvm-svn: 263179
2016-03-11 00:50:05 +00:00
Rafael Espindola f3314b2e4f Move getLocalRelTarget to the file where it is used.
llvm-svn: 263152
2016-03-10 19:00:22 +00:00
Rui Ueyama 17d6983a4e Rename MaxAlignment -> Alignment.
We can argue about a maximum alignment of a group of symbols,
but for each symbol, there is only one alignment.
So it is a bit weird that each symbol has a "maximum alignment".

llvm-svn: 263151
2016-03-10 18:58:53 +00:00
George Rimar 1452f485e2 [ELF] - Fixed handling R_X86_64_DTPOFF64 relocation relaxation
R_X86_64_DTPOFF64 was not handled properly.
Next sample app was impossible to link before this patch:

~/pg/release/bin/clang -target x86_64-pc-linux testthread.cpp -c -g
~/pg/d+a/bin/ld.lld testthread.o 
"Unknown TLS optimization" (value was 17)

__thread int x = 0;
void _start() {
}

It works fine now.

Differential revision: http://reviews.llvm.org/D18039

llvm-svn: 263150
2016-03-10 18:57:17 +00:00
George Rimar 3498c7fbd0 [ELF] - Refactor of SymbolBody::compare()
That makes it a bit shorter.

Differential revision: http://reviews.llvm.org/D18004

llvm-svn: 263144
2016-03-10 18:49:24 +00:00
George Rimar 5a3dcf4edf [ELF] - Do not call doInitSymbols for all ELFTs
It looks a bit wierd that we have to initialize symbols for all ELFT 
types when we use only one ELFT for link. We can only init those
that we need. Patch fixes it.

Differential revision: http://reviews.llvm.org/D18047

llvm-svn: 263133
2016-03-10 17:38:49 +00:00
George Rimar e094388861 [ELF] - Consistent spelling for error/warning messages
Previously error and warnings were not consistent in lld.
Some of them started from lowercase letter, others from
uppercase. Also there was one or two which had a dot at the end.
This patch changes all messages to start from uppercase letter if
they were not before.

Differential revision: http://reviews.llvm.org/D18045

llvm-svn: 263125
2016-03-10 16:58:34 +00:00
Sean Silva 03e41ee6a7 [lto] Initialize asmparsers.
Summary:
They are needed for inline asm during LTO.

In particular we hit the report_fatal_error on
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp:138

    LLVM ERROR: Inline asm not supported by this streamer because we don't have an asm parser for this target

Reviewers: ruiu, rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D18027

llvm-svn: 263094
2016-03-10 04:58:52 +00:00
Sean Silva 4aaeac6ad3 [lto] Add saving the LTO .o file to -save-temps.
Summary:
This implements another part of -save-temps.
After this, the only remaining part is dumping the optimized bitcode. But
currently LLD's LTO doesn't have a non-intrusive place to put this.
Eventually we probably will and it will make sense to add it then.

Reviewers: ruiu, rafael

Subscribers: joker.eph, Bigcheese, llvm-commits

Differential Revision: http://reviews.llvm.org/D18009

llvm-svn: 263070
2016-03-09 22:30:05 +00:00
Jan Vesely ef1e62033b ELF: link with BitWriter module
Fixes build broken by r263055.

llvm-svn: 263064
2016-03-09 21:38:04 +00:00
Rafael Espindola e090fb2891 ELF: Remove non-standard ELF features from AMDGPU target.
Patch by Tom Stellard!

llvm-svn: 263063
2016-03-09 21:37:22 +00:00
Rui Ueyama 2b4df612ec Simplify. NFC.
In this context, MBRef.getBufferIdentifier() == Path.

llvm-svn: 263061
2016-03-09 21:15:17 +00:00
Sean Silva c43ec673b9 Update for Rui's comments on D18006
Somehow I missed them.

llvm-svn: 263057
2016-03-09 20:06:24 +00:00
Sean Silva 35ef3d95eb [lto] Add beginning of -save-temps option.
Summary:
This is useful for debugging issues with LTO.
The option follows the analogous option in ld64 and the gold plugin (per
Rafael's suggestion).

For starters, this only dumps the combined bitcode file.
In a future patch I will add dumping for the .o file.

The naming of the output follows ld64's convention which is slightly more
consistent IMO (consistent `.lto.<extension>` for all the files).

Reviewers: rafael, ruiu

Subscribers: joker.eph, Bigcheese, llvm-commits

Differential Revision: http://reviews.llvm.org/D18006

llvm-svn: 263055
2016-03-09 20:01:08 +00:00
Sean Silva 50d27ff3c1 [lto] Don't lazy load metadata for now.
Summary:
At the very least we hit

    Assertion failed: (((Flags & RF_HaveUnmaterializedMetadata) || Node->isResolved()) && "Unexpected unresolved node"), function MapMetadataImpl, file /Users/Sean/pg/llvm/lib/Transforms/Utils/ValueMapper.cpp, line 375.

on the included test case.

We currently do things like parse the module twice to keep the
implementation minimal. I think it makes sense to add start with eager
loading for similar reasons.

Reviewers: rafael

Subscribers: ruiu, Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17982

llvm-svn: 263045
2016-03-09 18:38:40 +00:00
George Rimar 599d77246d Fixed "not all control paths return a value" warning. NFC.
llvm-svn: 263040
2016-03-09 18:05:34 +00:00
George Rimar 3c45ed2f5e [ELF] - Issue an error if trying to link object that uses splitstacks.
Each object file compiled in split stack mode will have an empty
section with a special name: .note.GNU-split-stack

We don't support this in linker now, so patch just adds an error out for that.

Differential revision: http://reviews.llvm.org/D17918

llvm-svn: 263039
2016-03-09 18:01:45 +00:00
Rafael Espindola 972b236c30 Simplify: SHN_ABS is >= SHN_LORESERVE.
llvm-svn: 263012
2016-03-09 14:31:18 +00:00
Sean Silva 7255d0b068 [lto] Avoid duplicate symbol error for appending linkage.
Summary:
Is there any other code needed for correctly handling appending linkage?
Do we need to do something more with @llvm.global_ctors in
SymbolTable.cpp:addBitcodeFile; otherwise the combined bitcode module
won't have all the global ctors.

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17975

llvm-svn: 262992
2016-03-09 03:42:39 +00:00
Sean Silva 3dbf9a31b5 Avoid unnecessary qualification.
Thanks to Rui for spotting this.

llvm-svn: 262983
2016-03-09 02:02:26 +00:00
Sean Silva 31a5ab9e3b [lto] Record whether a variable is TLS.
Summary:

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17974

llvm-svn: 262975
2016-03-09 00:47:47 +00:00
Rafael Espindola 708453d99f Assume GV is not null for now.
It will come back when we add support for inline asm in .bc files.

llvm-svn: 262972
2016-03-09 00:31:06 +00:00
Sean Silva b284e71e03 [lto] Don't add variables with private linkage to the symbol table.
Summary:
This causes the issue in PR26872 to go away now that we aren't creating
symbols for the string literals, but that may just be concealing a
deeper problem, so best to keep that PR open.

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17971

llvm-svn: 262968
2016-03-08 23:50:56 +00:00
Rafael Espindola e02f4dfb9e Remove an unnecessary hack.
It doesn't look like anything is depending on using local dynamic tls
relocations with preemptable  symbols.

llvm-svn: 262957
2016-03-08 21:17:31 +00:00
Rafael Espindola 1f04c44885 Delete isTlsDynRel.
It was a badly specified hack for when a tls relocation should be
propagated to the dynamic relocation table.

This replaces it with a not as bad hack of saying that a local dynamic
tls relocation is never preempted.

I will try to remove even that second hack in the next patch.

llvm-svn: 262955
2016-03-08 20:24:36 +00:00
Rafael Espindola 0650192094 Revert "ELF: Add /lib and /usr/lib as default search paths."
It was causing errors like

/lib/libc.so.6 is incompatible with elf_x86_64

when linking on Fedora.

Every system has different default paths. It seems better to just trust
the driver to pass the correct -L options.

This reverts commit 262910.

llvm-svn: 262941
2016-03-08 17:13:12 +00:00
Rui Ueyama 3f9f09265b ELF: Rename NoInhibitExec -> NoinhibitExec.
The variables corresponding to command line options are named mechanically.
Because the option for the variable is -noinhibit-exec and not -no-inhibit-exec,
it should be name this way.

llvm-svn: 262911
2016-03-08 04:06:29 +00:00
Rui Ueyama b9883d55d8 ELF: Add /lib and /usr/lib as default search paths.
GNU ld and gold have these paths as default search paths.
If you don't want these directories, pass -nostdlib.

llvm-svn: 262910
2016-03-08 04:06:27 +00:00
Rafael Espindola 37bcaac179 Add support for common symbols.
llvm-svn: 262848
2016-03-07 19:15:57 +00:00
Rui Ueyama 68fae23475 Do not use "default" for a fully-covered switch.
llvm-svn: 262846
2016-03-07 19:06:14 +00:00
Rafael Espindola e711fc3767 Adjust the .bss alignment to include common symbols.
llvm-svn: 262840
2016-03-07 17:43:39 +00:00
Rafael Espindola 4f29c1a337 lto: Record visibility in defined symbols.
llvm-svn: 262835
2016-03-07 17:14:36 +00:00
Rui Ueyama fd4fee599e Split BitcodeFile::parse. NFC.
llvm-svn: 262813
2016-03-07 00:54:17 +00:00
George Rimar 2f0fab53e4 [ELF] - Simplify a SymbolBody class interface a bit.
Get rid of few accessors in that class, and replace
them with direct fields access.

Differential revision: http://reviews.llvm.org/D17879

llvm-svn: 262796
2016-03-06 06:26:18 +00:00
George Rimar 4d1d16d0ed Fixed formatting issues in AArch64 target methods. NFC.
llvm-svn: 262795
2016-03-06 06:16:05 +00:00
George Rimar 7b8850f2bd [ELF] - Changed return type of Target::relaxTls()
Patch changes the return type of Target::relaxTls 
to size_t from unsigned. That is consistent with
its use from other code.

Change was reviewed http://reviews.llvm.org/D17882
and asked to commit separately from that patch above.

llvm-svn: 262794
2016-03-06 06:09:50 +00:00
George Rimar 98b060d228 [ELF] - Use the uint32_t instead of unsigned in Target class for relocations types
Patch changes all relocations types to be uint32_t and also 
fixes some dependent inconsistency in callers code.

Differential revision: http://reviews.llvm.org/D17882

llvm-svn: 262793
2016-03-06 06:01:07 +00:00
Rafael Espindola 7f6d50b229 Use IRMover directly.
This has a few advantages:
* If lld selected a non bitcode symbol, be the bitcode GV is not merged
* lib/Linker is not redoing symbol resolution.

llvm-svn: 262773
2016-03-05 14:51:51 +00:00
Rafael Espindola 888f2c33d4 lto: Start taking symbol visibility into consideration.
llvm-svn: 262761
2016-03-05 00:09:37 +00:00
Rafael Espindola d405f4721c Refactor target independent code.
The rules for when we can relax tls relocations are target independent.
The only things that are target dependent are the relocation values.

llvm-svn: 262748
2016-03-04 21:37:09 +00:00
Rui Ueyama d4530c6eb8 Add a comment about _DYNAMIC.
llvm-svn: 262735
2016-03-04 18:34:14 +00:00
Rafael Espindola 1ea51d2718 Refactor duplicated code.
llvm-svn: 262720
2016-03-04 16:14:19 +00:00
Simon Atanasyan 4e18a3163d [ELF][MIPS] Factor out the code reading and sign-extending low 16-bits of 32-bit word. NFC
llvm-svn: 262708
2016-03-04 10:55:29 +00:00
Simon Atanasyan 0dcf541692 [ELF][MIPS] Factor out the code writing relocation result into low 16-bit of destination. NFC
llvm-svn: 262707
2016-03-04 10:55:24 +00:00
Simon Atanasyan 3b37785fee [ELF][MIPS] Factor out the code reading and calculating AHL addend into the separate function. NFC
llvm-svn: 262706
2016-03-04 10:55:20 +00:00
Simon Atanasyan deed55d706 [ELF][MIPS] Use writeMipsHi16 to apply result of R_MIPS_PCHI16 relocation. NFC
llvm-svn: 262705
2016-03-04 10:55:16 +00:00
Simon Atanasyan a888e6726f [ELF][MIPS] Replace S and A arguments of the writeMipsHi16 function by the single argument V. NFC
llvm-svn: 262704
2016-03-04 10:55:12 +00:00
Simon Atanasyan 3474b907dd [ELF][MIPS] s/applyMipsHi16Reloc/writeMipsHi16/ NFC
llvm-svn: 262703
2016-03-04 10:55:04 +00:00
Rui Ueyama a3cb80adfc Use check function.
llvm-svn: 262685
2016-03-04 01:56:52 +00:00
Davide Italiano 255730cdc5 [ELF] Generalize symbol type handling.
SymbolBody constructor and friends take isFunc and isTLS boolean arguments.
ELF symbols have already a type so than be easily passed as argument.
If we want to support another type, this scheme is not good enough, that is,
the current code logic would require passing another `bool isObject` around.
Up to two argument, this stretching exercise was a little bit goofy but
still acceptable, but with more types to support, is just too much, IMHO.

Change the code so that the type is passed instead.

Differential Revision:   http://reviews.llvm.org/D17871

llvm-svn: 262684
2016-03-04 01:55:28 +00:00
Rafael Espindola 75714f618c Rename 'fatal' to 'check' when it doesn't always fail.
llvm-svn: 262666
2016-03-03 22:24:39 +00:00
Rui Ueyama 6df27e7f21 Remove dead code.
llvm-svn: 262662
2016-03-03 21:56:21 +00:00
Davide Italiano 05920b14c8 [ELF] Be slightly more consistent, use uint8_t instead of unsigned char.
llvm-svn: 262660
2016-03-03 21:54:03 +00:00
Rafael Espindola ec9957bd0b Delete dead code.
llvm-svn: 262653
2016-03-03 20:45:26 +00:00
George Rimar e5960ceb6b [ELF] - Do not allow .bss to occupy the file space when producing relocatable output
When generating relocatable output SHT_NOBITS sections
were still occupy the file space.

Differential revision: http://reviews.llvm.org/D17857

llvm-svn: 262650
2016-03-03 20:24:14 +00:00
Rafael Espindola 005d84430d Fix PR26818.
The hack of using a plt address as the address of an undefined function
only works in executables. Don't try it with shared libraries.

llvm-svn: 262642
2016-03-03 18:44:38 +00:00
Rafael Espindola 1130935c4a Simplify error handling.
This makes fatal return T when there is no error. This avoids the need
for quite a few temporaries.

llvm-svn: 262626
2016-03-03 16:21:44 +00:00
George Rimar 4cfe572932 [ELF] - add support for relocations against local symbols when producing relocatable output.
There was a known limitation for -r option:
relocations against local symbols were not supported. 
For example rel[a].eh_frame sections contained relocations against sections
and that was not supported for -r before. Patch fixes that.

Differential review: http://reviews.llvm.org/D17813

llvm-svn: 262590
2016-03-03 07:49:35 +00:00
Rui Ueyama eb3413e43a Replace ECRAII class with a function.
RCRAII class was a bit tricky. This patch removes that.

llvm-svn: 262586
2016-03-03 06:22:29 +00:00
Rui Ueyama a1ee70ba75 Allow joined options to fix http://llvm.org/pr26730.
llvm-svn: 262550
2016-03-03 00:09:02 +00:00
Rui Ueyama a453c0a5ad Merge DarwinLdDriver and Driver.
Now that DarwinLdDriver is the only derived class of Driver.
This patch merges them and actually removed the class because
they can now just be non-member functions. This change simplifies
a common header, Driver.h.

http://reviews.llvm.org/D17788

llvm-svn: 262502
2016-03-02 19:08:05 +00:00
Rafael Espindola cdf3a2a5be 1Fix handling of undef in partial LTO.
llvm-svn: 262497
2016-03-02 18:21:46 +00:00
Rafael Espindola 3ca9ee0c53 LTO: Use the correct relocation model.
llvm-svn: 262492
2016-03-02 17:21:06 +00:00
Rafael Espindola 4de44b7ef8 Handle comdat in LTO.
llvm-svn: 262489
2016-03-02 15:43:50 +00:00
Simon Atanasyan ea423e261f [ELF] Fix reading of PC values of FDEs
The patch fixes two related problems:
- If CIE augmentation string has 'L' token the CIE contains a byte
  defines LSDA encoding. We should skip this byte in `getFdeEncoding`
  routine. Before this fix we do not skip it and if the next token
  is 'R' treat this byte as FDE encoding.
- FDE encoding format has separate flags e.g. DW_EH_PE_pcrel for
  definition of relative pointers. We should add .eh_frame address to
  the PC value iif the DW_EH_PE_pcrel is specified.

http://www.airs.com/blog/archives/460

There is one more not fixed problem in this code. If PC value is encoded
using signed relative format e.g. DW_EH_PE_sdata4 | DW_EH_PE_pcrel we
should sign extend result of read32 to perform calculation correctly.
I am going to fix that in a separate patch.

Differential Revision: http://reviews.llvm.org/D17733

llvm-svn: 262461
2016-03-02 05:38:42 +00:00
Rui Ueyama 148945eb17 Fix --help message.
llvm-svn: 262413
2016-03-01 22:17:09 +00:00
George Rimar 262b927d36 [ELF] - handle of command line options incompatible with -r
Patch handles the command line options
incompatible with relocatable output.

Differential revision: http://reviews.llvm.org/D17758

llvm-svn: 262377
2016-03-01 19:38:51 +00:00
George Rimar 2abc587c1e [ELF] - More direct implementation of edata/etext
As was suggested in mails, this patch implements edata/etext
symbols in a more direct way.
It iterates through PT_LOADs.

Result seems to be the same and equal to gold output.

Differential revision: http://reviews.llvm.org/D17755

llvm-svn: 262369
2016-03-01 19:18:07 +00:00
George Rimar c1034a85d0 [ELF] - do not create special symbols when creating relocatable output
__start_/__end_ <section-name> symbols and other specials like:
preinit_array_start/end
init_array_start/end
fini_array_start/end

should not be created by linker when creating relocatable files.

Differential revision: http://reviews.llvm.org/D17774

llvm-svn: 262366
2016-03-01 19:12:35 +00:00
George Rimar aa4dc20f09 [ELF] - Create _DYNAMIC symbol for dynamic output
lld needs to provide _DYNAMIC symbol when creating a shared library
both bfd and gold do that.

This should fix the https://llvm.org/bugs/show_bug.cgi?id=26732

Differential revision: http://reviews.llvm.org/D17607

llvm-svn: 262348
2016-03-01 16:23:13 +00:00
Rafael Espindola 393877d51b Fix BUILD_SHARED_LIBS build.
llvm-svn: 262345
2016-03-01 15:56:53 +00:00
Rafael Espindola 9907eb0b0a Produce PT_NOTE program headers.
llvm-svn: 262331
2016-03-01 13:23:29 +00:00
George Rimar 6de3f63bb0 [ELF] use of already declared reference instead of indirect access to fields. NFC.
llvm-svn: 262315
2016-03-01 08:46:03 +00:00
Rafael Espindola 1b625535f0 lto: don't fetch members for weak undef.
llvm-svn: 262225
2016-02-29 14:29:48 +00:00
Rafael Espindola 9bcbfd7d42 Remove bogus assert.
llvm-svn: 262219
2016-02-29 13:46:39 +00:00
Rui Ueyama e7b330052f Move functionality of UniversalDriver to the entry point file.
UniversalDriver was used as a dispatcher to each platform-specific driver.
It had its own Options.td file. It was not just too much to parse only a
few options (we only want to parse -core, -flavor or argv[0]),
but also interpreted arguments too early. For example, if you invoke lld as
"lld -flavor gnu ... -help", then you'd get the UniversalDriver's help
message instead of GnuDriver's. This patch eliminates the use of Options
from the dispatcher.

http://reviews.llvm.org/D17686

llvm-svn: 262190
2016-02-28 19:50:14 +00:00
Rui Ueyama 3e80897627 ELF: Remove OutSection class and use a map instead.
It is easier to handle section filler data separately rather than
merging with section names.

llvm-svn: 262175
2016-02-28 05:09:11 +00:00
Rui Ueyama 7a6c9aed7a Simplify. NFC.
llvm-svn: 262174
2016-02-28 04:48:54 +00:00
Rui Ueyama 7c82dbf333 Remove unused #include.
llvm-svn: 262169
2016-02-28 03:27:09 +00:00
Rui Ueyama 1eb9f44118 ELF: Add --help option.
llvm-svn: 262168
2016-02-28 03:18:09 +00:00
Rui Ueyama 1abcf370fd ELF: Add --version option.
llvm-svn: 262167
2016-02-28 03:18:07 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rui Ueyama 40c589048e ELF: Remove relSize function from ICF.cpp. NFC.
llvm-svn: 262155
2016-02-27 20:29:45 +00:00
Rafael Espindola 18f0950783 Report duplicated symbols in bitcode.
llvm-svn: 262076
2016-02-26 21:49:38 +00:00
Rafael Espindola 297ce4ece9 Make SymbolBodies private.
This makes BitcodeFile a bit closer to ObjectFile.

If anyone prefers I can go the other way and delete getSymbols from
ObjectFile.

llvm-svn: 262072
2016-02-26 21:31:34 +00:00
Rui Ueyama 68e15559b8 Fix broken buildbots.
llvm-svn: 262034
2016-02-26 16:49:54 +00:00
Rui Ueyama 4d169bdca2 Simplify. NFC.
Regarding the comment, it is out of context because it describes
what it does not do there. It got too long because it was originally
two different comments that were simply merged together.
The semantics is described in fixAbsoluteSymbols, so we don't need it.

llvm-svn: 262031
2016-02-26 16:38:39 +00:00
Rui Ueyama dad77c593b Simplify. NFC.
llvm-svn: 262027
2016-02-26 15:42:06 +00:00
Rui Ueyama 72acaa1d17 Add comment on AMDGPU that the difference has no obvious reason.
llvm-svn: 262026
2016-02-26 15:39:26 +00:00
Rui Ueyama eec23eb319 Fix unsafe dereference.
Bound may point to one element beyond the end of the
vector, so *Bound is not safe.

llvm-svn: 262022
2016-02-26 15:13:24 +00:00
George Rimar e2ee72b509 [ELF] - Implemented linkerscript sections padding.
BSD linker scripts contain special cases to add NOP
padding to code sections. Syntax is next:

.init:
 {
   KEEP (*(.init))
 } =0x90909090
(0x90 is NOP)

This patch implements that functionality.

llvm-svn: 262020
2016-02-26 14:48:31 +00:00
George Rimar 9e8593949d Description of symbols is avalable here:
https://docs.oracle.com/cd/E53394_01/html/E54766/u-etext-3c.html

It is said that:
_etext - The address of _etext is the first 
location after the last read-only loadable segment.

_edata - The address of _edata is the first 
location after the last read-write loadable segment.

_end - If the address of _edata is greater than the address 
of _etext, the address of _end is same as the address of _edata.

In real life _end and _edata has different values for that case.
Both gold/bfd set _edata to the end of the last non SHT_NOBITS section.
This patch do the same for consistency.

It should fix the https://llvm.org/bugs/show_bug.cgi?id=26729.

Differential revision: http://reviews.llvm.org/D17601

llvm-svn: 262019
2016-02-26 14:36:36 +00:00
Rafael Espindola a350e266aa Refactor multiple calls to canBePreempted.
llvm-svn: 262018
2016-02-26 14:33:23 +00:00
Rafael Espindola 993f0273e3 Fix some confusion about what can be preempted.
For shared libraries we allow any weak undefined symbol to eventually be
resolved, even if we never see a definition in another .so. This matches
the behavior when handling other undefined symbols in a shared library.

For executables, we require seeing a definition in a .so or resolve it
to zero. This is also similar to how non weak symbols are handled.

llvm-svn: 262017
2016-02-26 14:27:47 +00:00
Rui Ueyama dc9cc6a574 Remove redundant template instantiations.
This class is used only in this translation unit, so no need
to instantiate them explicitly.

llvm-svn: 261951
2016-02-26 01:30:35 +00:00
Rui Ueyama bca6eb85a3 Fix typo in comment.
llvm-svn: 261943
2016-02-26 00:10:01 +00:00
Rui Ueyama ad59b65f18 ELF: Add '*' to auto.
llvm-svn: 261941
2016-02-25 23:58:21 +00:00
Rui Ueyama a354c5c433 ELF: Create MIPS .rld_map section earlier.
This is the usual way of instantiating a globally-visible section.

llvm-svn: 261938
2016-02-25 23:54:49 +00:00
Rafael Espindola 58e4c6bdba Delete dead code.
When this code was first added it was compensating for the code deciding
to create plt entries for directly referenced functions being too aggressive.

That has since been fixed, so we don't need this anymore.

llvm-svn: 261933
2016-02-25 23:16:33 +00:00
Rafael Espindola dd7f4e33ea Move common code out of target specific hooks.
llvm-svn: 261932
2016-02-25 23:03:55 +00:00
Simon Atanasyan 860fbf094e [ELF][MIPS] Calculate combined addend for R_MIPS_GOT16 against local symbol
R_MIPS_GOT16 relocation against local symbol requires index of a local
GOT entry which contains page address corresponds to sum of the symbol
address and addend. The addend in that case is calculated using addends
from the R_MIPS_GOT16 and paired R_MIPS_LO16 relocations.

Differential Revision: http://reviews.llvm.org/D17610

llvm-svn: 261930
2016-02-25 21:33:56 +00:00
Simon Atanasyan bea9698b0e [ELF][MIPS] Remove redundant namespace qualifier. NFC
llvm-svn: 261928
2016-02-25 21:09:05 +00:00
Rui Ueyama 3095148015 ELF: Split Writer::addPredefiendSections. NFC.
llvm-svn: 261924
2016-02-25 19:34:37 +00:00
Rui Ueyama 4cea4e81d4 ELF: Split Writer::writeHeader. NFC.
llvm-svn: 261923
2016-02-25 19:28:37 +00:00
Rui Ueyama 10bd283041 ELF: Define log() to print out message if --verbose is given.
llvm-svn: 261919
2016-02-25 18:56:01 +00:00
Rui Ueyama 6a9ef8550c Remove default values which are always overwritten.
llvm-svn: 261913
2016-02-25 18:49:09 +00:00
Rui Ueyama 0b28952993 ELF: Implement ICF.
This patch implements the same algorithm as LLD/COFF's ICF. I'm
not going to repeat the same description about how it works, so you
want to read the comment in ICF.cpp in this patch if you want to know
the details. This algorithm should be more powerful than the ICF
algorithm implemented in GNU gold. It can even merge mutually-recursive
functions (which is harder than one might think).

ICF is a fairly effective size optimization. Here are some examples.

 LLD:   37.14 MB -> 35.80 MB (-3.6%)
 Clang: 59.41 MB -> 57.80 MB (-2.7%)

The lacking feature is "safe" version of ICF. This merges all
identical sections. That is not compatible with a C/C++ language
requirement that two distinct functions must have distinct addresses.

But as long as your program do not rely on the pointer equality
(which is in many cases true), your program should work with the
feature. LLD works fine for example.

GNU gold implements so-called "safe ICF" that identifies functions
that are safe to merge by heuristics -- for example, gold thinks
that constructors are safe to merge because there is no way to
take an address of a constructor in C++. We have a different idea
which David Majnemer suggested that we add NOPs at beginning of
merged functions so that two or more pointers can have distinct
values. We can do whichever we want, but this patch does not
include neither.

http://reviews.llvm.org/D17529

llvm-svn: 261912
2016-02-25 18:43:51 +00:00
Rafael Espindola 148445ef98 Add support for weak symbols in LTO.
llvm-svn: 261881
2016-02-25 16:25:41 +00:00
Rafael Espindola f1ce4cf1f1 Remove unnecessary prefix.
llvm-svn: 261880
2016-02-25 16:20:00 +00:00
Simon Atanasyan d040a58da3 [ELF][MIPS] Add STO_MIPS_PLT flag to the symbols require pointer equality
On MIPS we need to mark symbol which has a PLT entry and requires
pointer equality by STO_MIPS_PLT flag. That is necessary to help
dynamic linker distinguish such symbols and MIPS lazy-binding stubs.

https://sourceware.org/ml/binutils/2008-07/txt00000.txt

Differential Revision: http://reviews.llvm.org/D17593

llvm-svn: 261879
2016-02-25 16:19:15 +00:00
George Rimar 12737b7f72 [ELF] - Referencing __start or __stop should keep the section from GC.
This fixes the https://llvm.org/bugs/show_bug.cgi?id=22906 bug.

In GNU Binutils, a reference to start or stop is sufficient to 
prevent the section from being garbage collected.
Patch implements the same behavior for lld.

Differential revision: http://reviews.llvm.org/D17502

llvm-svn: 261840
2016-02-25 08:40:26 +00:00
George Rimar 58941ee12a [ELF2] - Basic implementation of -r/--relocatable
-r, -relocatable - Generate relocatable output

Currently does not have support for files containing 
relocation sections with entries that refer to local 
symbols (like rel[a].eh_frame which refer to sections
and not to symbols)

Differential revision: http://reviews.llvm.org/D14382

llvm-svn: 261838
2016-02-25 08:23:37 +00:00
Simon Atanasyan 49bc69b9bb [ELF][MIPS] Enumerate absolute MIPS relocations in the isRelRelative
This commit does two related thing. At first, it enumerates supported
absolute MIPS relocations in the `MipsTargetInfo<ELFT>::isRelRelative`
method. In that case the code is shorter and the case switch does not
tend to grow. At second, it prevents R_MIPS_COPY and PLT creation for
relative relocations. For almost all relative MIPS relocations like
R_MIPS_PC19_S2, R_MIPS_PCHI16 etc it does not have a sence. The only
exception is R_MIPS_PC32. GNU linker creates a copy relocation or PLT
entry for it. But I could not find any real test case uses R_MIPS_PC32
with DSO defined symbol as a target. So for now I prefer to skip this
case to simplify the LLD code.

llvm-svn: 261822
2016-02-25 05:03:52 +00:00
Rafael Espindola a598a3a08a Mark R_AARCH64_CALL26 as relative.
llvm-svn: 261783
2016-02-24 22:07:12 +00:00
Rafael Espindola 47ed542328 Mark R_AARCH64_ADD_ABS_LO12_NC as relative.
llvm-svn: 261772
2016-02-24 21:48:06 +00:00
Rafael Espindola 57ca270b7a Mark R_AARCH64_LDST64_ABS_LO12_NC as relative.
llvm-svn: 261769
2016-02-24 20:52:58 +00:00
Rafael Espindola 40afcb547e Mark R_AARCH64_LDST32_ABS_LO12_NC as relative.
llvm-svn: 261766
2016-02-24 20:18:06 +00:00
Rafael Espindola 9a3bb54b2e R_AARCH64_LDST8_ABS_LO12_NC is effectivelly relative.
It only sets the low bits and given the page alignment of PT_LOAD the
dynamic linker can only change the high ones.

llvm-svn: 261765
2016-02-24 19:58:50 +00:00
Rafael Espindola c36e97ae39 R_AARCH64_ADR_PREL_PG_HI21 is relative.
llvm-svn: 261764
2016-02-24 19:36:30 +00:00
Rui Ueyama 733153de3c ELF: Do not instantiate InputSectionBase::Discarded.
"Discarded" section is a marker for discarded sections, and we do not
use the instance except for checking its identity. In that sense, it
is just another type of a "null" pointer for InputSectionBase. So,
it doesn't have to be a real instance of InputSectionBase class.

In this patch, we no longer instantiate Discarded section but instead
use -1 as a pointer value. This eliminates a global variable which
needed initialization at startup.

llvm-svn: 261761
2016-02-24 18:33:35 +00:00
Rafael Espindola 795dc5a0fb Move target independent code out of x86_64 only path.
The logic for deciding if an undefined symbol should have the value of a
got entry is not target specific.

llvm-svn: 261760
2016-02-24 18:24:23 +00:00
Rafael Espindola b508f520e7 Create implicit plt entries for R_X86_64_32S.
llvm-svn: 261749
2016-02-24 16:37:47 +00:00
Rafael Espindola a4e35f7092 Mark R_AARCH64_PREL32 as relative.
llvm-svn: 261747
2016-02-24 16:15:13 +00:00
George Rimar c3794e5834 [ELF] - replaced std::function with raw pointers in LinkerScript.cpp
Change as was proposed by David Blaikie.

Differential revision: http://reviews.llvm.org/D17499

llvm-svn: 261729
2016-02-24 09:21:47 +00:00