Commit Graph

4718 Commits

Author SHA1 Message Date
Hans Wennborg 17436ce174 Follow-up to r254049; remove function I missed in the revert.
llvm-svn: 254052
2015-11-25 01:24:15 +00:00
Hans Wennborg 82d2d07ced Revert r254031: "ELF2: LinkerScript: lookup absolute paths under sysroot"
The test fails on Windows:

Command 34: "ld.lld" "-o" "D:\src\llvm\build.release\tools\lld\test\ELF\Output\l
inkerscript.s.tmp2" "D:\src\llvm\build.release\tools\lld\test\ELF\Output\linkers
cript.s.tmp.dir/xyz.script" "--sysroot=D:\src\llvm\build.release\tools\lld\test\
ELF\Output\linkerscript.s.tmp.dir"
Command 34 Result: 1
Command 34 Output:

Command 34 Stderr:
Unable to find /libxyz.a

llvm-svn: 254049
2015-11-25 00:58:31 +00:00
Rui Ueyama a46566f2db ELF: Omit PT_GNU_STACK segment if -z execstack is provided.
In the previous patch (r254003), I made the linker emit PT_GNU_STACK
unconditionally. But sometimes you want to have a control over the
presence of the segment. With this patch, you can omit the segment
by passing -z execstack option.

llvm-svn: 254039
2015-11-24 23:42:33 +00:00
Rui Ueyama a7e09c6221 ELF2: Factor out isUnderSysroot from readLinkerScript. NFC.
llvm-svn: 254032
2015-11-24 22:26:33 +00:00
Simon Atanasyan 44136b675d ELF2: 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.

https://www.sourceware.org/binutils/docs-2.24/ld/File-Commands.html

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

llvm-svn: 254031
2015-11-24 22:16:25 +00:00
Rui Ueyama 9aa5686b9f ELF: Improve error handling of unknown emulation names.
This patch reverts r253985 and implements the same feature
in a less intrusive way.

llvm-svn: 254004
2015-11-24 18:55:36 +00:00
Rui Ueyama 7b19c34550 Revert "ELF: Make .note.GNU-stack more compatible with traditional linkers."
This reverts commit r253797 because it was based on a misunderstanding
that lld wouldn't work on NetBSD without this change.

llvm-svn: 254003
2015-11-24 18:48:16 +00:00
Martell Malone 4ccb2d412e ELF: print out a verbose error when a windows emulation is used
llvm-svn: 253985
2015-11-24 14:52:16 +00:00
George Rimar e3336c0be6 Reapply fixed r253967.
llvm-svn: 253971
2015-11-24 10:15:50 +00:00
George Rimar 11721ce810 Revert r253967 which broke buildbot.
llvm-svn: 253970
2015-11-24 10:04:22 +00:00
George Rimar 63a6ca9150 [ELF] Implements -z relro: create an ELF "PT_GNU_RELRO" segment header in the object.
Partial (-z relro) and full (-z relro, -z now) relro cases are implemented.

Partial relro:
The ELF sections are reordered so that the ELF internal data sections (.got, .dtors, etc.) precede the program's data sections (.data and .bss).
.got is readonly, .got.plt is still writeable.

Full relro:
Supports all the features of partial RELRO, .got.plt is also readonly.

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

llvm-svn: 253967
2015-11-24 09:44:28 +00:00
George Rimar 77d1cb1ddf [ELF2] - Optimization for R_X86_64_GOTTPOFF relocation.
R_X86_64_GOTTPOFF is not always requires GOT entries. Some relocations can be converted to local ones.

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

llvm-svn: 253966
2015-11-24 09:00:06 +00:00
Igor Kudrin 5d2bffdd57 [ELF/AArch64] Add support for R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC.
With these relocations, it is now possible to build a simple "hello world"
program for AArch64 Debian.

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

llvm-svn: 253957
2015-11-24 06:48:31 +00:00
Igor Kudrin ee252ded15 [ELF/AArch64] Factor out overflow checks into a separate function. NFC.
Differential revision: http://reviews.llvm.org/D14922

