Commit Graph

100 Commits

Author SHA1 Message Date
Rafael Espindola 666625b78c Pass a const pointer to getImplicitAddend. NFC.
llvm-svn: 265143
2016-04-01 14:36:09 +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
Rafael Espindola 4e5ab42e21 Pass a const SymbolBody to needsGot. NFC.
llvm-svn: 265012
2016-03-31 13:38:28 +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 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
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
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 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 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
Rui Ueyama 9328b2cdde Use ELFT instead of ELFFile<ELFT>.
llvm-svn: 263510
2016-03-14 23:16:09 +00:00
George Rimar cbcda9e077 Remove dead code. NFC.
llvm-svn: 263433
2016-03-14 14:25:28 +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
Rafael Espindola 1f04c44885 Delete isTlsDynRel.
It was a badly specified hack for when a tls relocation should be
propagated to the dynamic relocation table.

This replaces it with a not as bad hack of saying that a local dynamic
tls relocation is never preempted.

I will try to remove even that second hack in the next patch.

llvm-svn: 262955
2016-03-08 20:24:36 +00:00
George Rimar 7b8850f2bd [ELF] - Changed return type of Target::relaxTls()
Patch changes the return type of Target::relaxTls 
to size_t from unsigned. That is consistent with
its use from other code.

Change was reviewed http://reviews.llvm.org/D17882
and asked to commit separately from that patch above.

llvm-svn: 262794
2016-03-06 06:09:50 +00:00
George Rimar 98b060d228 [ELF] - Use the uint32_t instead of unsigned in Target class for relocations types
Patch changes all relocations types to be uint32_t and also 
fixes some dependent inconsistency in callers code.

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

llvm-svn: 262793
2016-03-06 06:01:07 +00:00
Rafael Espindola d405f4721c Refactor target independent code.
The rules for when we can relax tls relocations are target independent.
The only things that are target dependent are the relocation values.

llvm-svn: 262748
2016-03-04 21:37:09 +00:00
Rafael Espindola 1ea51d2718 Refactor duplicated code.
llvm-svn: 262720
2016-03-04 16:14:19 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +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 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 f7ae359d2c Simplify. NFC.
llvm-svn: 261668
2016-02-23 18:53:29 +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 852860e920 make needsPlt a pure predicate.
llvm-svn: 260685
2016-02-12 15:47:37 +00:00
Adhemerval Zanella 74bcf03f87 [lld] [ELF/AArch64] Add support to some GD/LE/IS TLS relocations
This patch adds some TLS relocations and relaxations for AArch64.
Some Global-Dynamic relocation are handled by optimizing them to
Local-Exec (Initial-Exec is not yet supported). They are:

 - R_AARCH64_TLSDESC_ADR_PAGE21
 - R_AARCH64_TLSDESC_LD64_LO12_NC
 - R_AARCH64_TLSDESC_ADD_LO12_NC
 - R_AARCH64_TLSDESC_CALL

Also some Init-Exec is optimized to Local-Exec if possible. They are:

 - R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
 - R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC

Finally some Local-Exec relocation are handled in relocateOne:

 - R_AARCH64_TLSLE_ADD_TPREL_HI12
 - R_AARCH64_TLSLE_ADD_TPREL_LO12_NC

This work is mainly for compiler bootstrap, where static binaries is
showing good progress (although shared object still lacking support
from both TLS aarch64 backend and some other issues).

llvm-svn: 260677
2016-02-12 13:43:03 +00:00
Rui Ueyama c1c282a04e ELF: Release Target at end of link().
Previously, Target held a value until a new value is assigned to the
variable. That was a benign leak -- that was not an unbounded leak
and didn't grab any resources except a small amount of memory. But
it is better to fix than leaving as is.

llvm-svn: 260592
2016-02-11 21:18:01 +00:00
George Rimar 2960c9867a [ELF] - Remove R_X86_64_GOTTPOFF from static relocation processing
R_X86_64_TPOFF64 is a dynamic relocation,
it should not appear in static relocation processing.
Patch fixes it.

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

llvm-svn: 260508
2016-02-11 11:14:46 +00:00
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 4b03451cac [ELF][MIPS] Replace needsMipsLocalGot function by canBePreempted
Symbol does not need an entry i the 'global' part of GOT if it cannot be
preempted. So canBePreempted fully satisfies us at least for now.

llvm-svn: 259779
2016-02-04 11:51:45 +00:00
Rui Ueyama 9398f86a2a Remove a parameter from Target::writePlt.
llvm-svn: 259158
2016-01-29 04:15:02 +00:00
Rui Ueyama 012eb783b3 ELF: Provide default implemenatations for simple functions.
llvm-svn: 259157
2016-01-29 04:05:09 +00:00
Rui Ueyama 57b676c546 Define stub functions instead of pure virtual functions.
To remove empty functions.

llvm-svn: 259155
2016-01-29 03:51:51 +00:00
Rui Ueyama 900e2d2578 ELF: Do not pass addresses that can be obtained using Out.
llvm-svn: 259154
2016-01-29 03:51:49 +00:00
Rui Ueyama 6251545683 Rename PltZeroEntrySize -> PltZeroSize.
This patch also fixes parameter name. They points to the beginning
of PLT or GOT tables, so GotAddr or PltAddr are better.)

