Commit Graph

1906 Commits

Author SHA1 Message Date
Rafael Espindola 37bcaac179 Add support for common symbols.
llvm-svn: 262848
2016-03-07 19:15:57 +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
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
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
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 a1ee70ba75 Allow joined options to fix http://llvm.org/pr26730.
llvm-svn: 262550
2016-03-03 00:09:02 +00:00
Rui Ueyama a0e9806101 Use ld.lld instead of "lld -flavor gnu".
llvm-svn: 262518
2016-03-02 21:11:36 +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 1054ae7e1e Remove CoreDriver.
CoreDriver implements a driver for a hypothetical platform.
It is intended to be used in unittests. However, it is actually
redundant because the features are tested using the real driver
for the real platforms. So we can remove this.

http://reviews.llvm.org/D17698

llvm-svn: 262421
2016-03-01 23:44:05 +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 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 9907eb0b0a Produce PT_NOTE program headers.
llvm-svn: 262331
2016-03-01 13:23:29 +00:00
Paul Robinson 2ce5cf0393 Fix LLD tests that used CHECK-NEXT-NOT. FileCheck does not support
combined suffixes.

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

llvm-svn: 262237
2016-02-29 18:05:21 +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
Rafael Espindola c778aa4a30 Delete more COFF and ELF bits from the old linker.
llvm-svn: 262184
2016-02-28 16:27:08 +00:00
Rafael Espindola fd14979812 Delete more ELF bits from the old linker.
llvm-svn: 262181
2016-02-28 16:03:37 +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 d3926f940a Delete the old script parser.
It was ELF specific.

llvm-svn: 262163
2016-02-28 02:14:48 +00:00
Rafael Espindola 3a4d0a7c17 Remove the old ELF linker.
I think it is clear by now that the new linker is viable.

llvm-svn: 262158
2016-02-28 00:10:58 +00:00
Rafael Espindola 18f0950783 Report duplicated symbols in bitcode.
llvm-svn: 262076
2016-02-26 21:49:38 +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 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
Rafael Espindola e3fda8a19d Add a newline at the end of the file.
llvm-svn: 261964
2016-02-26 03:17:25 +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
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
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
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