llvm-svn: 253884
2015-11-23 17:16:09 +00:00
Igor Kudrin bf08749b29 [ELF/AArch64] Fix overflow checks for R_AARCH64_PREL16 and _PREL32 relocations.
llvm-svn: 253879
2015-11-23 16:56:10 +00:00
Rafael Espindola e02c86812c Fix Elf_Rel processing for .eh_frame.
Thanks to Simon for the bug report.

llvm-svn: 253869
2015-11-23 15:28:28 +00:00
Rui Ueyama e79b09a616 ELF: Make .note.GNU-stack more compatible with traditional linkers.
With this patch, lld creates PT_GNU_STACK segments only when all input
files have .note.GNU-stack sections. This is in line with other linkers
with a minor difference (we don't care about .note.GNU-stack rwx bits as
you can always remove .note.GNU-stack sections instead of setting x bit.)

At least, NetBSD loader does not understand PT_GNU_STACK segments and
reject any executables that have the section. This patch makes lld
compatible with such operating systems.

llvm-svn: 253797
2015-11-21 22:19:32 +00:00
Rui Ueyama df06d203e5 Update documents.
llvm-svn: 253728
2015-11-20 22:47:42 +00:00
Rui Ueyama 8486a51845 Remove trailing whitespaces and untabify.
llvm-svn: 253727
2015-11-20 22:47:40 +00:00
Davide Italiano dc67f9b7e8 [ELF/AArch64] Add support for LDST8_ABS_LO12_NC/LDST64_ABS_LO12_NC.
These two relocations where the only missing step to get a dynamically
linked (with libc) "hello world" on FreeBSD.

llvm-svn: 253714
2015-11-20 21:35:38 +00:00
Rui Ueyama 6220fd8bfd Define -E as an alias for --export-dynamic.
llvm-svn: 253713
2015-11-20 21:22:53 +00:00
Rui Ueyama 03bec877c5 Remove default values that are always overriden in Driver.cpp.
llvm-svn: 253710
2015-11-20 21:00:42 +00:00
Igor Kudrin 2f610d5e13 [ELF/AArch64] Accept -m aarch64linux.
This option is passed by clang driver if the target triple
is "aarch64-unknown-linux".

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

llvm-svn: 253639
2015-11-20 02:48:53 +00:00
Igor Kudrin b044af50f2 [ELF] Define symbols "_end" and "end" if referenced.
These symbols are expected to point to the end of the data segment.

Implements http://llvm.org/pr25528.

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

llvm-svn: 253637
2015-11-20 02:32:35 +00:00
Rui Ueyama d94478b04e Remove redundant namespace specifiers.
llvm-svn: 253635
2015-11-20 02:19:36 +00:00
Rui Ueyama 2022e81af0 Make a function out-of-line.
There's no need to write it in a .h file.

llvm-svn: 253633
2015-11-20 02:10:52 +00:00
Rui Ueyama 2dc3f8c278 Remove redundant "using namespace".
llvm-svn: 253632
2015-11-20 01:59:16 +00:00
Rui Ueyama dfa577bafb Fix formatting.
llvm-svn: 253620
2015-11-19 23:30:10 +00:00
Igor Kudrin 4bc5ad4c37 [ELF] Prevent SEGFAULT in case of conflict with an internally defined symbol.
Differential Revision: http://reviews.llvm.org/D14832

llvm-svn: 253588
2015-11-19 19:08:45 +00:00
Rui Ueyama 905c41b00d Update "Getting Started" document.
llvm-svn: 253522
2015-11-18 23:53:19 +00:00
Ed Maste c98805b493 Accept -whole-archive and -no-whole-archive (with a single dash)
Clang uses the single-dash version in addSanitizerRuntime().

llvm-svn: 253477
2015-11-18 17:22:02 +00:00
Rafael Espindola 9c8904fb38 Rename ld.lld2 to ld.lld since it is the default.
llvm-svn: 253437
2015-11-18 06:11:01 +00:00
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
Peter Collingbourne 70507e59fe COFF: Destroy LTOModules as they are linked.
This should help reduce memory consumption during LTO.

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

