Commit Graph

1620 Commits

Author SHA1 Message Date
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
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
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
Ed Maste add8ee31a4 Correct relocation type in test header comment
llvm-svn: 251242
2015-10-25 16:30:05 +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
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 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
Lang Hames 5e7cfe4e2b [lld][MachO] Prune unused EH frames.
llvm-svn: 251095
2015-10-23 05:39:16 +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
Davide Italiano 6e91c598b9 [ELF2] Add support for -z origin.
llvm-svn: 250907
2015-10-21 17:09:47 +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
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 505f792cbb Fixed buildbot. Sorry.
llvm-svn: 250815
2015-10-20 11:07:03 +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 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 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
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 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