Commit Graph

4583 Commits

Author SHA1 Message Date
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
George Rimar 70e2508259 [ELF] - R_386_COPY relocation implemented (x86)
Implements R_386_COPY relocation for x86 target.
Similar to one for x64 http://reviews.llvm.org/D14090 which did most of job needed.

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

llvm-svn: 254065
2015-11-25 11:27:40 +00:00
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