llvm-svn: 259150
2016-01-29 03:00:32 +00:00
Rui Ueyama 69c30edb5e Add a comment.
llvm-svn: 259149
2016-01-29 03:00:30 +00:00
Rui Ueyama c516ae1719 ELF: Make Target's member function names shorter.
llvm-svn: 259147
2016-01-29 02:33:45 +00:00
Rui Ueyama 724d625c7a ELF: Remove accessors from Target.
These accessors do not provide values. We can simply make the variables public.

llvm-svn: 259141
2016-01-29 01:49:32 +00:00
Rui Ueyama 74b7df016f Remove unused variable.
llvm-svn: 259140
2016-01-29 01:49:29 +00:00
Rui Ueyama baf16512ea Rename isTlsOptimized -> canRelaxTls.
This function is a predicate that a given relocation can be relaxed.
The previous name implied that it returns true if a given relocation
has already been optimized away.

llvm-svn: 259128
2016-01-29 00:20:12 +00:00
George Rimar 237b218770 [ELF] - fix possible UB when dereferencing null
In InputSection.cpp it was possible to dereference null.
Had to change signature of relocateTlsOptimize to accept pointer instead of reference.

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

llvm-svn: 258508
2016-01-22 18:02:28 +00:00
Simon Atanasyan 56ab5f0289 [ELF][MIPS] Initial support of MIPS local GOT entries
Some MIPS relocation (for now R_MIPS_GOT16) requires creation of GOT
entries for symbol not included in the dynamic symbol table. They are
local symbols and non-local symbols with 'local' visibility. Local GOT
entries occupy continuous block between GOT header and regular GOT
entries.

The patch adds initial support for handling local GOT entries. The main
problem is allocating local GOT entries for local symbols. Such entries
should be initialized by high 16-bit of the symbol value. In ideal world
there should be no duplicated entries with the same values. But at the
moment of the `Writer::scanRelocs` call we do not know a value of the
symbol. In this patch we create new local GOT entry for each relocation
against local symbol, though we can exhaust GOT quickly. That needs to
be optimized later. When we calculate relocation we know a final symbol
value and request local GOT entry index. To do that we maintain map
between addresses and local GOT entry indexes. If we start to calculate
relocations in parallel we will have to serialize access to this map.

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

llvm-svn: 258388
2016-01-21 05:33:23 +00:00
Simon Atanasyan 682aeea9de [ELF][MIPS] Ignore 'hint' relocations like R_MIPS_JALR in the `scanRelocs` method
MIPS ABI has relocations like R_MIPS_JALR which is just a hint for
linker to make some code optimization. Such relocations should not be
handled as a regular ones and lead to say dynamic relocation creation.

The patch introduces new virtual `Target::isHintReloc` method, overrides
it in the `MipsTargetInfo` class and calls it in the `Writer<ELFT>::scanRelocs`
method.

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

llvm-svn: 257798
2016-01-14 20:42:09 +00:00
Rui Ueyama b705b10012 ELF: Remove dead code.
R_X86_64_PLT32 is handled in the same way as R_X86_64_PC32 by
relocateOne(), so this function does not seems to be needed.
Without this code, all tests still pass.

http://reviews.llvm.org/D15971

llvm-svn: 257203
2016-01-08 20:11:47 +00:00
Rui Ueyama 2b0edc2fdc Add a comment.
llvm-svn: 257140
2016-01-08 02:41:35 +00:00
Rui Ueyama 3a7c2f6f44 ELF: Simplify Target::isSizeReloc and add comments.
All non-trivial relocation decisions need explanations like this
to help readers understand not only how relocations are handled but
why they are handled these ways. This is a start.

llvm-svn: 257119
2016-01-08 00:13:23 +00:00
George Rimar a07ff66112 [ELF] - Implemented R_*_IRELATIVE relocations for x86, x64 targets.
This relocation is similar to R_*_RELATIVE except that the value used in this relocation is the program address returned by the function, which takes no arguments, at the address of
the result of the corresponding R_*_RELATIVE relocation as specified in the processor-specific ABI. The purpose of this relocation to avoid name lookup for locally defined STT_GNU_IFUNC symbols at load-time.

More info can be found in ifunc.txt from https://sites.google.com/site/x32abi/documents.

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

llvm-svn: 256144
2015-12-21 10:12:06 +00:00
George Rimar bfb7bf7429 [ELF] - R_386_GOTOFF relocation implemented.
R_386_GOTOFF is calculated as S + A - GOT, where:
S - Represents the value of the symbol whose index resides in the relocation entry.
A - Represents the addend used to compute the value of the relocatable field.
GOT - Represents the address of the global offset table.

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

llvm-svn: 256143
2015-12-21 10:00:12 +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
Rui Ueyama 02dfd496b0 ELF: Rename relocNeedsCopy -> needsCopyRel
Just "copy" was a bit too ambiguous to say about copy relocations.

llvm-svn: 255866
2015-12-17 01:18:40 +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
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