Commit Graph

1535 Commits

Author SHA1 Message Date
Ed Schouten 988b827992 Provide support for Binutils' --no-dynamic-linker option.
GNU ld seems to write a PT_INTERP header into executables containing a
default (read: bogus) value if --dynamic-linker flag is not provided.
LLD is different in the sense that it omits it unless --dynamic-linker
is provided, which seems fair.

Binutils 2.26 added a new flag, --no-dynamic-linker, that can be used to
generate binaries without PT_INTERP. Let's go ahead and also add this
flag to LLD, so that we can invoke the linker in a portable way.

Reviewed by:	ruiu
Differential Revision:	http://reviews.llvm.org/D18723

llvm-svn: 265246
2016-04-02 20:58:02 +00:00
Rui Ueyama 12dff23951 Simplify. NFC.
llvm-svn: 265242
2016-04-02 19:36:36 +00:00
Rui Ueyama 24d0d2f917 Merge two `if`s.
llvm-svn: 265241
2016-04-02 19:31:01 +00:00
Rui Ueyama 8fe7ce5903 Variable names should start with uppercase letters.
llvm-svn: 265239
2016-04-02 19:15:26 +00:00
Rui Ueyama 7e71c61a7a Rename a variable. NFC.
We had variables MB and Mb in this function. Rename of one them.

llvm-svn: 265237
2016-04-02 19:09:07 +00:00
Rui Ueyama d1aa97b5c2 Do not return early.
Early return in this context is a bit confusing, so avoid doing it.

llvm-svn: 265236
2016-04-02 18:52:23 +00:00
Rui Ueyama 1fc5d48877 Move code to initialize LLVM to one place.
llvm-svn: 265235
2016-04-02 18:18:44 +00:00
Rui Ueyama bfc1d9d976 Remove DefinedElf class.
DefinedElf was a superclass of DefinedRegular and SharedSymbol classes
and represented the notion of defined symbols created for ELF symbols.

It turned out that we didn't use that class often. We had only two
occurrences of dyn_cast'ing to DefinedElf, and both were easily
rewritten without it.

The class was also a bit confusing. The concept of "created for ELF
symbol" is orthogonal to defined/undefined types. However, we had
two distinct classes, DefinedElf and UndefinedElf.

This patch simply removes the class. Now the class hierarchy is one
level shallower.

llvm-svn: 265234
2016-04-02 18:06:18 +00:00
Sean Silva abd25c9b3e Call cl::ParseCommandLineOptions from the driver.
Thanks to Rui for the suggestion; this simplifies things.

llvm-svn: 265213
2016-04-02 04:08:02 +00:00
Davide Italiano 4fda708624 [LTO] Fix symbols which were internalized incorrectly.
If a symbol is defined in an archive, when we replace its body
the isUsedInRegularObj wasn't set correctly. Internalize makes
its decision based on that bit so we ended up internalizing
symbols that we shouldn't (because they're referenced).
This should fix. Thanks to Peter and Rafael for discussion
and help diagnosing the issue!

Found during LTO of unittests.

llvm-svn: 265208
2016-04-02 02:10:40 +00:00
Sean Silva 242bbdb7bf Fix MSVC build after r265206
c:\b\slave\sanitizer-windows\llvm\tools\lld\elf\Config.h(94) : error C2797: 'lld:🧝:Configuration::MLlvm': list initialization inside member initializer list or non-static data member initializer is not implemented

llvm-svn: 265207
2016-04-02 01:51:51 +00:00
Sean Silva 8e4ad5dbf8 PR27104: Add -mllvm option
The argv[0] is based on the analogous thing in clang.

llvm-svn: 265206
2016-04-02 01:39:56 +00:00
Rafael Espindola 059f3fb8fb Don't create a plt when LD access is optimized.
llvm-svn: 265203
2016-04-02 00:19:22 +00:00
Rafael Espindola cf3b04dab9 Don't create a PLT when we optimize out the plt use.
llvm-svn: 265202
2016-04-01 23:36:56 +00:00
Rui Ueyama e8a45e48f9 Rename a few variables. NFC.
We had Phdr, PHdr and Phdrs in one line. That was a bit confusing.

llvm-svn: 265194
2016-04-01 22:42:04 +00:00
Rafael Espindola 36404d0030 Simplify if. NFC.
llvm-svn: 265166
2016-04-01 18:04:21 +00:00
George Rimar 687788c90e [ELF] - Split Writer::assignAddresses(): extract code for initializing dummies sections
Extracts code for initializing dummies sections
to avoid possible duplication in following patches.

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

llvm-svn: 265159
2016-04-01 17:30:52 +00:00
Rui Ueyama f7f52ef65d Make error handling consistent.
Some functions in Writer reports error using HasError, and some reports
their return values. This patch makes them to consistently use HasError.

