Commit Graph

24 Commits

Author SHA1 Message Date
Rafael Espindola a0a65f973a Use the plt entry as the address of some symbols.
This is the function equivalent of a copy relocation.

Since functions are expected to change sizes, we cannot use copy
relocations. In situations where one would be needed, what is done
instead is:
* Create a plt entry
* Output an undefined symbol whose addr is the plt entry.

The dynamic linker makes sure any shared library uses the plt entry as
the function address.

llvm-svn: 260224
2016-02-09 15:11:01 +00:00
Simon Atanasyan e1bfc2e793 [ELF][MIPS] Support R_MIPS_COPY relocation
Generate R_MIPS_COPY relocation for 'static' relocations against object
symbols defined in a shared libraries.

llvm-svn: 260083
2016-02-08 10:05:13 +00:00
Sean Silva 09247f8955 Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
Summary:
LLVM3.3 (and earlier) would fail to include a relocation section in
the group that the section it was relocating is in. Object files
affected by this issue have been encountered in the wild when using LLD.

This would result in a siutation like:

  Section {
    Index: 5
    Name: .text._Z3fooIiEvv (6)
    Type: SHT_PROGBITS (0x1)
    Flags [ (0x206)
      SHF_ALLOC (0x2)
      SHF_EXECINSTR (0x4)
      SHF_GROUP (0x200)
    ]
    Address: 0x0
    Offset: 0x48
    Size: 5
    Link: 0
    Info: 0
    AddressAlignment: 1
    EntrySize: 0
  }
  Section {
    Index: 6
    Name: .rela.text._Z3fooIiEvv (1)
    Type: SHT_RELA (0x4)
    Flags [ (0x0)
    ]
    Address: 0x0
    Offset: 0x3F0
    Size: 24
    Link: 8
    Info: 5
    AddressAlignment: 8
    EntrySize: 24
  }

In LLD, during symbol resolution, we discard the section containing the
weak symbol, but this amounts to replacing it with
InputSection<ELFT>::Discarded.
When we later saw the corresponding relocation section, we would then
end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is
bogus.

Reviewers: ruiu, rafael

Subscribers: llvm-commits, Bigcheese

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

llvm-svn: 259831
2016-02-04 21:41:07 +00:00
Rui Ueyama 71c066d8cf ELF: Include archive names in error messages.
If object files are drawn from archive files, the error message should
be something like "conflict symbols in foo.a(bar.o) and baz.o" instead
of "conflict symbols in bar.o and baz.o". This patch implements that.

