Commit Graph

1649 Commits

Author SHA1 Message Date
David Majnemer 8a4be35c9c Adjust test from fallout due to r253429
As a side note, the jump target is much nicer than before.

We went from: <bar+...> to <.plt>

llvm-svn: 253433
2015-11-18 04:37:23 +00:00
Igor Kudrin db7de9f590 [ELF2/AArch64] Add lazy relocation support for AArch64.
Differential Revision: http://reviews.llvm.org/D14749

llvm-svn: 253352
2015-11-17 18:01:30 +00:00
Rafael Espindola 7477e99af7 Make ELF2 the default.
With this the only way to get the old elf linker is "-flavor old-elf".

llvm-svn: 253318
2015-11-17 07:19:44 +00:00
Rafael Espindola 4b1285c55a Rename test/elf2 to test/ELF.
llvm-svn: 253313
2015-11-17 05:36:42 +00:00
Rafael Espindola f16ba74ed2 Rename test/elf to test/old-elf.
llvm-svn: 253312
2015-11-17 05:34:56 +00:00
Rafael Espindola 7467461ccc Rename the gnu flavour to gnu old.
This is the first step in making ELF2 the default.

llvm-svn: 253188
2015-11-16 08:54:19 +00:00
George Rimar 03220309e1 [ELF2] - Implemented PT_GNU_STACK support, -z execstack option.
PT_GNU_STACK is a entry in the elf file format which contains the access rights (read, write, execute) of the stack,
it is always generated now. By default stack is not executable in this implementation. 
-z execstack can be used to make executable.

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

llvm-svn: 253145
2015-11-14 20:56:08 +00:00
George Rimar 687138c7d1 [ELF2] - Implemented R_X86_64_GOTTPOFF relocation
Generates single GOT entry, R_X86_64_TPOFF64 is added to RelaDyn.

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

llvm-svn: 253049
2015-11-13 16:28:53 +00:00
Rafael Espindola f8ce28676a Use ld.lld2, not -flavor gnu2
llvm-svn: 253044
2015-11-13 15:01:17 +00:00
George Rimar 51e37d9997 [ELF2] - dont merge .data.rel.ro/.data.rel.ro.local into .data section.
This sections can be protected with relro after resolving relocations by dynamic linker.

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

llvm-svn: 253018
2015-11-13 07:56:27 +00:00
Denis Protivensky e1a89c2d1c Fix failing test on Windows
Remove backslash before redirection as it causes
echo to fail on Windows.

llvm-svn: 253017
2015-11-13 07:19:20 +00:00
Igor Kudrin b34115b7fe [ELF2/AArch64] Add support for R_AARCH64_CALL26 and R_AARCH64_JUMP26.
This patch covers only the case where no DSO is involved.

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

llvm-svn: 253007
2015-11-13 03:26:59 +00:00
Michael J. Spencer 627ae703b5 [elf2] Implement global dynamic tls.
llvm-svn: 252979
2015-11-13 00:28:34 +00:00
Rui Ueyama f5bcf2a72f ELF2: Print an error message for --relocatable.
llvm-svn: 252923
2015-11-12 18:54:15 +00:00
Denis Protivensky 8e3b38aba1 [ELF2] SECTIONS command basic support
* determine output section by input section name
* discard input sections
* order output sections accordingly

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

llvm-svn: 252868
2015-11-12 09:52:08 +00:00
Igor Kudrin 304860ab67 [ELF2] Add mandatory .dynamic section entries on MIPS.
The MIPS target requires specific dynamic section entries to be defined.

 * DT_MIPS_RLD_VERSION and DT_MIPS_FLAGS store predefined values.
 * DT_MIPS_BASE_ADDRESS holds base VA.
 * DT_MIPS_LOCAL_GOTNO holds the number of local GOT entries.
 * DT_MIPS_SYMTABNO holds the number of .dynsym entries.
 * DT_MIPS_GOTSYM holds the index of the .dynsym entry
   which corresponds to the first entry of the global part of GOT.
 * DT_MIPS_RLD_MAP holds the address of the reserved space in the data segment.
 * DT_MIPS_PLTGOT points to the .got.plt section if it exists.
 * DT_PLTGOT holds the address of the GOT section.

See "Dynamic Section" in Chapter 5 in the following document for detailed
description: ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

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

llvm-svn: 252857
2015-11-12 04:39:49 +00:00
Igor Kudrin f4cdfe88ee [ELF2] Sort dynamic symbols according to the MIPS requirements.
The MIPS ABI has requirements to sort the entries in the .dyn.sym section.
Symbols which are not in the GOT have to precede the symbols which are added to
the GOT. The latter must have the same order as the corresponding GOT entries.