llvm-svn: 265156
2016-04-01 17:24:19 +00:00
Rui Ueyama 8ecc2ec0e3 Remove dead code.
Thanks to George Rimor for pointing it out.

llvm-svn: 265155
2016-04-01 17:17:14 +00:00
Rui Ueyama a63baf176f Don't do extra work if -r is given.
fixAbsoluteSymbols fixes linker-created symbol addresses. Since we don't
create such symbols for relocatable output, we don't need to call this
function.

llvm-svn: 265154
2016-04-01 17:11:42 +00:00
Rui Ueyama e044e9cf80 Tidy up address and file offset assignments in the Writer.
assignAddressesRelocatable function did not set addresses to sections
despite its name. What it actually did is to set file offsets to sections.
assignAddresses function assigned addresses and file offsets to sections.
So there was a confusion what they were doing, and they had duplicate code.

This patch separates file offset assignments from address assignments.
A new function, assignFileOffsets assign file offsets. assignAddresses
do not care about file offsets anymore.

llvm-svn: 265151
2016-04-01 17:07:17 +00:00
Rafael Espindola 790db9c458 Bring r264761 back with an extra fix.
The extra fix is to note that it still requires copy relocations.

Original message:

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.

P.S.: Suggestions for a better name for the predicate are welcome :-)

llvm-svn: 265150
2016-04-01 17:00:36 +00:00
Rafael Espindola 2ee0092053 Don't apply a recolation that the dynamic linker will rewrite.
This matches the behavior of both bfd and gold. Looks like we just got
here for mips because of a bad ordering of an if else chain.

llvm-svn: 265147
2016-04-01 16:21:09 +00:00
Rafael Espindola 666625b78c Pass a const pointer to getImplicitAddend. NFC.
llvm-svn: 265143
2016-04-01 14:36:09 +00:00
Rafael Espindola 31d2ada6d5 Refactor duplicated code.
We had almost identical code to handle creating a plt entry in two
places.

llvm-svn: 265142
2016-04-01 14:14:48 +00:00
Rafael Espindola b97f4beec4 Avoid creating duplicated relocations.
llvm-svn: 265139
2016-04-01 12:54:27 +00:00
George Rimar 5a5c39ca2a Fix linux buildbot after r265136
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/20138

Fix: Move method above class that uses it.
Works fine with MSVS.

llvm-svn: 265137
2016-04-01 12:24:28 +00:00
George Rimar e2da42a762 Make dummySectionsNum() to be not a member of writer. NFC.
llvm-svn: 265136
2016-04-01 11:59:32 +00:00
George Rimar b345e0d15c Split Writer::assignAddresses(): extract common code to fixFileOff(). NFC.
llvm-svn: 265131
2016-04-01 11:04:47 +00:00
George Rimar 900a260357 Split Writer::assignAddresses(): extract assignPhdrs(). NFC.
llvm-svn: 265130
2016-04-01 10:49:14 +00:00
George Rimar efded31a61 [ELF] - Move calculation of _end to fixAbsoluteSymbols()
That is consistent with other symbols: _edata, _etext
and can help to avoid duplicate code.

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

llvm-svn: 265129
2016-04-01 10:23:32 +00:00
Davide Italiano 8eca282dc9 [LTO] Inherit options from Codegen before initializing TargetMachine.
This fixes bootstrap of llvm-tblgen (with LTO) and PR27150.
Slightly longer explanation follows.

Emission of .init_array instead of .ctors is supported only on a
subset of the Target LLVM supports. Codegen needs to be conservative
and always emit .ctors unless instructed otherwise (based on target).
If the dynamic linker sees .init_array it completely ignores
what's inside .ctors and therefore some constructors are not called
(and this causes llvm-tblgen to crash on startup).

Teach LLD/LTO about the Codegen options so we end up always emitting
.init_array and avoid this issue.
In future, we might end up supporting mix of .ctors and .init_array
in different input files if this shows up as a real-world use case.
The way gold handles this case is mapping .ctors from input into
.init_array in output. There's also another caveat because
as far as I understand .ctors run in reverse order so when we do
the copy/mapping we need to reverse copy in the output if there's
more than one ctor. That's why I'd rather avoid this complicate logic
unless there's a real need.

An analogous reasoning holds for .dtors/.fini_array.

llvm-svn: 265085
2016-04-01 00:35:29 +00:00
Peter Collingbourne d418b1da38 ELF: Correctly handle --whole-archive for thin archives.
Differential Revision: http://reviews.llvm.org/D18669