llvm-svn: 253397
2015-11-17 23:30:59 +00:00
Yunzhong Gao fbee89263f Fixing build failures caused by r253367. Sorry for breaking the build.
llvm-svn: 253374
2015-11-17 20:48:12 +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
Igor Kudrin e7ad0937bb [ELF2] getPLTRefReloc() -> getPltRefReloc().
llvm-svn: 253351
2015-11-17 17:47:53 +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 97a8695aa1 Rename gnu2 to gnu.
This is the second step in making ELF2 the default.

llvm-svn: 253270
2015-11-16 23:21:55 +00:00
Igor Kudrin 351b41de4e [ELF2] Remove target specific code from GotPltSection.
The content of reserved entries of the .got.plt section is target specific.

In particular, on x86_64 the zero entry holds the address of the .dynamic section,
but on AArch64 the same info is stored in the zero entry of the .got section.

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

llvm-svn: 253239
2015-11-16 17:44:08 +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
Rui Ueyama 1d37e60dc5 ELF2: Make comment less opinionated.
llvm-svn: 253058
2015-11-13 18:56:07 +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 4b40ebce66 [ELF2] - fix of eh-frame-merge.s and eh-frame-merge.s tests fails for win32 configuration.
llvm-svn: 253043
2015-11-13 13:44:59 +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 ecd7f377dd [elf2] get{Local,Global}DynamicReloc -> is{LocalGlobal}DynamicReloc.
llvm-svn: 252982
2015-11-13 00:32:58 +00:00
Michael J. Spencer 627ae703b5 [elf2] Implement global dynamic tls.
llvm-svn: 252979
2015-11-13 00:28:34 +00:00
Rui Ueyama a6f103f705 ELF2: Add comments and reorganize option list a bit.
llvm-svn: 252978
2015-11-13 00:26:12 +00:00
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
Rafael Espindola 9b89608698 Remove a redundant boolean.
llvm-svn: 251921
2015-11-03 14:34:11 +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
Rafael Espindola de212f1589 Delete dead getter.
llvm-svn: 251908
2015-11-03 13:36:38 +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
Rafael Espindola 31f8888cd9 Make a method static. NFC.
llvm-svn: 251799
2015-11-02 14:33:11 +00:00
Igor Kudrin 2169b1bd26 [ELF2] Ensure that .dynsym section is finalized before .gnu.hash.
It is required to fill up the GNU hash table section before its
finalize() method is called.

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

llvm-svn: 251789
2015-11-02 10:46:14 +00:00
George Rimar 0e8d1922c8 [ELF2] Revert of r251692
llvm-svn: 251782
2015-11-02 08:24:16 +00:00
George Rimar d98bcc713d Comments about how values were calculated for functions below were added.
1. X86_64TargetInfo::writePltZeroEntry.
2. X86_64TargetInfo::writePltEntry.

llvm-svn: 251692
2015-10-30 09:11:12 +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
George Rimar 8b8222b04c [ELF2] merge-string.s test fixed for win32 configuration.
Differential revision: http://reviews.llvm.org/D14171

llvm-svn: 251644
2015-10-29 19:30:28 +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
Lang Hames ac416d42fc [lld][MachO] Use a std::string rather than a StringRef for the section name in
MachODefinedCustomSectionAtom.

The section names for these atoms are initialized from temporaries (e.g.
segName + "/" + sectName), so we can't use StringRef here.

llvm-svn: 251610
2015-10-29 03:57:31 +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 069b2dd66c [Driver] Ignore -G option in both new and old ELF linker
This is optimization option that make sense for MIPS targets. We can
safely ignore it now.

llvm-svn: 251519
2015-10-28 14:50:58 +00:00
Igor Kudrin f1d6029016 [ELF2] Move sorting and data to the GNU hash table section.
It is the GNU hash table section that should be reaponsible for storing its own
data and applying its requirements for the order to dynamic symbols.

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

llvm-svn: 251502
2015-10-28 07:05:56 +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
Rui Ueyama 12504649dc ELF2: Move some code from MarkLive.cpp to InputSection.cpp.
This function is useful for ICF, so move that to a common place.

llvm-svn: 251455
2015-10-27 21:51:13 +00:00
Michael J. Spencer 4633a373e0 [elf2] Don't allocate VA space for TLS NOBITS sections.
Differential Revision: http://reviews.llvm.org/D13838

