Commit Graph

5094 Commits

Author SHA1 Message Date
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 29d8eef440 Rename so that the function name is consistent between ELF and COFF.
llvm-svn: 261914
2016-02-25 18:49:11 +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 1c576054cb Make test more portable.
We just need to show that an error is printed, so no need to check for a
system dependent message.

llvm-svn: 261802
2016-02-24 22:47:41 +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
George Rimar cb2aeb66e4 [ELF] - Teach input section wildcard patterns to recognize '?' meta character.
`?' - matches any single character
https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html

This is used in linker scripts.

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

llvm-svn: 261726
2016-02-24 08:49:50 +00:00
Rui Ueyama 5ac589171d ELF: Remove InputSectionBase::getAlign and instead add Align member.
This is a preparation for ICF. If we merge two sections, we want to
align the merged section at the largest alignment requirement.
That means we want to update the alignment value, which was
impossible before this patch because Header is a const value.

llvm-svn: 261712
2016-02-24 00:38:18 +00:00
Rui Ueyama 8fc070d64d ELF: Remove InputSectionBase::isLive and use Live member instead. NFC.
This is also a preparation for ICF.

llvm-svn: 261711
2016-02-24 00:23:15 +00:00
Rui Ueyama d7e4a281c4 ELF: Make some functions constant. NFC.
This is a preparation for ICF.

llvm-svn: 261710
2016-02-24 00:23:13 +00:00
Rui Ueyama 436d91d835 COFF: Temporarily remove flaky a test.
This test is flaky for more than half a year or so on buildbots
and has been causing confusion. Remove it while I'm investing the
cause.

llvm-svn: 261709
2016-02-24 00:23:11 +00:00
Rafael Espindola d5b688c8e8 Use a different error in test.
This opens the way for -r being implemented.

llvm-svn: 261682
2016-02-23 20:36:20 +00:00
Rafael Espindola 435c00f39c Fix the aarch64 logic for dynamic relocations.
There is nothing aarch64 specific in here. If a symbol can be preempted,
we need to copy the full relocation to the dynamic linker.

If a symbol cannot be preempted, we can make the dynamic linker life
easier and produce a relative relocation.

This is directly equivalent to R_X86_64_64 to R_x86_64_RELATIVE
conversion.

llvm-svn: 261678
2016-02-23 20:19:44 +00:00
Rafael Espindola f7ae359d2c Simplify. NFC.
llvm-svn: 261668
2016-02-23 18:53:29 +00:00
Rafael Espindola 75baf09be5 Don't include tbss's alignment in offset.
The .tbss section is in the middle of a PT_LOAD. Whatever treatment we
give to its address we must also give to the offset.

We were ignoring it for address computations, but not for offset.

Fixes pr26712.

llvm-svn: 261667
2016-02-23 18:39:55 +00:00
Rui Ueyama c89bff2ce1 Handle bitcode files in archive files with --whole-archive.
This patch moves BitcodeFile instantiation into createObjectFile.
Previously, we handle bitcode files outside that function and did
not handle for --whole-archive.

http://reviews.llvm.org/D17527

llvm-svn: 261663
2016-02-23 18:17:11 +00:00
Adhemerval Zanella 668ad0ffcb [lld] [ELF/AArch64] Fix R_AARCH64_ABS64 in Shared mode
This patch fixes the R_AARCH64_ABS64 relocation when used in shared mode,
where it requires a dynamic R_AARCH64_RELATIVE relocation. To correct set
the addend on the dynamic relocation (since it will be used by the dynamic
linker), a new TargetInfo specific hook was created (getDynRelativeAddend)
to get the correct addend based on relocation type.

The patch fixes the issues when creating shared library code against
{init,fini}_array, where it issues R_AARCH64_ABS64 relocation against
local symbols.

llvm-svn: 261651
2016-02-23 16:54:40 +00:00
Simon Atanasyan 7862c173c3 [ELF][MIPS] Rename test case. NFC
llvm-svn: 261617
2016-02-23 08:34:18 +00:00
George Rimar 481c2ce64b [ELF] - Linkerscript KEEP command.
When link-time garbage collection is in use (-gc-sections), it is 
often useful to mark sections that should not be eliminated. 
This is accomplished by surrounding an input section's wildcard 
entry with KEEP(). Patch implements that command.

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

llvm-svn: 261616
2016-02-23 07:47:54 +00:00
Rui Ueyama c00718fd8e Use TinyPtrVector<Ty *> instead of SmallVector<Ty *, 1>.
Thanks to Sean Silva for the suggestion.

llvm-svn: 261606
2016-02-23 03:34:37 +00:00
Rafael Espindola 8176d57d62 Handle a weak undefined tls to archive member.
A weak undefined should not fetch archive members, so we have to keep
the Lazy symbol.

That means the lazy symbol has to encode information about the original
weak undef.

Fixes pr25762.

llvm-svn: 261591
2016-02-22 23:19:29 +00:00
Rafael Espindola 5e8b54afdb Remove a trivial getter.
llvm-svn: 261590
2016-02-22 23:16:05 +00:00
Rafael Espindola fb1533b326 Don't create copy relocs in shared libraries.
This fixes PR26699.

llvm-svn: 261576
2016-02-22 21:23:29 +00:00
Rafael Espindola 56da313e86 Correctly handle two gd relocations to the same symbol.
Fixes PR26676.

llvm-svn: 261561
2016-02-22 19:57:55 +00:00
Rafael Espindola 6feecec0b0 Handle undef symbols in LTO.
This also handles bc files is archives.

llvm-svn: 261374
2016-02-19 22:50:16 +00:00
Rafael Espindola 7efa5be205 Add support for merging strings with alignment larger than one char.
This reduces the .rodata of scyladb from 4501932 to 4334639 bytes (1.038
times smaller).

I don't think it is critical to support tail merging, just exact
duplicates, but given the code organization it was actually a bit easier
to support both.

llvm-svn: 261327
2016-02-19 14:17:40 +00:00