Commit Graph

4383 Commits

Author SHA1 Message Date
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
Hal Finkel 8228198049 [ELF2/PPC64] Don't create .plt entries for weak undef symbols
Instead of specifically creating .plt entries for weak undef symbols, mirror
the logic in r250584, and use canBePreempted to determine is a REL24 relocation
needs a .plt entry. This might cause relocateOne to be called for a weak undef
symbol, with a REL24 relocation, but ignore this as a special case (this will
cause SA == 0, which won't happen under any other circumstance).

llvm-svn: 250597
2015-10-17 00:48:20 +00:00
Rui Ueyama eb3d5cef34 Remove DOS newlines.
llvm-svn: 250586
2015-10-16 23:55:40 +00:00
George Rimar 8911d85c2f [ELF2] - Implemented R_X86_64_PLT32 relocation.
There is sometimes no need to generate relocation via PLT. 
Example - when symbol is not undefined and we are not creating shared library. Then we can create relative relocation instead of referencing and creating PLT records.

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

llvm-svn: 250584
2015-10-16 23:52:24 +00:00
Rafael Espindola 80c94a7856 Use a reference. NFC.
llvm-svn: 250578
2015-10-16 23:22:23 +00:00
Michael J. Spencer 1bf73000cf [elf2] Sort allocated TLS sections at the start of the R/W PT_LOAD.
Differential Revision: http://reviews.llvm.org/D13763

llvm-svn: 250572
2015-10-16 23:11:07 +00:00
Rui Ueyama 6455852a28 ELF2: Treat IsMips64EL as a global configuration.
If one file is MIPS64EL, all files are MIPS64EL, and vice versa.
We do not have to look up MIPS-ness for each file. Currently we
do not support 64-bit MIPS, so the config value is always false.

llvm-svn: 250566
2015-10-16 22:51:43 +00:00
Hal Finkel 230c5c5b52 [ELF2] Remove unneeded new Type parameter
As pointed out by Rafael (with a further suggestion by Rui), the new Type
parameter I added in r250555 is not needed. Remove it.

llvm-svn: 250563
2015-10-16 22:37:32 +00:00
Hal Finkel c91740616a [ELF2] Don't create RelativeReloc for weak undef symbols
When we have a R_PPC64_ADDR64 for a weak undef symbol, which thus resolves to
0, and we're creating a shared library, we need to make sure that it stays 0
(because code that conditionally calls the weak function tests for this).
Unfortunately, we were creating a R_PPC64_RELATIVE for these relocation
targets, making the address of the undefined weak symbol equal to the base
address of the shared library (which is non-zero). In general, we should not be
creating RelativeReloc relocs for undef weak symbols.

llvm-svn: 250558
2015-10-16 22:11:05 +00:00
Michael J. Spencer 7dccca543a [elf2] Simplify and rename x86-64 relocation error tests.
llvm-svn: 250556
2015-10-16 22:05:52 +00:00
Hal Finkel 6f97c2bc00 [ELF2] getLocalRelTarget should handle R_PPC64_TOC directly
R_PPC64_TOC does not have an associated symbol, but does have a non-zero VA
that target-specific code must compute using some non-trivial rule. We
handled this as a special case in PPC64TargetInfo::relocateOne, where
we knew to write this special address, but that did not work when creating shared
libraries. The special TOC address needs to be the subject of a
R_PPC64_RELATIVE relocation, and so we also need to know how to encode this
special address in the addend of that relocation.

Thus, some target-specific logic is necessary when creating R_PPC64_RELATIVE as
well. To solve this problem, we teach getLocalRelTarget to handle R_PPC64_TOC
as a special case. This allows us to remove the special case in
PPC64TargetInfo::relocateOne (simplifying code there), and naturally allows the
existing logic to do the right thing when creating associated R_PPC64_RELATIVE
relocations for shared libraries.

llvm-svn: 250555
2015-10-16 21:55:40 +00:00
Rui Ueyama 83a131fa73 ELF2: Remove an empty stub for 32-bit PPC.
This code will be resurrected when we start working on PPC32.

llvm-svn: 250553
2015-10-16 21:37:09 +00:00
Davide Italiano a716574b0d [ELF2/AArch64] Comment R_AARCH64_ADD_ABS_LO12_NC relocation.
Differential Revision:	 http://reviews.llvm.org/D13832

llvm-svn: 250551
2015-10-16 21:06:55 +00:00
Rafael Espindola bfaa4ef60e Fix a copy and paste error in a test.
llvm-svn: 250548
2015-10-16 20:25:12 +00:00
Rafael Espindola 890e89caad Add an interesting case where we were already producing the correct result.
llvm-svn: 250544
2015-10-16 19:57:42 +00:00
Hal Finkel 0091862801 [ELF2/PPC64] Invert PPC64TargetInfo::isRelRelative's default
When I initially implemented PPC64TargetInfo::isRelRelative, I included a fixed
set of relative relocations, and made the default false. In retrospect, this
seems unwise in two respects: First, most PPC64 relocations are relative
(either to the base address, the TOC, etc.). Second, most relocation targets
are not appropriate for R_PPC64_RELATIVE (which writes a 64-bit absolute
address). Thus, back off, and include only those relocations for which we test
(or soon will), and are obviously appropriate for R_PPC64_RELATIVE.

llvm-svn: 250540
2015-10-16 19:01:50 +00:00
Rafael Espindola 4cda58168a Add a ObjectFile<ELFT>::getSection helper and simplify. NFC.
llvm-svn: 250519
2015-10-16 15:29:48 +00:00
Rui Ueyama c7cc6ecf08 ELF2: Use ELFT to template OutputSections.
This patch is to use ELFT instead of Is64Bits to template OutputSection
and its subclasses. This increases code size slightly because it creates
two identical functions for some classes, but that's only 20 KB out of
33 MB, so it's negligible.

This is as per discussion with Rafael. He's not fan of the idea but OK
with this. We'll revisit later to this topic.

llvm-svn: 250466
2015-10-15 22:27:29 +00:00
Rui Ueyama c6ef3f28fc ELF2: Do not treat .strtab specially when creating sections.
String table is added to end of the file so that all the other sections
are finalized before string table. But we can just add section names to
the string table before calling finalize() on any section instead.

llvm-svn: 250463
2015-10-15 21:50:30 +00:00
Rui Ueyama 5f1eee1aac ELF2: Move HashTableSection::hash out of the class.
Because the function does not depend on the class.

llvm-svn: 250462
2015-10-15 21:27:17 +00:00
Rui Ueyama 2317d0d4d6 Remove a getter/setter that don't hide anything.
llvm-svn: 250458
2015-10-15 20:55:22 +00:00
Rui Ueyama 96b190428e Fix style.
llvm-svn: 250457
2015-10-15 20:55:20 +00:00
Rui Ueyama 6607227fc1 ELF2: Rename SymVA -> SA if SymVA includes addend.
llvm-svn: 250447
2015-10-15 19:52:27 +00:00
Rui Ueyama 9e82fa22e4 ELF2: s/R/SA/ in PPC64 relocations because R is S + A.
llvm-svn: 250445
2015-10-15 19:39:36 +00:00
Rafael Espindola b26d807033 Use OutputSectionBase in a few more places. NFC.
Just making room for having another output section type.

llvm-svn: 250443
2015-10-15 19:31:49 +00:00
Rafael Espindola 826941a69a Rename variable to make it clear it includes the addend.
Thanks to Rui for the suggestion.

llvm-svn: 250437
2015-10-15 18:19:39 +00:00
Rui Ueyama d9189ceb23 ELF2: Implement __start_SECNAME and __stop_SECNAME.
If a section name is valid as a C identifier (which is rare because of
the leading '.'), linkers are expected to define __start_<secname> and
__stop_<secname> symbols. They are at beginning and end of the section,
respectively. This is not requested by the ELF standard, but GNU ld and
gold provide this feature.

llvm-svn: 250432
2015-10-15 17:11:03 +00:00
Hal Finkel 33e17a7c73 [ELF2/PPC64] Error on R_PPC64_ADDR16 overflow
R_PPC64_ADDR16 is not a truncated relocation, and should error if the address
cannot be represented in 16 bits.

llvm-svn: 250424
2015-10-15 16:17:30 +00:00
Hal Finkel 000561c2f5 Revert "r250372 - [ELF2/PPC64] Remove now-dead weak/undef check"
Unfortunately, the check was not as dead as I had thought, and adjusting the
starting VA again exposed the problem. We end up trying to relocate the bl
(using a 24-bit relative offset) to a symbol address of zero, and in general,
that does not fit.

Thus, reverting for now, and adding a test case.

llvm-svn: 250423
2015-10-15 16:12:35 +00:00
Rafael Espindola aa19708f88 Centralize the handling of r_addend. NFC.
When a relocation points to a SHF_MERGE section, the addend has special meaning.
It should be used to find what in the section the relocation points to. It
should not be added to the output position.

Centralizing it means that the above rule will be implemented once, not once
per target.

llvm-svn: 250421
2015-10-15 15:52:12 +00:00
Rafael Espindola ae81a7bf49 Use OutputSectionBase in a few cases where we don't need a OutputSection.
NFC. This is just preparation for adding a new OutputSection dedicated to
SHF_MERGE input sections.

llvm-svn: 250419
2015-10-15 15:29:53 +00:00
Ed Maste cbd42b17c7 Recognize -Bshareable alias for -shared
llvm-svn: 250397
2015-10-15 13:03:16 +00:00
Rafael Espindola 37f0b7d28a Rename CAlloc since it allocates sections, not chunks.
llvm-svn: 250395
2015-10-15 12:33:04 +00:00
Rafael Espindola bdc7620191 Remove unnecessary llvm:: prefix.
llvm-svn: 250394
2015-10-15 12:30:29 +00:00
Hal Finkel 736c741752 [ELF2] Set a target-specific VAStart for PPC64
After some additional post-commit (post-revert) discussion and research, this
reverts, in part, r250205, so the ABI-recommended starting address can be used
on PPC64 (as is done by other linkers).

Also, this addresses the FIXME in ELF/Writer.cpp by making VAStart a
target-dependent property.

llvm-svn: 250378
2015-10-15 07:49:07 +00:00
Hal Finkel ae3f05b987 [ELF2/PPC64] Remove now-dead weak/undef check
After r250311, this check is dead. Remove it.

llvm-svn: 250372
2015-10-15 06:44:19 +00:00