Since these sorting requirements contradict those of the GNU hash section,
they cannot be used together.

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

llvm-svn: 252854
2015-11-12 04:08:12 +00:00
Rafael Espindola 0c6a4f197f Add support for processing .eh_frame.
This adds support for:
* Uniquing CIEs
* Dropping FDEs that point to dropped sections

It drops 657 488 bytes from the .eh_frame of a Release+Asserts clang.

The link time impact is smallish. Linking clang with a Release+Asserts
lld goes from 0.488064805 seconds to 0.504763060 seconds (1.034 X slower).

llvm-svn: 252790
2015-11-11 19:54:14 +00:00
Rafael Espindola a016b1e186 Canonicalize the type of .eh_frame.
GNU as can give it type SHT_PROGBITS or SHT_X86_64_UNWIND depending on
teh construct.

MC gives it type SHT_X86_64_UNWIND.

The linker has to canonicalize to one or the other so that there is only
one .eh_frame in the end.

llvm-svn: 252757
2015-11-11 17:33:22 +00:00
Michael J. Spencer dc9c5df5cd [elf2] Add support for local TLS symbols.
llvm-svn: 252686
2015-11-11 01:28:23 +00:00
Michael J. Spencer ac2307b9ff [elf2][x86-64] Add support for DTPOFF64
llvm-svn: 252685
2015-11-11 01:28:11 +00:00
Michael J. Spencer a5d9d1f154 [elf2][x86-64] Add support for DTPOFF32
llvm-svn: 252684
2015-11-11 01:27:58 +00:00
Michael J. Spencer 1e22561a57 [elf2] Add support for R_X86_64_TLSLD.
leaq symbol@tlsld(%rip), %rdi
call __tls_get_addr@plt

symbol@tlsld (R_X86_64_TLSLD) instructs the linker to generate a tls_index entry (two GOT slots) in the GOT for the entire module (shared object or executable) with an offset of 0. The symbol for this GOT entry doesn't matter (as long as it's either local to the module or null), and gold doesn't put a symbol in the dynamic R_X86_64_DTPMOD64 relocation for the GOT entry.

All other platforms defined in http://www.akkadia.org/drepper/tls.pdf except for Itanium use a similar model where global and local dynamic GOT entries take up 2 contiguous GOT slots, so we can handle this in a unified manner if we don't care about Itanium.

While scanning relocations we need to identify local dynamic relocations and generate a single tls_index entry in the GOT for the module and store the address of it somewhere so we can later statically resolve the offset for R_X86_64_TLSLD relocations. We also need to generate a R_X86_64_DTPMOD64 relocation in the RelaDyn relocation section.

This implementation is a bit hacky. It side steps the issue of GotSection and RelocationSection only handling SymbolBody entries by relying on a specific relocation type. The alternative to this seemed to be completely rewriting how GotSection and RelocationSection work, or using a different hacky signaling method.

llvm-svn: 252682
2015-11-11 01:00:24 +00:00
Rafael Espindola 8ea46e00f1 Start treating .eh_frame specially.
For now, just don't follow edges leaving from it to mark other sections
live.

llvm-svn: 252493
2015-11-09 17:44:10 +00:00
George Rimar 564da7ee87 [ELF2] - Fixed crash for case when section sh_entsize is set to zero for SHF_MERGE type of sections.
Differential revision: http://reviews.llvm.org/D14451

llvm-svn: 252454
2015-11-09 08:40:44 +00:00
Davide Italiano bbcc7f6115 [ELF2/AArch64] Support R_AARCH64_LDST64_ABS_LO12_NC relocation.
llvm-svn: 252415
2015-11-08 04:45:26 +00:00
Rafael Espindola ea7a1e9092 Round up the memsize of PT_TLS.
This is cleaner than computing relocations as if we had done it.

While at it, keep a single Phdr variable instead of multiple fields of it.

llvm-svn: 252352
2015-11-06 22:14:44 +00:00
Rafael Espindola 1954c614d4 .eh_frame is not normally writable. Update the test to reflect that.
llvm-svn: 252312
2015-11-06 15:25:54 +00:00
Igor Kudrin 15cd9ffd1e [ELF2] Add GOT section for MIPS target.
This patch implements R_MIPS_GOT16 relocation for global symbols in order to
generate some entries in GOT. Only reserved and global entries are supported
for now. For the detailed description about GOT in MIPS, see "Global Offset
Table" in Chapter 5 in the followin document:
ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

In addition, the platform specific symbol "_gp" is added, see "Global Data
Symbols" in Chapter 6 in the aforementioned document.

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

