Commit Graph

746 Commits

Author SHA1 Message Date
George Rimar c7dc0be36a Reapply fixed r255626 that broke buildbot:
[ELF] - refactor of code in RelocationSection<ELFT>::writeTo()

Just a little reformat of 'if' conditions, NFC.

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

Fix was:
* Renamed unsigned Rel; to unsigned Reloc;

llvm-svn: 255631
2015-12-15 08:48:39 +00:00
George Rimar b076446368 Revert of r255626 "[ELF] - refactor of code in RelocationSection<ELFT>::writeTo()"
as it broke buildbot: 
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/17836/steps/build_Lld/logs/stdio
/Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/tools/lld/ELF/OutputSections.cpp:268:14: error: redefinition of 'Rel'
    unsigned Rel;   ^
/Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/tools/lld/ELF/OutputSections.cpp:241:34: note: previous definition is here
  for (const DynamicReloc<ELFT> &Rel : Relocs) {

That compiles fine on my MSVS 2015 thought.

llvm-svn: 255628
2015-12-15 08:39:42 +00:00
George Rimar e3556420c1 [ELF] - refactor of code in RelocationSection<ELFT>::writeTo()
Just a little reformat of 'if' conditions, NFC.

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

llvm-svn: 255626
2015-12-15 08:23:08 +00:00
Simon Atanasyan 350311974b [ELF][MIPS] Remove applying the redundant bit-mask
The `mipsHigh` return type is `uint16_t` so we do not need to extract
low 16-bits from return value explicitly.

llvm-svn: 255622
2015-12-15 06:06:34 +00:00
Simon Atanasyan e4361859c0 [ELF][MIPS] Ignore R_MIPS_JALR relocation for now
The `R_MIPS_JALR` is a relocation generated by gcc and gas. This
relocation points to the `jalr` instruction which might be optimized and
converted to the `b` instruction under some conditions.

Now we just ignore this relocation and keep instructions unchanged.

llvm-svn: 255453
2015-12-13 06:49:14 +00:00
Simon Atanasyan dddbeb7a46 [ELF][MIPS] Match paired relocation using relocation type and symbol index
If we have R_MIPS_HI16 relocation, the paired relocation is the next
R_MIPS_LO16 relocation with the same symbol as a target.

llvm-svn: 255452
2015-12-13 06:49:08 +00:00
Simon Atanasyan 2cd670da02 [ELF][MIPS] Fix calculation of the R_MIPS_HI16 relocation
llvm-svn: 255451
2015-12-13 06:49:01 +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
Rafael Espindola a6763e8386 Discard local symbols from SHF_MERGE sections.
This matches the behavior of both gold and bfd ld.

llvm-svn: 255355
2015-12-11 18:49:29 +00:00
Ed Maste f2ac688217 ELF: Allow -e <entry> with -shared
It is reasonable to specify an entry point for shared objects - for
example, for the FreeBSD rtld ld-elf.so.1.

Unlike GNU ld we leave the entry address as 0 if -shared is specified
without -e.

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

llvm-svn: 255349
2015-12-11 17:46:46 +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
Rui Ueyama 01faef0ddc Simplify. NFC.
llvm-svn: 255284
2015-12-10 19:19:04 +00:00
Rui Ueyama ccfc3261f3 Simplify an expression. NFC.
llvm-svn: 255282
2015-12-10 19:13:08 +00:00
Ed Maste 3261be4b8d Add --version-script= alias for --version-script
llvm-svn: 255249
2015-12-10 14:08:45 +00:00
George Rimar a5fbebc206 [ELF] - Implemented --print-gc-sections command line argument.
List all sections removed by garbage collection. This option is only effective if garbage collection has been enabled via the `--gc-sections' option.

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

llvm-svn: 255235
2015-12-10 09:12:18 +00:00
George Rimar b72a9c6f02 [ELF] - Resolve R_386_PLT32 statically in some cases.
If R_386_PLT32 relocation is applied against symbol that can not be preempted then it can be resolved statically.
Patch implements it for x86 target.

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

llvm-svn: 255233
2015-12-10 09:03:39 +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 c55b4e25f4 [ELF] - fixed mistype in comment, NFC.
llvm-svn: 254918
2015-12-07 16:54:56 +00:00
George Rimar 95c1a58539 Renamed addLocalModelTlsIndex() -> addCurrentModuleTlsIndex(), NFC.
(per discussion with Michael Spencer)

llvm-svn: 254896
2015-12-07 08:02:20 +00:00
Igor Kudrin cfe47f5b32 [ELF/AArch64] Allow only valid dynamic relocations in the output.
All relocations, which cannot be handled by the dynamic linker,
cause a linking error "rebuild with -fPIC".

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

llvm-svn: 254840
2015-12-05 06:20:24 +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
Rui Ueyama 7ee3cf7d61 Fix style by sorting switch-cases.
llvm-svn: 254649
2015-12-03 20:59:51 +00:00
Rui Ueyama 24e39525d0 Remove redundant namespace specifiers.
llvm-svn: 254648
2015-12-03 20:57:45 +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
George Rimar 9db204af65 [ELF] - Implemented some GD, LD and IE TLS access models for x86 target.
Main aim of the patch to introduce basic support for TLS access models for x86 target.
Models using @tlsgd, @tlsldm and @gotntpoff are implemented.

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

llvm-svn: 254500
2015-12-02 09:58:20 +00:00
Simon Atanasyan 09b3e3685f [ELF] MIPS paired R_MIPS_HI16/LO16 relocations support
Some MIPS relocations including `R_MIPS_HI16/R_MIPS_LO16` use combined
addends. Such addend is calculated using addends of both paired relocations.
Each `R_MIPS_HI16` relocation is paired with the next `R_MIPS_LO16`
relocation. ABI requires to compute such combined addend in case of REL
relocation record format only.

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

This patch implements lookup of the next paired relocation suing new
`InputSectionBase::findPairedRelocLocation` method. The primary
disadvantage of this approach is that we put MIPS specific logic into
the common code. The next disadvantage is that we lookup `R_MIPS_LO16`
for each `R_MIPS_HI16` relocation, while in fact multiple `R_MIPS_HI16`
might be paired with the single `R_MIPS_LO16`. From the other side
this way allows us to keep `MipsTargetInfo` class stateless and implement
later relocation handling in parallel.

This patch does not support `R_MIPS_HI16/R_MIPS_LO16` relocations against
`_gp_disp` symbol. In that case the relocations use a special formula for
the calculation. That will be implemented later.

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

llvm-svn: 254461
2015-12-01 21:24:45 +00:00
George Rimar 90cd0a8234 [ELF] - Fixed bug leading to miss of tls relocation when @tlsgd and @gottpoff relocations were used at the same time.
Combination of @tlsgd and @gottpoff at the same time leads to miss of R_X86_64_TPOFF64 dynamic relocation. Patch fixes that.

@tlsgd(%rip) - Allocate two contiguous entries in the GOT to hold a tls index
structure (for passing to tls get addr).
@gottpoff(%rip) - Allocate one GOT entry to hold a variable offset in initial TLS
block (relative to TLS block end, %fs:0).

The same situation can be observed for x86 (probably others too, not sure) with corresponding for that target relocations: @tlsgd, @gotntpoff.

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

llvm-svn: 254443
2015-12-01 19:20:26 +00:00
George Rimar b17f739808 Reapply r254428.
Fix was:
uint32_t getLocalTlsIndexVA() { return getVA() + LocalTlsIndexOff; }
=>
uint32_t getLocalTlsIndexVA() { return Base::getVA() + LocalTlsIndexOff; }
Both works for my MSVS.

Original commit message:
[ELF] - Refactor of tls_index implementation for tls local dynamic model.

Patch contains the next 2 changes:
1) static variable Out<ELFT>::LocalModuleTlsIndexOffset moved to Out<ELFT>::Got. At fact there is no meaning for it to be separated from GOT class because at each place of using it anyways needs to call GOT`s getVA(). Also it is impossible to have that offset and not have GOT.
2) addLocalModuleTlsIndex -> addLocalModelTlsIndex (word "Module" changed to "Model"). Not sure was it a mistype or not but I think that update is closer to Urlich terminology.

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

