Commit Graph

4514 Commits

Author SHA1 Message Date
Rui Ueyama b2f6fc177c Early continue. NFC.
llvm-svn: 252935
2015-11-12 19:45:58 +00:00
Rui Ueyama 92ce0e9122 ELF2: Make type a bit stricter. NFC.
llvm-svn: 252934
2015-11-12 19:42:43 +00:00
Rui Ueyama 1a8fffa2fb ELF2: Simplify -z option handling. NFC.
llvm-svn: 252924
2015-11-12 19:00:37 +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
Denis Protivensky 1b1b34ef95 [ELF2] Fix gcc warning in section kind switch
llvm-svn: 252864
2015-11-12 09:11:20 +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 7c84aecb58 Fix indentation. Thank to David Blaikie for noticing.
llvm-svn: 252759
2015-11-11 17:40:08 +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
Rafael Espindola db9bf4dbfe Add a helper for getting the output offset of an input offset.
This will get a non st_value use shortly.

llvm-svn: 252753
2015-11-11 16:50:37 +00:00
Rafael Espindola 1fe2d1e6d4 Convert a few size_t I missed in the previous commit. Sorry about that.
llvm-svn: 252745
2015-11-11 15:55:00 +00:00
Rafael Espindola 32994991ce Replace size_t with uintX_t in a few places.
If linking a 32 bit binary, these values must fit in 32 bits.

llvm-svn: 252739
2015-11-11 15:40:37 +00:00
Rafael Espindola a0fa8480a6 Remove const from a few places. NFC.
This just reduces the noise from an upcoming patch.

llvm-svn: 252737
2015-11-11 15:29:50 +00:00
Rafael Espindola d04c12a430 Remove unnecessary this->. NFC.
llvm-svn: 252736
2015-11-11 15:20:45 +00:00
Rafael Espindola 8e37f791f7 Don't pass a member variable to a method. NFC.
llvm-svn: 252718
2015-11-11 10:23:32 +00:00
Rafael Espindola 9a6e4632a0 Move relocate to the base class.
This is in preparation for adding .eh_frame support. They will have
another input section type but will also need to be relocated.

llvm-svn: 252717
2015-11-11 10:18:52 +00:00
Rafael Espindola c240e36690 Simplify. NFC.
llvm-svn: 252716
2015-11-11 09:57:08 +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
Eugene Zelenko 4154794892 Fix Clang-tidy modernize-use-auto warnings, other minor fixes.
Differential revision: http://reviews.llvm.org/D14553

llvm-svn: 252661
2015-11-10 22:37:38 +00:00
Igor Kudrin f6f45476f5 [ELF2] Remove Writer::getVAStart, use TargetInfo::getVAStart instead.
llvm-svn: 252593
2015-11-10 08:39:27 +00:00
Rafael Espindola e7e57b200f Use llvm provided read and write functions.
llvm-svn: 252518
2015-11-09 21:43:00 +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 7bcaec83be Fix a few windows only tests.
This argument must be non-null.

llvm-svn: 252336
2015-11-06 19:57:37 +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
Kevin Enderby 35dfc95efe These are the matching changes needed to the lld project for the changes to llvm
in r252192 that changed the Archive and Child interfaces in libObject. These include
Rafael Espindola’s many suggested updates.

llvm-svn: 252193
2015-11-05 19:25:47 +00:00
Rui Ueyama 7f20fb90e2 Remove redundant namespace specifiers.
llvm-svn: 252178
2015-11-05 18:13:25 +00:00
Rafael Espindola ac1c0f8931 Check the range of R_X86_64_TPOFF32.
llvm-svn: 252169
2015-11-05 15:22:26 +00:00
Rafael Espindola 8f3a6aeadb Avoid implicit Archive::child_iterator construction.
llvm-svn: 252167
2015-11-05 14:40:28 +00:00
Rafael Espindola 543f29d1a9 Don't implicitly construct an Archive::child_iterator.
llvm-svn: 252166
2015-11-05 14:34:56 +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
Eugene Zelenko 6e43b499d2 Fix Clang-tidy modernize-use-override warnings, other minor fixes.
Differential revision: http://reviews.llvm.org/D14310

llvm-svn: 252034
2015-11-04 02:11:57 +00:00
Rafael Espindola 5fbe008eb7 Simplify the logic to avoid the Closed set.
IMHO this makes the code easier to read: at each iteration we add
a section to a PT_LOAD and increase its size.

llvm-svn: 252011
2015-11-03 23:19:42 +00:00
Michael J. Spencer 2c6f213bcd [elf2] Use value-initialization instead of memset.
llvm-svn: 252006
2015-11-03 22:43:11 +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 d7a267b84b Remove redundant = nullptr.
llvm-svn: 251987
2015-11-03 22:01:20 +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 b8c3b1523f Fix thinko.
This would match SHF_ALLOC or SHF_TLS. We want both.

llvm-svn: 251939
2015-11-03 16:30:27 +00:00
Rafael Espindola 9eb3e57042 Simplify and fix style.
llvm-svn: 251927
2015-11-03 15:46:15 +00:00