llvm-svn: 252275
2015-11-06 07:43:03 +00:00
Rafael Espindola ac1c0f8931 Check the range of R_X86_64_TPOFF32.
llvm-svn: 252169
2015-11-05 15:22:26 +00:00
Michael J. Spencer 6c34eff536 [elf2] Fix R_X86_64_TPOFF32 handling.
For x86-64 the initial executable TLS block is placed directly before the
thread specific data register so compilers can directly access it via
R_X86_64_TPOFF32. Generate the correct (negative) offset for this case.

llvm-svn: 252131
2015-11-05 02:00:35 +00:00
Michael J. Spencer d77f0d2526 [elf2] Implement R_X86_64_TPOFF32.
This does not support TPOFF32 relocations to local symbols as the address calculations are separate. Support for this will be a separate patch.

llvm-svn: 251998
2015-11-03 22:39:09 +00:00
Rafael Espindola 61362ce876 Handle 0 sized sections like any other section.
This is a case where there is inconsistency among ELF linkers:

* The spec says nothing special about empty sections.
* BFD ld removes them.
* Gold handles them like regular sections.

We were outputting them but sometimes ignoring them. This would create
odd looking outputs where a rw section could be in a ro segment for example.

The bfd way of doing things is also strange for the case where a symbol
points to the empty section.

Now we match gold and what seems to be the intention of the spec.

llvm-svn: 251988
2015-11-03 22:08:08 +00:00
Rafael Espindola 443f50a833 Create .bss only when needed.
This is a small complication, but produces nicer output and is a step to
handling zero size sections uniformly.

llvm-svn: 251980
2015-11-03 21:35:14 +00:00
Rafael Espindola d1ec682411 Update for llvm change.
llvm-svn: 251971
2015-11-03 20:02:28 +00:00
Rafael Espindola 7bb1adfd66 Avoid checking for irrelevant facts.
If the test is not for layout, it should not depend on the address for example.

llvm-svn: 251969
2015-11-03 19:56:47 +00:00
Rafael Espindola 115f0f365d Two small fixes to copy relocation processing.
* We can determine the alignment requirement.
* We have to update the bss alignment with it.

llvm-svn: 251914
2015-11-03 14:13:40 +00:00
Rafael Espindola 31b71a921a Make the test a bit more strict and fix the math.
llvm-svn: 251913
2015-11-03 14:08:43 +00:00
Rafael Espindola e1bd952ea9 Simplify. NFC.
llvm-svn: 251912
2015-11-03 14:03:11 +00:00
Rafael Espindola f486beab7e Make this input a bit more readable.
llvm-svn: 251911
2015-11-03 13:58:27 +00:00
Michael J. Spencer 78aa1de3ae [elf2] Generate PT_TLS.
Differential Revision: http://reviews.llvm.org/D14167

llvm-svn: 251872
2015-11-03 00:34:39 +00:00
Davide Italiano 9b71ef92e7 [ELF2/AArch64] Add relocation tests to ensure we handle overflow correctly.
llvm-svn: 251646
2015-10-29 20:02:27 +00:00
Davide Italiano 3300b798ca [ELF2/AArch64] Implement R_AARCH64_PREL16 and R_AARCH64_PREL32 relocations.
llvm-svn: 251645
2015-10-29 19:55:59 +00:00
Lang Hames 2ed3bf9527 [lld][MachO] Make sure LC_RPATH command size is a multiple of the pointer size.
llvm-svn: 251637
2015-10-29 16:50:26 +00:00
George Rimar 5268721e59 Reapply r251536
llvm-svn: 251541
2015-10-28 18:33:08 +00:00
George Rimar 9413fa26af Revert r251536 as it broke buildbot: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/2104
llvm-svn: 251539
2015-10-28 18:16:24 +00:00
George Rimar 06f4e43d29 [ELF2] R_X86_64_64 plt relocation implemented.
This little patch is a final point in fix for https://llvm.org/bugs/show_bug.cgi?id=25175.

It`s make sample from issue description to work with -O0 optimization flag (with -O0 it generates R_X86_64_64 plt relocation).

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

llvm-svn: 251536
2015-10-28 17:59:44 +00:00
George Rimar bc590feb2b [ELF2] R_X86_64_COPY relocation implemented
Differential revision: http://reviews.llvm.org/D14090.

llvm-svn: 251526
2015-10-28 16:48:58 +00:00
Davide Italiano b12d668e3d [ELF2/AArch64] Add support for R_AARCH64_PREL64.
llvm-svn: 251523
2015-10-28 16:14:18 +00:00
Simon Atanasyan 07fe7a943f [Driver] Accept both -m <emulation> and -m<emulation>
GNU linkers accept both variants and at least for MIPS target gcc passes
joined variant of the '-m' option.

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

llvm-svn: 251497
2015-10-28 05:13:12 +00:00