llvm-svn: 254433
2015-12-01 18:24:07 +00:00
George Rimar 60849f2913 revert r254428 [ELF] - Refactor of tls_index implementation for tls local dynamic model.
It failed buildbot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/3782/steps/build/logs/stdio

Target.cpp
In file included from /home/buildbot/Buildbot/Slave/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/lld/ELF/Target.cpp:20:
/home/buildbot/Buildbot/Slave/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/lld/ELF/OutputSections.h:136:42: error: use of undeclared identifier 'getVA'
  uint32_t getLocalTlsIndexVA() { return getVA() + LocalTlsIndexOff; }

llvm-svn: 254432
2015-12-01 18:11:16 +00:00
George Rimar b8bfd25239 [ELF] - Target interface simplification, getGotRefReloc() removed.
Removes Target::getGotRefReloc() method to simplify Target class a little.

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

llvm-svn: 254429
2015-12-01 17:52:40 +00:00
George Rimar 0ec3f306d4 [ELF] - Refactor of tls_index implementation for tls local dynamic model.
Patch contains the next 2 changes:
1) static variable Out<ELFT>::LocalModuleTlsIndexOffset moved to Out<ELFT>::Got. At fact there is no meaning for it to be separated from GOT class because at each place of using it anyways needs to call GOT`s getVA(). Also it is impossible to have that offset and not have GOT.
2) addLocalModuleTlsIndex -> addLocalModelTlsIndex (word "Module" changed to "Model"). Not sure was it a mistype or not but I think that update is closer to Urlich terminology.

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

llvm-svn: 254428
2015-12-01 17:45:31 +00:00
Igor Kudrin b4a0927853 [ELF] Rearrange relocation codes in natural order. NFC.
Differential revision: http://reviews.llvm.org/D15045

llvm-svn: 254393
2015-12-01 08:41:20 +00:00
Rui Ueyama f6ed550f5e Remove extraneous parentheses.
llvm-svn: 254345
2015-11-30 23:20:22 +00:00
Rui Ueyama 28a661ec80 ELF: Make comments consistent.
In other places, we don't have the comment. Absence of check{Int,UInt}
is the sign that no overflow check is needed.

llvm-svn: 254326
2015-11-30 21:00:53 +00:00
George Rimar 5828c2319e [ELF] - Split RelocationSection<ELFT>::writeTo function.
Splitted writeTo to separate tls relocs handling stuff which is too long for one method now. NFC.

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

llvm-svn: 254309
2015-11-30 17:49:19 +00:00
George Rimar cc06a6ffd3 Fixed potential crash on non-ELF64LE targets.
Incorrect template specialization was used (generic ELFT type was expected but platform specific was used).

llvm-svn: 254253
2015-11-29 14:14:20 +00:00
Simon Atanasyan a1b8fc3bb4 [ELF] Lookup INPUT argument in the current directory
If an argument of the INPUT directive is a regular path, linker should
lookup it in the current folder first.

The fix does not contain any test cases because I think it is not a good
idea to pollute a current folder (which in general might be arbitrary)
by test files.

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

llvm-svn: 254178
2015-11-26 20:23:46 +00:00
George Rimar fb5d7f23d9 Replaced stuff with auto. NFC.
llvm-svn: 254175
2015-11-26 19:58:51 +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
Igor Kudrin 9b7e7db8ca [ELF] Factor out relocation checks into separate functions.
It helps to standardize common checks and unify error messages.

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

llvm-svn: 254144
2015-11-26 09:49:44 +00:00
Simon Atanasyan 16b0cc9ee6 [ELF] Reapply r254031 - LinkerScript: lookup absolute paths under sysroot
In case a sysroot prefix is configured, and the filename starts with
the '/' character, and the script being processed was located inside
the sysroot prefix, the file's name will be looked for in the sysroot
prefix. Otherwise, the linker falls to the common lookup scheme.

It is slightly modified version of the commit r254031. The problem of
the initial commit was in the `is_absolute` call. On Windows 'C:\' is
absolute path but we do not need to find it under sysroot. In this patch
linker looks up a path under sysroot only if the paths starts with '/'
character.

llvm-svn: 254135
2015-11-26 05:53:00 +00:00
Hal Finkel f950595ea1 Fix a comment typo (cashe -> cache)
llvm-svn: 254111
2015-11-25 23:54:53 +00:00
George Rimar 77b7779b48 Reapply r254098.
Fix is (OutputSections.cpp):
for (std::pair<const SymbolBody *, size_t> &I : Entries) {
 =>
for (std::pair<const SymbolBody *, unsigned> &I : Entries) {

llvm-svn: 254105
2015-11-25 22:15:01 +00:00
George Rimar dbb2f6188d Revert r254098 as it seems broke build bot.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/3555

llvm-svn: 254103
2015-11-25 22:03:16 +00:00
George Rimar 6713cf8a52 [ELF] - Implemented optimizations for @tlsld and @tlsgd
Implements @tlsld (LD to LE) and @tlsgd (GD to LE) optimizations.
Patch does not implement the GD->IE case for @tlsgd.

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

llvm-svn: 254101
2015-11-25 21:46:05 +00:00
George Rimar 21c0a7131b [ELF] - Lazy relocations support for x86 target.
Patch implements lazy relocations for x86.
One of features of x86 is that executable files and shared object files have separate procedure linkage tables. So patch implements both cases.

Detailed information about instructions used can be found in http://docs.oracle.com/cd/E19620-01/805-3050/chapter6-1235/index.html (search: x86: Procedure Linkage Table).

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

llvm-svn: 254098
2015-11-25 21:37:59 +00:00
Simon Atanasyan 96306bbebc [ELF2][MIPS] Support R_MIPS_CALL16 relocation
R_MIPS_CALL16 relocation provides the same result as R_MIPS_GOT16
relocation but does not need to check the result on overflow.

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

llvm-svn: 254092
2015-11-25 20:58:52 +00:00
George Rimar d23970f778 [ELF/x86] Implemented R_386_TLS_LE_32, R_386_TLS_LE relocations.
This patch implements next relocations:
R_386_TLS_LE - Negative offset relative to static TLS (GNU version).
R_386_TLS_LE_32 - Offset relative to static TLS block.

These ones are created when using next code sequences:
* @tpoff - The operator must be used to compute an immediate value. The linker will report
an error if the referenced variable is not defined or it is not code for the executable
itself. No GOT entry is created in this case.
* @ntpoff Calculate the negative offset of the variable it is added to relative to the static TLS block.
The operator must be used to compute an immediate value. The linker will report
an error if the referenced variable is not defined or it is not code for the executable
itself. No GOT entry is created in this case.

Information was found in Ulrich Drepper, ELF Handling For Thread-Local Storage, http://www.akkadia.org/drepper/tls.pdf, (6.2, p76)

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

llvm-svn: 254090
2015-11-25 20:41:53 +00:00
George Rimar 1393477fd7 [ELF] - simplify Target interface, relocPointsToGot() removed.
https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-26/index.html says:
R_386_GOTPC
Resembles R_386_PC32, except that it uses the address of the global offset table in its calculation. The symbol referenced in this relocation normally is _GLOBAL_OFFSET_TABLE_, which also instructs the link-editor to create the global offset table.

Currently _GLOBAL_OFFSET_TABLE_ has value == zero. And we use GOT address to calculate the relocation. This patch does not changes that. It just removes the method which is used only for x86. So it is close to non functional change.

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

llvm-svn: 254088
2015-11-25 20:20:31 +00:00