llvm-svn: 259475
2016-02-02 08:22:41 +00:00
George Rimar 02ca17906d [ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.
Main executable did not export symbols that exist both in the main executable and in DSOs before this patch.
Symbols from object files that override symbols in DSO should be added to .dynsym table.

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

llvm-svn: 258672
2016-01-25 08:44:38 +00:00
Rafael Espindola 0bc0c02387 Prefer symbols from .o over .so.
This matches the behavior of gold and bfd ld.

llvm-svn: 258102
2016-01-18 23:54:05 +00:00
George Rimar f6bc65a3b2 Reapply r257753 with fix:
Added check for terminator CIE/FDE which has zero data size.
void EHOutputSection<ELFT>::addSectionAux(
...
 // If CIE/FDE data length is zero then Length is 4, this
 // shall be considered a terminator and processing shall end.
    if (Length == 4)
      break;
...

After this "Bug 25923 - lld/ELF2 linked application crashes if exceptions were used." is fixed for me. Self link of clang also works.

Initial commit message:
[ELF] - implemented --eh-frame-hdr command line option.

--eh-frame-hdr
Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header.

Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr.
This section contains a lookup table for quick binary search of FDEs.
Detailed info can be found here:
http://www.airs.com/blog/archives/462

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

llvm-svn: 257889
2016-01-15 13:34:52 +00:00
Rui Ueyama 5f91ace828 Revert r257753: "[ELF] - implemented --eh-frame-hdr command line option."
This reverts commit r257753 because we cannot link Clang with this patch.

llvm-svn: 257797
2016-01-14 20:32:19 +00:00
George Rimar 28f4fbe480 [ELF] - implemented --eh-frame-hdr command line option.
--eh-frame-hdr
Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header.

Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr.
This section contains a lookup table for quick binary search of FDEs.
Detailed info can be found here:
http://www.airs.com/blog/archives/462

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

llvm-svn: 257753
2016-01-14 10:30:32 +00:00
George Rimar 3d737e45c0 Reapply r257588
Fix: Added missed input file.

Initial commit message:
[ELF/AArch64] - Implemented R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 and R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC relocations

* R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 is calculated as Page(G(GTPREL(S+A))) – Page(P), set an ADRP immediate field to bits [32:12] of X; check –2^32 ≤ X < 2^32;
* R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC is calculated as G(GTPREL(S+A)), set an LD offset field to bits [11:3] of X. No overflow check; check that X&7 = 0.

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

llvm-svn: 257596
2016-01-13 13:04:46 +00:00
Simon Atanasyan 49f98c742c [ELF][MIPS] Do not use 'sed' to modify binary files
On Windows different versions of 'sed' work in different text/binary
mode by default. If default mode is text, sed produces corrupted binary
files. Unfortunately there is no standard command line option to select
the mode. Some 'sed' support '-b' to switch to binary mode, while other
ones support '--text' option and does not have '-b' option at all.

llvm-svn: 257471
2016-01-12 12:38:43 +00:00
Simon Atanasyan 188558e5eb [ELF][MIPS] Prevent substitution of _gp_disp symbol
On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
start of function and gp pointer into GOT. To make seal with such symbol
we add new method addIgnoredStrong(). It adds ignored symbol with global
binding to prevent the symbol substitution. The addIgnored call is not
enough here because this call adds a weak symbol which might be
substituted by symbol from shared library.

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

llvm-svn: 257449
2016-01-12 06:23:57 +00:00
George Rimar 1395dbdbc6 [ELF/AARCH64] - Implemented R_AARCH64_TSTBR14 relocation.
R_AARCH64_TSTBR14 is calculated as S+A-P,
Set the immediate field of a TBZ/TBNZ instruction to bits [15:2] of X; check -2^15 ≤ X < 2^15

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

llvm-svn: 257334
2016-01-11 14:27:05 +00:00
George Rimar 4102bfbe71 [ELF/AARCH64] - Implemented R_AARCH64_CONDBR19 relocation.
R_AARCH64_CONDBR19 is calculated as S+A-P,
Set the immediate field of a conditional branch instruction to bits [20:2] of X; check -2^20 ≤ X< 2^20.

Afaik there is no document for AARCH64 instruction encoding from official for unknown reason, so 
I used gold source code and next link as a reference for implementation: http://kitoslab-eng.blogspot.ru/2012/10/armv8-aarch64-instruction-encoding.html. From which is clear that immediate field of a conditional branch instruction is 5 bits off. That is proved by output which is is equal to gold/bfd now.

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

llvm-svn: 257333
2016-01-11 14:22:00 +00:00
Rui Ueyama deb154001d ELF: Implement --wrap.
In this patch, all symbols are resolved normally and then wrap options
are applied. Renaming is implemented by mutating `Body` pointers of
Symbols. (As a result, Symtab.find(SymbolName)->getName() may return
a string that's different from SymbolName, but that is by design.
I designed the symbol and the symbol table to allow this kind of
operations.)

http://reviews.llvm.org/D15896

llvm-svn: 257075
2016-01-07 17:20:07 +00:00
George Rimar 6f17e09307 [ELF] - implemented @indntpoff (x86) relocation and its optimization.
@indntpoff is similar to @gotntpoff, but for use in position dependent code. While @gotntpoff resolves to GOT slot address relative to the
start of the GOT in the movl or addl instructions, @indntpoff resolves to the
absolute GOT slot address. ("ELF Handling For Thread-Local Storage", Ulrich Drepper).

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

llvm-svn: 255884
2015-12-17 09:32:21 +00:00
Rafael Espindola 2992563b93 Treat unnamed symbols as locals.
There is work under way in llvm to avoid creating unnecessary names for
symbols. This makes lld capable of handling that.

llvm-svn: 255357
2015-12-11 19:09:21 +00:00
George Rimar 48651489b3 [ELF] - R_X86_64_SIZE64/R_X86_64_SIZE32 relocations implemented.
R_X86_64_SIZE64/R_X86_64_SIZE32 relocations were introduced in 0.98v of "System V Application Binary Interface x86-64" (http://www.x86-64.org/documentation/abi.pdf).

Calculation for them is Z + A, where:
Z - Represents the size of the symbol whose index resides in the relocation entry.
A - Represents the addend used to compute the value of the relocatable field.

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

llvm-svn: 255332
2015-12-11 08:59:37 +00:00
Rafael Espindola 69d1ca6af2 Fix alignment computation for copy relocs.
Fixes PR25798.

Thanks to Ed Maste for the bug report and suggested fix.

llvm-svn: 255307
2015-12-10 22:53:24 +00:00
George Rimar 2558e12bac [ELF] - Implement the TLS relocation optimization for 32-bit x86.
Implement the TLS relocation optimization for 32-bit x86 that is described in
"ELF Handling For Thread-Local Storage" by Ulrich Drepper, chapter 5,
"IA-32 Linker Optimizations". Specifically, this patch implements these
optimizations: LD->LE, GD->IE, GD->LD, and IE->LE.

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

llvm-svn: 255103
2015-12-09 09:55:54 +00:00
George Rimar 25411f2558 [ELF] - Implemented @tlsgd optimization (GD->IE case, x64).
"Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5 x86-x64 linker optimizations, http://www.akkadia.org/drepper/tls.pdf) shows how GD can be optimized to IE.
This patch implements the optimization.

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

llvm-svn: 254713
2015-12-04 11:20:13 +00:00
Igor Kudrin 9606d19a65 [ELF/AArch64] Support R_AARCH64_COPY relocation.
Generate R_AARCH64_COPY relocations for non-GOT relocations,
which reference object symbols from shared libraries.

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

llvm-svn: 254591
2015-12-03 08:05:35 +00:00
Igor Kudrin fea8ed50ef [ELF/AArch64] Fix overflow checks for R_AARCH64_{ABS,PREL}{16,32} relocations.
ABI specifies the allowed range for these relocations as 2^(n-1) <= X < 2^n.

The patch fixes checks and introduces precise tests for these relocations.

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

llvm-svn: 254146
2015-11-26 10:05:24 +00:00
Rafael Espindola 4b1285c55a Rename test/elf2 to test/ELF.
llvm-svn: 253313
2015-11-17 05:36:42 +00:00