llvm-svn: 265073
2016-03-31 23:12:18 +00:00
Simon Atanasyan 13f6da1d2c [ELF] Implement infrastructure for thunk code creation
Some targets might require creation of thunks. For example, MIPS targets
require stubs to call PIC code from non-PIC one. The patch implements
infrastructure for thunk code creation and provides support for MIPS
LA25 stubs. Any MIPS PIC code function is invoked with its address
in register $t9. So if we have a branch instruction from non-PIC code
to the PIC one we cannot make the jump directly and need to create a small
stub to save the target function address.
See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

- In relocation scanning phase we ask target about thunk creation necessity
by calling `TagetInfo::needsThunk` method. The `InputSection` class
maintains list of Symbols requires thunk creation.

- Reassigning offsets performed for each input sections after relocation
scanning complete because position of each section might change due
thunk creation.

- The patch introduces new dedicated value for DefinedSynthetic symbols
DefinedSynthetic::SectionEnd. Synthetic symbol with that value always
points to the end of the corresponding output section. That allows to
escape updating synthetic symbols if output sections sizes changes after
relocation scanning due thunk creation.

- In the `InputSection::writeTo` method we write thunks after corresponding
input section. Each thunk is written by calling `TargetInfo::writeThunk` method.

- The patch supports the only type of thunk code for each target. For now,
it is enough.

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

llvm-svn: 265059
2016-03-31 21:26:23 +00:00
Peter Collingbourne 098c3fcb03 ELF: Add more variants of ignored flags.
Differential Revision: http://reviews.llvm.org/D18668

llvm-svn: 265058
2016-03-31 21:18:34 +00:00
Rui Ueyama b339b6de0d Define a utility function to read -O and lto-O options.
llvm-svn: 265056
2016-03-31 21:15:31 +00:00
Peter Collingbourne ed22f9b6f1 ELF: Add flag for controlling LTO optimization level.
Differential Revision: http://reviews.llvm.org/D18667

llvm-svn: 265053
2016-03-31 21:00:27 +00:00
Ed Maste e2b7677c9e lld: accept and ignore _fbsd suffix in emulation name
Differential Revision:	http://reviews.llvm.org/D18661

llvm-svn: 265044
2016-03-31 20:26:30 +00:00
Rafael Espindola 4e5ab42e21 Pass a const SymbolBody to needsGot. NFC.
llvm-svn: 265012
2016-03-31 13:38:28 +00:00
Rafael Espindola 66ea7bb2c1 Fix the alignment check.
We have to check the final value that is written.

I don't think this has any real word implications (unless something
supports unaligned instructions), but unblocks simplifying the handling
of PC relative relocations.

llvm-svn: 265009
2016-03-31 12:09:36 +00:00
Simon Atanasyan cf8c42f546 [ELF][MIPS] Revert r264761 and add test case to demonstrate the problem
If we make R_MIPS_LO16 a relative relocation, linker:
- never creates R_MIPS_COPY relocation for it
- attempts to create R_MIPS_REL32 dynamic relocation if R_MIPS_LO16's
  target is a preemptible symbol

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

llvm-svn: 264956
2016-03-30 22:43:14 +00:00
Reid Kleckner 4f88914c5b Remove unused fwd decl for LLVM IR stuff that lives in LTO now
llvm-svn: 264911
2016-03-30 20:15:41 +00:00
Rui Ueyama 4709190376 Split Writer::assignAddresses. NFC.
llvm-svn: 264905
2016-03-30 19:41:51 +00:00
Rui Ueyama 38dc83417b Include line number in error message for linker scripts.
This patch is based on http://reviews.llvm.org/D18545 written
by George Rimar.

llvm-svn: 264878
2016-03-30 16:51:57 +00:00
Rafael Espindola 287e100db2 No relocation needs bot SA and ZA.
Pass only one of them to relocateOne.

llvm-svn: 264866
2016-03-30 13:27:50 +00:00
Rafael Espindola 8cc68c313b Implement getImplicitAddend for mips.
llvm-svn: 264865
2016-03-30 13:18:08 +00:00
Rafael Espindola abc9a12929 Simplify mips addend processing.
It is now added to the addend in the same way as a regular Elf_Rel
addend.

llvm-svn: 264864
2016-03-30 12:45:58 +00:00
Rafael Espindola da99df366d Fix handling of addends on i386.
Because of merge sections it is not sufficient to just add them while
applying a relocation.

llvm-svn: 264863
2016-03-30 12:40:38 +00:00
Ismail Donmez 22921c9cf5 Fix shared build after r264790
llvm-svn: 264844
2016-03-30 08:31:46 +00:00
George Rimar f1c0bf5b40 [ELF] - Do not keep undefined locals in .symtab
gold and bfd do not include the undefined locals in symtab.
We have no reasons to support that either.

That fixes PR27016

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

llvm-svn: 264843
2016-03-30 08:16:11 +00:00
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