llvm-svn: 251454
2015-10-27 21:22:54 +00:00
Rui Ueyama 305a7d3f44 ELF2: Make parseEmulation side-effect free. NFC.
llvm-svn: 251440
2015-10-27 19:29:27 +00:00
Davide Italiano ce0d48adbb [ELF2/Driver] Accept both -L <arg> and -L<arg>.
This matches ld.bfd and ld.gold behavior. The change is simple enough
and avoid trouble to consumers (they don't have to change their Makefiles).
Side note: found while trying to build FreeBSD base system with lld.

llvm-svn: 251408
2015-10-27 15:10:53 +00:00
Rui Ueyama 0b2b964797 ELF2: Ignore -( and -).
They are aliases to --start-group and --end-group, respectively.

llvm-svn: 251332
2015-10-26 19:05:44 +00:00
Rui Ueyama df985afa14 COFF: De-parallelize ICF for now.
There was a threading issue in the ICF code for COFF. That seems like
a venign bug in the sense that it doesn't produce an incorrect output,
but it oftentimes misses reducible sections. As a result, mergeable
sections could remain in outputs, which makes the output nondeterministic.

Basically the algorithm we are using for ICF is this: We group sections
so that identical sections will eventually be in the same group. Initially,
all sections are in one group. We split the group by relocation targets
until we get a convergence (if relocation targets are in different gruops,
the sections are different). Once a group is split, they will never be
merged.

Each section has a group ID. That variable itself is atomic, so there's
no threading issue at the level that we can use thread sanitizer.
The point is, when we split a group, we re-assign new group IDs to group
of sections. That are multiple separate writes to atomic varaibles.
Thus, splitting a group is not an atomic operation, and there's a small
chance that the other thread observes inconsistent group IDs.

Over-splitting is always "safe", so it will never create incorrect output.

I suspect that the nondeterminism stems from that point. However, I
cannot prove or fix that at this moment, so I'm going to avoid using
threads here.

llvm-svn: 251300
2015-10-26 16:20:00 +00:00
George Rimar f940d5918f Another fix of -Wqual-const warning.
llvm-svn: 251259
2015-10-25 20:14:07 +00:00
Ed Maste add8ee31a4 Correct relocation type in test header comment
llvm-svn: 251242
2015-10-25 16:30:05 +00:00
Rui Ueyama 7ba639bdd6 Fix -Wqual-const warning.
llvm-svn: 251241
2015-10-25 16:25:04 +00:00
Rafael Espindola f82ed2a28c Add support for merging string from SHF_STRINGS sections.
llvm-svn: 251212
2015-10-24 22:51:01 +00:00
Rui Ueyama 9eb7ed0423 ELF2: Move Writer class to the top of the file. NFC.
llvm-svn: 251195
2015-10-24 18:22:59 +00:00
Rui Ueyama 6621d8ed7c ELF2: Add comments and simplify. NFC.
llvm-svn: 251194
2015-10-24 17:57:40 +00:00
Rui Ueyama 157c433a83 ELF2: Remove setNameOffset and combine that with writeHeader. NFC.
llvm-svn: 251193
2015-10-24 17:57:39 +00:00
Rui Ueyama 9fbb3d8850 ELF2: Rename StringTableSection::getFileOff -> getOffset.
getFileOff functions defined for other classes return an offset
from beginning of the file. StringTableSection's getFileOff however
returned an offset from beginning of the section. That was confusing.

llvm-svn: 251192
2015-10-24 17:44:52 +00:00
George Rimar 5dad7c1d4c Reapply r251144: fixed test.
llvm-svn: 251184
2015-10-24 08:52:46 +00:00
Lang Hames b1b67f4daf [lld][Darwin] Add support for the -sectcreate option.
llvm-svn: 251183
2015-10-24 08:20:51 +00:00
Rui Ueyama c27d2f266e ELF2: Remove FIXMEs which we are not sure if we have to fix.
llvm-svn: 251173
2015-10-24 01:46:40 +00:00
Rui Ueyama e08cd678de ELF2: Simplify file magic setter.
llvm-svn: 251159
2015-10-23 22:44:39 +00:00
Rui Ueyama bcb2d0f94b ELF2: Factor out getEntryAddr from writeHeader. NFC.
llvm-svn: 251158
2015-10-23 22:44:37 +00:00
Rui Ueyama c611d97006 ELF2: Use character literals for ELF file magic.
This is consitent with Support/ELF.h and more obvious than before.

llvm-svn: 251155
2015-10-23 22:31:47 +00:00
Rafael Espindola 6779a23626 Update for llvm api change.
llvm-svn: 251154
2015-10-23 21:48:35 +00:00
Rui Ueyama 803195ed6d ELF2: Simplify Writer::assignAddresses. NFC.
This patch is an attempt to simplify assignAddresses function by splitting
it and using less variables. I tried to split the code to create PHDRs from
the code to assign addresses, but it didn't make this code simpler, so I
didn't do that in this patch.

llvm-svn: 251152
2015-10-23 21:45:59 +00:00
Rui Ueyama b621d1ae58 Revert "[ELF2] --strip-all/-s command line implemented"
This reverts commit r251144 because the new test is failing.

llvm-svn: 251148
2015-10-23 21:08:41 +00:00
George Rimar 236bf3bfe4 [ELF2] --strip-all/-s command line implemented
-s, --strip-all - Strip all symbols
Implementation removes .strtab and .symtab sections from output.

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

llvm-svn: 251144
2015-10-23 20:24:44 +00:00
Rafael Espindola 48225b4433 Drop a few const to reduce the noise from the next patch. NFC.
llvm-svn: 251140
2015-10-23 19:55:11 +00:00
Rafael Espindola 2c1217d82a Parse and store the value of the -O option.
llvm-svn: 251136
2015-10-23 19:02:19 +00:00
Rui Ueyama c44e5a15ce ELF2: Do not apply 0xffff bit mask to uint16_t return values. NFC.
llvm-svn: 251118
2015-10-23 16:54:58 +00:00
Rui Ueyama 3835b490da Style fix.
llvm-svn: 251114
2015-10-23 16:13:27 +00:00
Lang Hames 5e7cfe4e2b [lld][MachO] Prune unused EH frames.
llvm-svn: 251095
2015-10-23 05:39:16 +00:00
Rui Ueyama 96f0e0bfc9 ELF2: Improve Target::relocateOne().
relocateOne is a function to apply a relocation. Previously, that
function took a pointer to Elf_Rel or Elf_Rela in addition to other
information that can be derived from the relocation entry. This patch
simplifies the parameter list. The new parameters, P or SA, are used
in the ELF spec to describe each relocation. These names make
relocateOne look like a mechanical, direct translation of the ELF spec.

llvm-svn: 251090
2015-10-23 02:40:46 +00:00
Rui Ueyama 2beabc9be5 ELF2: SymbolBody::repl() never returns a nullptr.
So we can use dyn_cast instead of dyn_cast_or_null here.

llvm-svn: 251076
2015-10-22 23:10:25 +00:00
Rui Ueyama 8a598f89ad ELF2: Keep .eh_frame even if they are not live.
.eh_frame sections need to be preserved if they refer to live sections.
So the liveness relation is reverse for eh_frame sections. For now,
we simply preserve all .eh_frame sections. Thanks Rafael for pointing
this out. .jcr are kept for the same reason.

llvm-svn: 251068
2015-10-22 21:42:05 +00:00
Rui Ueyama c4aaed9255 ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.

In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.

This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.

It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.

http://reviews.llvm.org/D13950

llvm-svn: 251043
2015-10-22 18:49:53 +00:00
Igor Kudrin 0cb1561e42 Fix the buildbot.
test/elf2/gnu-hash-table.s requires ppc target support to run.

llvm-svn: 251002
2015-10-22 08:58:03 +00:00
Igor Kudrin 1b0d7066ff [ELF2] Add support for GNU Hash section
This patch implements --hash-style command line switch.

* By default, or with "sysv" or "both" parameters, the linker generates
  a standard ELF hash section.
* With "gnu" or "both", it produces a GNU-style hash section.

That section requires the symbols in the dynamic symbol table section, which
are referenced in the GNU hash section, to be placed after not hashed ones and
to be sorted to correspond the order of hash buckets in the GNU Hash section.

The division function, as well as estimations for the section's parameters,
are just the first rough attempt and the subjects for further adjustments.

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

llvm-svn: 251000
2015-10-22 08:21:35 +00:00
Rui Ueyama 9cfc8e08a8 ELF2: Remove FIXMEs.
These classes are partially written, so almost all features
are FIXMEs. We do not want to add new FIXMEs to the classes
when we add new features to other non-stub classes.

llvm-svn: 250947
2015-10-21 21:13:35 +00:00
Rui Ueyama 86696f38ea ELF2: Avoid bitwise-OR hack. NFC.
The previous code is too clever that that needs a bit more
brain power than this new code.

llvm-svn: 250934
2015-10-21 19:41:03 +00:00
Rui Ueyama 8f2c4da65a ELF2: Rename getMostConstrainingVisibility -> getVisibility. NFC.
The previous name was too long.

llvm-svn: 250920
2015-10-21 18:13:47 +00:00
Rui Ueyama c96d0dd431 ELF2: Simplify DT_FLAGS{,_1} handling. NFC.
llvm-svn: 250914
2015-10-21 17:47:10 +00:00
Davide Italiano 6e91c598b9 [ELF2] Add support for -z origin.
llvm-svn: 250907
2015-10-21 17:09:47 +00:00
Craig Topper f88d22970d Update lld to match llvm r250901. OptTable constructor now takes an ArrayRef. NFC
llvm-svn: 250904
2015-10-21 16:31:56 +00:00
Rafael Espindola f5af835759 Fix symbol value calculation in SHF_MERGE.
We would get the wrong value if the symbol was in the middle of an entry.

llvm-svn: 250865
2015-10-20 22:08:49 +00:00
Igor Kudrin ab665fc475 [ELF2] Determine the order of entries of symbol tables in the finalize() phase.
* Move the responsibility to call SymbolBody::setDynamicSymbolTableIndex()
  from the hash table to the dynamic symbol table.
* Hash table is not longer responsible for filling the dynamic symbol table.
* The final order of symbols of both symbol tables is set before writing
  phase starts.
* Remove repeaded scan of the symbol table during writting SymbolTableSection.

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

llvm-svn: 250864
2015-10-20 21:47:58 +00:00
Lang Hames 2483d8f4a7 [lld][MachO] Fix indentation.
llvm-svn: 250863
2015-10-20 21:47:19 +00:00
Lang Hames 650c00be89 [lld][MachO] Fix typo in comment.
llvm-svn: 250861
2015-10-20 21:44:30 +00:00
Igor Kudrin 853b88d7ff [ELF2] Extract calculation of symbol binding as a separate function.
Differential Revision: http://reviews.llvm.org/D13910

llvm-svn: 250855
2015-10-20 20:52:14 +00:00
George Rimar 0f5ac9f571 [ELF2] .shstrtab section implemented
The section header table index of the entry that is associated with the section name string table.

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

llvm-svn: 250836
2015-10-20 17:21:35 +00:00
George Rimar 4a8c93ee85 [elf2] - remove redundant check.
This one is not needed anymore after r250812

llvm-svn: 250818
2015-10-20 11:27:00 +00:00
George Rimar 505f792cbb Fixed buildbot. Sorry.
llvm-svn: 250815
2015-10-20 11:07:03 +00:00
George Rimar 85f1d6678f [ELF2] -l behavior is JoinedOrSeparate. Keeping consistency with ld here.
llvm-svn: 250812
2015-10-20 10:03:14 +00:00
George Rimar b7d79b5c27 [ELF2] Fixed crash when no library is specified for -l
llvm-svn: 250811
2015-10-20 09:58:56 +00:00
George Rimar 648a2c37fb [ELF2] - Lazy relocation support for x86_64.
Target has supportsLazyRelocations() method which can switch lazy relocations on/off (currently all targets are OFF except x64 which is ON). So no any other targets are affected now.

Differential Revision: http://reviews.llvm.org/D13856?id=37726

llvm-svn: 250808
2015-10-20 08:54:27 +00:00
George Rimar c96c182ab4 Reverts r250775 as it breaks self-hosting.
llvm-svn: 250807
2015-10-20 08:49:43 +00:00
Davide Italiano ea03901e71 [Driver] Remove a FIXME that didn't make a lot of sense.
Thanks to Rui for pointing out!

llvm-svn: 250800
2015-10-20 05:07:59 +00:00
Davide Italiano 06edc7c0aa [ELF2] Correctly set bits when -z now is specified.
The option now just sets NOW bit in DT_FLAGS_1 but some loaders
seem to require also BIND_NOW bit to be set in DT_FLAGS. This is,
also, what ld.bfd and gold do.

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

llvm-svn: 250799
2015-10-20 04:58:40 +00:00
Davide Italiano 1ea1fd6b34 [Driver] Error out instead of silently ignoring on invalid -z argument.
This matches what both ld.bfd and gold do.

llvm-svn: 250775
2015-10-20 00:34:04 +00:00
Davide Italiano 88f476b9eb [ELF2] Introduce support for -z nodelete.
llvm-svn: 250771
2015-10-20 00:20:20 +00:00
Davide Italiano 58cbaf0604 [ELF2/OutputSections] Allocate the correct number of entries after r250739.
llvm-svn: 250760
2015-10-19 23:32:16 +00:00
Davide Italiano 56d18f4f8a [OutputSection] Set the symbolic bit in DT_FLAGS and not DT_FLAGS_1.
The two names are similar enough that they might lead to confusion.
The output of readobj clarifies but I missed it when I originally
committed this. Found while linking FreeBSD userland with lld.

llvm-svn: 250739
2015-10-19 21:34:00 +00:00
Davide Italiano 5d1ec86910 [Driver] Ignore some options used to link FreeBSD userland.
We're gonna implement them at some point, but they're mostly warning,
not of vital importance at this stage of development.

llvm-svn: 250738
2015-10-19 21:01:32 +00:00
Rafael Espindola c159c967f6 Add support for merging the contents of SHF_MERGE sections.
For now SHF_STRINGS are not supported.

llvm-svn: 250737
2015-10-19 21:00:02 +00:00
Rui Ueyama f215dac553 Replace auto with a real type. NFC.
llvm-svn: 250736
2015-10-19 20:55:28 +00:00
Rui Ueyama b7f2867a85 Reduce nesting level. NFC.
llvm-svn: 250732
2015-10-19 20:31:49 +00:00
Rafael Espindola 932efcfa77 Change getLocalRelTarget to include the addend.
Given the name, it is natural for this function to compute the full target.

This will simplify SHF_MERGE handling by allowing getLocalRelTarget to
centralize the addend logic.

llvm-svn: 250731
2015-10-19 20:24:44 +00:00
Rafael Espindola 4975752389 Simplify by computing on relocation field at a time.
llvm-svn: 250730
2015-10-19 19:58:18 +00:00
Rui Ueyama 75656eebb8 COFF: /OPT should accept comma-separated multiple arguments.
/OPT:foo,bar is equivalent to /OPT:foo /OPT:bar.

Reported by alexchandel. https://llvm.org/bugs/show_bug.cgi?id=25228

llvm-svn: 250728
2015-10-19 19:40:43 +00:00
Rafael Espindola d64430472d Fix comment.
llvm-svn: 250725
2015-10-19 19:24:03 +00:00
George Rimar 83f406cff5 [ELF2] - Linker script EXTERN command implemented.
The reason of collecting all undefines in vector is that during reading files we already need to have Symtab created. Or like was done in that patch - to put undefines from scripts somewhere to delay Symtab.addUndefinedOpt() call.

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

llvm-svn: 250711
2015-10-19 17:35:12 +00:00
Rafael Espindola 334c3e11e6 Delay the relocation scan.
We have to scan the relaxations after every symbol is defined.

This fixes pr25218.

llvm-svn: 250702
2015-10-19 15:21:42 +00:00
Igor Kudrin ea6a835f4e [ELF2] In/out parameter of writeGlobalSymbols() is changed to in parameter.
There is no outer code which requires the changed value.

llvm-svn: 250688
2015-10-19 08:01:51 +00:00
Rafael Espindola 69535df0e9 Mark R_X86_64_PLT32 as relative.
llvm-svn: 250682
2015-10-19 05:20:01 +00:00
Rafael Espindola 5045e44a17 Simplify. NFC.
llvm-svn: 250640
2015-10-18 03:13:46 +00:00