Commit Graph

1496 Commits

Author SHA1 Message Date
Ismail Donmez 23e5a38407 Fix shared build after r266484
llvm-svn: 266558
2016-04-17 09:01:51 +00:00
Duncan P. N. Exon Smith 2c66b23d79 LTO: Merge debug info types when linking bitcode
Make sure lld enables ODR type uniquing for debug info when invoking
LTO, as a follow-up to LLVM r266549.

llvm-svn: 266555
2016-04-17 07:35:38 +00:00
Simon Atanasyan 737a92c893 [ELF] Include Twine.h header to restore LLD build after r266524. NFC
llvm-svn: 266527
2016-04-16 10:58:45 +00:00
George Rimar 652852c5c0 Recommitted 266457 with fix:
* Do script driven layout only if SECTIONS section exist.

Initial commit message:

[ELF] - Implemented basic location counter support.

This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

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

llvm-svn: 266526
2016-04-16 10:10:32 +00:00
Davide Italiano 493b683f79 [LTO] Don't crash on a BitcodeFile without DataLayout.
Emit an error instead.

llvm-svn: 266504
2016-04-16 01:33:33 +00:00
Rui Ueyama faac567e68 Revert r266457: "[ELF] - Implemented basic location counter support."
This reverts commit r266457 as it breaks "hello world" both on
Linux and FreeBSD.

llvm-svn: 266485
2016-04-15 22:39:27 +00:00
Davide Italiano bc176631cd [LTO] Implement parallel Codegen for LTO using splitCodeGen.
Parallelism level can be chosen using the new --lto-jobs=K option
where K is the number of threads used for CodeGen. It currently
defaults to 1.

llvm-svn: 266484
2016-04-15 22:38:10 +00:00
Rafael Espindola 5628ee7631 Simplify got handling.
Each getRelExpr is now expected to return the correct got expression
instead of having Writer patch it up with needsGot.

llvm-svn: 266466
2016-04-15 19:14:18 +00:00
Rafael Espindola 7dd20563a2 Merge duplicated cases. NFC.
llvm-svn: 266459
2016-04-15 17:57:27 +00:00
George Rimar ea25877d4a [ELF] - Implemented basic location counter support.
This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

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

llvm-svn: 266457
2016-04-15 17:44:19 +00:00
Rafael Espindola 38c67a27fe Store a Symbol for EntrySym.
This makes it impossible to forget to call repl on the SymbolBody.

llvm-svn: 266432
2016-04-15 14:41:56 +00:00
Rafael Espindola 69a38060a8 Don't create relocations for absolute got entries.
llvm-svn: 266427
2016-04-15 12:44:43 +00:00
Rafael Espindola f8f6ad74a0 Don't create relocations for non preemptable absolute symbols.
llvm-svn: 266425
2016-04-15 12:22:22 +00:00
Rafael Espindola 3666025880 Two small related fixes.
* A hidden undefined is not preemptable.
* It is always zero, so we don't need a dynamic reloc for it.

llvm-svn: 266424
2016-04-15 11:57:07 +00:00
Simon Atanasyan 7ac68ccdc0 [ELF] Remove redundant empty line. NFC
llvm-svn: 266421
2016-04-15 09:47:36 +00:00
Rafael Espindola 5ffa13c473 Delete a dead repl.
It is only ever used on symbols taken from the symbol table.

llvm-svn: 266391
2016-04-15 00:15:02 +00:00
Simon Atanasyan 1ca263c890 [ELF][MIPS] Make R_MIPS_LO16 a relative relocation if it references _gp_disp symbol
The _gp_disp symbol designates offset between start of function and 'gp'
pointer into GOT. The following code is a typical MIPS function preamble
used to setup $gp register:

lui    $gp, %hi(_gp_disp)
addi   $gp, $gp, %lo(_gp_disp)

To calculate R_MIPS_HI16 / R_MIPS_LO16 relocations results we use
the following formulas:

%hi(_gp - P + A)
%lo(_gp - P + A + 4),
where _gp is a value of _gp symbol, A is addend, and P current address.

The R_MIPS_LO16 relocation references _gp_disp symbol is always the second
instruction. That is why we need four byte adjustments. The patch assigns
R_PC type for R_MIPS_LO16 relocation and adjusts its addend by 4. That fix
R_MIPS_LO16 calculation.

For details see p. 4-19 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

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

llvm-svn: 266368
2016-04-14 21:10:05 +00:00
Rafael Espindola 7f0b727235 Specialize the symbol table data structure a bit.
We never need to iterate over the K,V pairs, so we can avoid copying the
key as MapVector does.

This is a small speedup on most benchmarks.

llvm-svn: 266364
2016-04-14 20:42:43 +00:00
Rafael Espindola c9157d35d9 Hash symbol names only once per global SymbolBody.
The DenseMap doesn't store hash results. This means that when it is
resized it has to recompute them.

