Commit Graph

4631 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
Lang Hames ac2adce66b [lld][MachO] Recognize __thread_bss sections as zero-fill and set all the
appropriate bits.

This fixes the remaining clang regression test failures when linking clang with
lld on Darwin.

llvm-svn: 255390
2015-12-11 23:25:09 +00:00
Lang Hames fc3438cd3f [lld] Watch out for tool names inside paths when substituting tool-paths in lit.
If we don't filter these out we can end up, generating bogus paths, for example:
/home/user/lld/build/bin -> /home/user/home/user/lld/build/bin/lld/build/bin.

llvm-svn: 255378
2015-12-11 22:09:03 +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
Ed Maste 24bcc11e5c Test that -e <symbol> works
llvm-svn: 255347
2015-12-11 17:42:38 +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
Pete Cooper 80c9b9468f Make commands printed by llvm-lit include the build path in lit.cfg.
When llvm-lit prints a failure, you'll see something like 'lld *command*' However, you can't then take this, paste it in to a terminal and run it, because it's not got the absolute path of lld.

llvm and clang's lit.cfg files contain lists of commands to look for which are substituted by their full paths. So now you'd see something like '*build dir*/bin/lld *command*'.

This patch adds the same capability to lld's lit.cfg

Reviewed by Rafael Espíndola

llvm-svn: 255283
2015-12-10 19:17:35 +00:00
Rui Ueyama ccfc3261f3 Simplify an expression. NFC.
llvm-svn: 255282
2015-12-10 19:13:08 +00:00
Pete Cooper 5cd12580fd Verify that macho-o delta64 relocs have the same offset.
The delta64 relocation is represented as the pair ARM64_RELOC_SUBTRACTOR and ARM64_RELOC_UNSIGNED.

Those should always have the same offset, so this adds a check and tests to ensure this is the case.

Also updated the error printing in this case to shows both relocs when erroring on pair.

llvm-svn: 255274
2015-12-10 18:48:52 +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
Lang Hames 201c08f811 [lld][MachO] Always reserve space for the empty string in the mach-o symbol
table.

The first entry in the MachO symbol table is always the empty string: make sure
we reserve space for it, or we will overflow the symbol table by one byte.

No test case - this manifests as an occasional memory error. In the near future
I hope to set up a bot building and runnnig LLD with sanitizers - that should
catch future instances of this issue.

llvm-svn: 255178
2015-12-10 00:12: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
Pete Cooper 466d4b006b Don't bypass the GOT for delta32toGOT references.
The gcc_except_tab was generating these references to point to the typeinfo in the data section.

gcc_except_tab also had the DW_EH_PE_indirect flag set which means that at runtime we are going
to dereference this entry as if it is in the GOT.

Reviewed by Nick Kledzik in http://reviews.llvm.org/D15360.

llvm-svn: 255085
2015-12-09 00:46:02 +00:00
Rui Ueyama 1763c0d3bc COFF: Create an empty but valid PDF file.
MSVC linker considers PDB files created with this patch valid.
So you don't have to remove PDB files created by lld before
running MSVC linker.

This patch has no test since llvm-pdbdump dislikes PDB files
with no metadata streams.

llvm-svn: 255039
2015-12-08 18:39:55 +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
Rui Ueyama e737824d8a COFF: Create a PDB file with the correct file signature.
Before this patch, we created an empty PDB file if /debug option is
specified. For MSVC linker, such PDB file is completely broken, and
linker exits without doing anything as soon as it finds an empty PDB
file.

A PDB file created in this patch has the correct file signature.
MSVC linker still thinks that the file is broken, but it then removes
and replaces with its output.

This is an initial patch to support PDB in LLD. We aim to support
PDB in order to make it 100% compatible with MSVC linker. PDB support
is the last missing piece.

llvm-svn: 254796
2015-12-04 23:11:05 +00:00
Rafael Espindola 3d49d7aa22 Update for llvm change.
llvm-svn: 254725
2015-12-04 16:22:09 +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
Rafael Espindola 35dad13714 Update for LLVM api change.
llvm-svn: 254697
2015-12-04 02:42:47 +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
Rui Ueyama 43e12900d9 COFF: Non-external COMDAT sections sholud not be merged by ICF.
If a section symbol is not external, that COMDAT section should never
be merge with other sections in other compilation unit. Previously,
we didn't take visibility into account.

Note that COMDAT sections with non-external visibility makes sense
because they can be removed by dead-stripping.

Fixes https://llvm.org/bugs/show_bug.cgi?id=25686

llvm-svn: 254578
2015-12-03 02:23:33 +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