This patch is a small hack that wraps the StringRef in a struct that
remembers the hash value. That way we can be sure it is only hashed
once.

llvm-svn: 266357
2016-04-14 19:17:16 +00:00
Rafael Espindola 3151d89595 Simplify handling of size relocations. NFC.
llvm-svn: 266355
2016-04-14 18:39:44 +00:00
George Rimar 5cfd306e00 Move variables closer to code scopes that uses them. NFC.
llvm-svn: 266340
2016-04-14 17:05:56 +00:00
Rafael Espindola e149b488af Remove the only case where we would relocate a R_386_TLS_TPOFF.
llvm-svn: 266330
2016-04-14 16:05:42 +00:00
Rafael Espindola c1c14a227e Merge duplicated cases. NFC.
llvm-svn: 266328
2016-04-14 15:56:14 +00:00
Rafael Espindola 735bbaa1d9 Add missing typename.
llvm-svn: 266318
2016-04-14 14:40:38 +00:00
George Rimar 8bbff7ec85 [ELF] - Refactoring of end/edata/etext implementation.
Minor refactoring of how end/edata/etext symbols are handled.

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

llvm-svn: 266317
2016-04-14 14:37:59 +00:00
George Rimar 4c2ae3a171 Return back the zero parameter of aggregate initialization in OutputSectionFactory::lookup().
That was removed in r266304, but leads to warnings by Clang.
Thanks to Rafael Espíndola for pointing on that.

Though I think change was legal from point of C++.

llvm-svn: 266306
2016-04-14 14:24:23 +00:00
George Rimar d502f47726 Make OutputSectionFactory::lookup() inline. NFC.
Also I removed the last zero parameter of 
aggregate initialization as it is excessive here.

llvm-svn: 266304
2016-04-14 14:07:54 +00:00
George Rimar 2122168912 Removed excessive line. NFC.
llvm-svn: 266303
2016-04-14 13:56:28 +00:00
George Rimar 0fa18b8923 Reduce expression to single line. NFC.
llvm-svn: 266302
2016-04-14 13:47:04 +00:00
George Rimar ee741cfa5f Clang formated file. NFC.
llvm-svn: 266299
2016-04-14 13:23:02 +00:00
George Rimar 4e8cf85b74 Combine code branch into single line. NFC.
llvm-svn: 266298
2016-04-14 13:00:03 +00:00
Peter Collingbourne 0a68cf50f8 ELF: Do not create copy relocations for references in writable sections.
They are unnecessary, as the dynamic loader can apply the original relocations
directly. This was also resulting in the creation of copy relocations in PIEs.

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

llvm-svn: 266273
2016-04-14 01:48:11 +00:00
Rafael Espindola 3fa7352fc7 Fix warning about unused variable.
llvm-svn: 266232
2016-04-13 19:09:48 +00:00
Rafael Espindola ab14c88984 git-clang-format. NFC.
llvm-svn: 266231
2016-04-13 19:07:40 +00:00
Rafael Espindola f9d3dcf0a8 Don't set MustBeInDynSym for hidden symbols.
llvm-svn: 266230
2016-04-13 19:03:34 +00:00
Adhemerval Zanella 9df0720766 ELF: Implement --dynamic-list
This patch implements the --dynamic-list option, which adds a list of
global symbol that either should not be bounded by default definition
when creating shared libraries, or add in dynamic symbol table in the
case of creating executables.

The patch modifies the ScriptParserBase class to use a list of Token
instead of StringRef, which contains information if the token is a
quoted or unquoted strings. It is used to use a faster search for
exact match symbol name.

The input file follow a similar format of linker script with some
simplifications (it does not have scope or node names). It leads
to a simplified parser define in DynamicList.{cpp,h}.

Different from ld/gold neither glob pattern nor mangled names
(extern 'C++') are currently supported.

llvm-svn: 266227
2016-04-13 18:51:11 +00:00
George Rimar 2a78fceb2c [ELF] - Change -t implementation to print which archive members are used.
Previously each archive file was reported no matter were it's member used or not,
like:
lib/libLLVMSupport.a

Now lld prints line for each used internal file, like:
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/StringSaver.cpp.o)
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/Host.cpp.o)
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o)

That should be consistent with what gold do.

This fixes PR27243.

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

llvm-svn: 266220
2016-04-13 18:07:57 +00:00
Peter Collingbourne f6e9b4ec24 ELF: Use hidden visibility for all DefinedSynthetic symbols.
This simplifies the code by allowing us to remove the visibility argument
to functions that create synthetic symbols.

The only functional change is that the visibility of the MIPS "_gp" symbol
is now hidden. Because this symbol is defined in every executable or DSO, it
would be difficult to observe a visibility change here.

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

llvm-svn: 266208
2016-04-13 16:57:28 +00:00
Peter Collingbourne 1f71d748ae ELF: Do not create relative relocations for undefined symbols.
We need to ensure that the address of an undefined weak symbol evaluates to
zero. We were getting this right for non-PIC executables (where the symbol
can be evaluated directly) and for DSOs (where we emit a symbolic relocation
for these symbols, as they are preemptible). But we weren't getting it right
for PIEs. Probably the simplest way to ensure that these symbols evaluate
to zero is by not creating a relocation in .got for them.

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

llvm-svn: 266161
2016-04-13 02:24:48 +00:00
Rafael Espindola 22ef956a45 Change how we apply relocations.
With this patch we use the first scan over the relocations to remember
the information we found about them: will them be relaxed, will a plt be
used, etc.

With that the actual relocation application becomes much simpler. That
is particularly true for the interfaces in Target.h.

This unfortunately means that we now do two passes over relocations for
non SHF_ALLOC sections. I think this can be solved by factoring out the
code that scans a single relocation. It can then be used both as a scan
that record info and for a dedicated direct relocation of non SHF_ALLOC
sections.

I also think it is possible to reduce the number of enum values by
representing a target with just an OutputSection and an offset (which
can be from the start or end).

This should unblock adding features like relocation optimizations.

llvm-svn: 266158
2016-04-13 01:40:19 +00:00
Peter Collingbourne 173ee84530 ELF: Give automatically generated __start_* and __stop_* symbols hidden visibility.
These symbols describe a property of a linkage unit, so it seems reasonable
to limit their visibility to the linkage unit. Furthermore the use cases I
am aware of do not require more than hidden visibility.

This is a departure from the behavior of the bfd and gold linkers. However,
it is unclear that the decision to give these symbols default visibility
in those linkers was made deliberately. The __start_*/__stop_* feature
was added to the bfd linker in 1994 [1], while the visibility feature was
added about five years later [2], so it may have been that the visibility
of these symbols was not considered. The feature was implemented in gold
[3] in the same way; the behavior may have simply been copied from bfd.

The only related discussion I could find on the binutils mailing list [4]
was a user issue which would most likely not have occurred if the symbols
had hidden visibility.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=5efddb2e7c3229b569a862205f61d42860af678b
[2] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=0fc731e447cd01e7fc35197b487ff0e4fd25afca
[3] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bfd58944a64b0997a310b95fbe0423338961e71c
[4] https://sourceware.org/ml/binutils/2014-05/msg00011.html

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

llvm-svn: 266121
2016-04-12 20:41:42 +00:00
Rafael Espindola 6f92e14ce2 Use DefinedSynthetic for _gp* symbols.
The test changes to put _gp* in the .got section matches what both bfd
and gold do.

llvm-svn: 266067
2016-04-12 13:26:51 +00:00
Rafael Espindola 3a72cc0083 Simplify now that we always have a .got.
llvm-svn: 266064
2016-04-12 13:23:27 +00:00
Rafael Espindola a22b082e46 Always create a .got on mips.
The _gp* family of symbols is defined as an offset in .got, and it is
not at all clear what should happen when .got is not defined.

This will allow some simplifications on how these symbols are handled.

llvm-svn: 266063
2016-04-12 13:21:13 +00:00
Rafael Espindola 9b3f99e50f Devide _gp in the same spot as other mips symbols. NFC.
The test changes are just because of the symbol order.

llvm-svn: 266037
2016-04-12 02:24:43 +00:00
Davide Italiano 15c41b25c7 [LTO] Switch Module to std::unique_ptr<>.
Differential Revision:   http://reviews.llvm.org/D18994

llvm-svn: 266009
2016-04-11 22:39:51 +00:00
Rafael Espindola 8396f72f7b Simplify handling of mips gp* symbols.
Give them values instead of computing it during relocation.

llvm-svn: 265986
2016-04-11 20:34:27 +00:00
Rafael Espindola 03ef404e97 Simplify the creation of __rel[a]_iplt_{start,end}.
They can be regular DefinedSynthetic.

llvm-svn: 265981
2016-04-11 19:14:59 +00:00
Peter Collingbourne c98de13871 ELF: Set FDE count in .eh_frame_hdr correctly.
It is possible to have FDEs with duplicate PCs if ICF was able to merge
functions with FDEs, or if the input files for some reason contained duplicate
FDEs.  We previously weren't handling this correctly when producing the
contents of the .eh_frame_hdr section; we were dropping entries and leaving
null entries at the end of the section, which confused consumers of unwind
data, such as the backtrace() function.

Fix the bug by setting the FDE count to the number of FDEs actually emitted
into .eh_frame_hdr, rather than the number of FDEs in .eh_frame.

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

llvm-svn: 265957
2016-04-11 16:40:08 +00:00
Peter Collingbourne 7cf73ec4c7 ELF: Implement basic support for module asm in bitcode files.
Differential Revision: http://reviews.llvm.org/D18872

llvm-svn: 265956
2016-04-11 16:39:43 +00:00