Commit Graph

4552 Commits

Author SHA1 Message Date
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
Rui Ueyama 55c3f89edb ELF2: Do not use OutputSection as a member variable name.
We have OutputSection<ELFT> type. GCC 4.9.2 warns on the duplication.

llvm-svn: 250358
2015-10-15 01:58:40 +00:00
Rafael Espindola 39428e9358 Remove silly getter use.
It was creating a local var with the same name as the member var.

llvm-svn: 250347
2015-10-14 23:30:28 +00:00
Rui Ueyama 690db6786e Simplify.
llvm-svn: 250337
2015-10-14 22:32:10 +00:00
Rui Ueyama 2b675074fe ELF2: Support --entry=<addr>.
If an argument for --entry is a number, that's not a symbol name but
an absolute address. If that's the case, the address is directly set
to ELF header's e_entry.

llvm-svn: 250334
2015-10-14 22:20:57 +00:00
Rui Ueyama efc23de4dd ELF2: Move Target concrete classes from .h to .cpp.
llvm-svn: 250330
2015-10-14 21:30:32 +00:00
Rui Ueyama 80edbbbdf8 ELF2: Remove {set,get}OutputSection accessors.
These accessors didn't provide any additional value over a public
member variable, too.

llvm-svn: 250328
2015-10-14 21:09:55 +00:00
Rui Ueyama edffd91bce ELF2: Remove {set,get}OutputSectionOff accessors.
These accessors didn't provide any additional value over a public
member variable.

llvm-svn: 250326
2015-10-14 21:00:23 +00:00
Rui Ueyama 4fcadaf5e7 ELF2: Merge .{text,rodata,data,bss}.* sections.
Previously, we used input section names as output section names.
That resulted that we created lots of sections for comdat
or -f{function,data}-section sections.

This patch reduces the number of sections by dropping suffix from
all section names which start with ".text.", ".rodata.", ".data."
or ".bss.". GNU linker does this using the internal linker script,
but for LLD I chose to do that directly.

Interestingly, this makes the linker faster. Time to link Clang
is this.

Before:

  real    0m0.537s
  user    0m0.433s
  sys     0m0.104s

After:

  real    0m0.390s
  user    0m0.268s
  sys     0m0.120s

It make sense because previously we created 57659 sections now only 27.

llvm-svn: 250315
2015-10-14 19:21:25 +00:00
Rafael Espindola cc6ebb8e69 Handle dynamic relocs to weak undefined when possible.
llvm-svn: 250311
2015-10-14 18:42:16 +00:00
Rafael Espindola 227556e1c7 Add support for a R_X86_64_32 referring to a plt.
This can show up with a non-PIC .o being linked into an executable that uses
shared libraries.

llvm-svn: 250300
2015-10-14 16:15:46 +00:00
Simon Atanasyan 9c2d788dda [ELF2][mips] Support both big and little endian MIPS 32-bit targets
- Make the `MipsTargetInfo` template class with `ELFType` argument. Use
  the argument to select an appropriate relocation type and read/write
  routines.
- Add template function `add32` to add-and-write relocation value in
  both big and little endian cases. Keep the `add32le` to reduce code
  changes.

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

llvm-svn: 250297
2015-10-14 14:24:46 +00:00
Rui Ueyama 5f551aee02 ELF2: Remove getAddrSize().
llvm-svn: 250296
2015-10-14 14:02:06 +00:00
Hal Finkel 4e961dde16 [ELF2/PPC64] S+A -> R in more places when handling R_PPC64_REL24
We already have a variable, R, that equals S + A. Use it. NFC.

llvm-svn: 250243
2015-10-13 22:54:24 +00:00
Hal Finkel fa92f686bc [ELF2/PPC64] Fix the TOC save in the .plt stub
The comment was right, but the encoding was wrong (and, it seems, I forgot a
test case for the .plt stub).

llvm-svn: 250230
2015-10-13 21:47:34 +00:00
Davide Italiano 355cc52292 [ELF2] Don't allocate entry for DT_SYMBOLIC.
This fixes an oversight from my previous commit. Reported by
Rafael Espindola!

llvm-svn: 250229
2015-10-13 21:39:55 +00:00
Rui Ueyama 38edcec272 ELF2: Add a note about performance.
llvm-svn: 250227
2015-10-13 21:28:02 +00:00
Davide Italiano cebb449e11 [ELF2] Add support for -Bsymbolic.
llvm-svn: 250225
2015-10-13 21:02:34 +00:00
Davide Italiano 10d268d62c [ELF2/Linkerscript] Skip semicolon in linker directives parsing.
The documentation says: "You may separate commands using semicolons",
so they seem to be optional.

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

llvm-svn: 250223
2015-10-13 20:48:56 +00:00
Hal Finkel 515ed44776 [ELF2/PPC64] Fix the end-of-buffer check for TOC restoration
We'd miss the nop if it really did come right at the end of the buffer (nice
off-by-one error).

llvm-svn: 250220
2015-10-13 20:31:33 +00:00
Rui Ueyama 34f2924675 ELF2: Add comments.
llvm-svn: 250215
2015-10-13 19:51:57 +00:00
Hal Finkel 600ff141ec [ELF2] Simplify the NOBITS sorting logic
As Rafael suggested in his review of r250190, we can simplify this by writing
it like the earlier checks.

llvm-svn: 250212
2015-10-13 19:27:12 +00:00
Hal Finkel ea244fcb84 [ELF2] Drop unnecessary lld flags from test/elf2/ppc64-toc-restore.s
As Rafael pointed out in his review of r250110, -dynamic-linker, -rpath and
--export-dynamic are unnecessary.

llvm-svn: 250210
2015-10-13 19:16:56 +00:00
Hal Finkel 9abc2a50b3 [ELF2] Only call getPPC64SectionRank for EM_PPC64 files
Suggested by Rafael in his review of r250100. As Rafael points out, this may
grow into a switch in the future, but regardless, calling this on files for
other architectures is unnecessary.

llvm-svn: 250209
2015-10-13 19:07:29 +00:00
Rui Ueyama deac4909c7 Update README.
llvm-svn: 250208
2015-10-13 18:55:59 +00:00
Hal Finkel 08be61407b [ELF2] Fixup comment about section sorting requirements
As Rafael pointed out in his review of r250100, the NOBITS check is no longer
the last requirement.

llvm-svn: 250206
2015-10-13 18:55:01 +00:00
Hal Finkel d962ef0bf8 Revert: "Re: [lld] r249752 - Revert: r249728 - Roll back r249726 and r249723 because they broke buildbots."
This has turned out to be unnecessary, and while some ability to set VAStart
will be needed at some point, this is not clearly the right direction.

llvm-svn: 250205
2015-10-13 18:50:28 +00:00
Rui Ueyama 93bfee5f70 ELF2: Avoid using "finalize" as a function name.
"finalize" does not give a hint about what that function is actually
going to do. This patch make it more specific by renaming scanShlibUndefined.
Also add a comment that we basically ignore undefined symbols in DSOs except
this function.

llvm-svn: 250191
2015-10-13 18:10:33 +00:00
Hal Finkel 0d7e83bbc4 [ELF2] Ensure strict weak ordering in section sorting (v2)
The fix in r250109 to ensure a strict weak ordering in the section sorting was
a bit overzealous. We only use the NOBITS comparison if either A or B is a
NOBITS section. Otherwise, we fall through to the target-specific ranking
function. Failure to do this causes the sorting to fail in cases where, for
example, a .dynamic section happens to end up in between .got and .toc, etc. in
the initial ordering (.dynamic has a type SHT_DYNAMIC, compared to SHT_PROGBITS
or SHT_NOBITS).

llvm-svn: 250190
2015-10-13 17:57:46 +00:00
Rui Ueyama c58656c7c0 Revert r250169: "This patch implements basic variant of lazy loading for x86_x64 and for X86 targets."
With this patch LLD is not able to self-host on x86-64 Linux.

llvm-svn: 250182
2015-10-13 16:59:30 +00:00
Rui Ueyama c2c22f44bf Remove extra semicolons for -Wpedantic.
llvm-svn: 250178
2015-10-13 16:44:13 +00:00
Rui Ueyama f8432d97f3 ELF2: Fix BSD's __progname symbol issue.
BSD's DSO files have undefined symbol "__progname" which is defined
in crt1.o. On that system, both user programs and system shared
libraries depend on each other.

In general, we need to put symbols defined by user programs which are
referenced by shared libraries to user program's .dynsym.

http://reviews.llvm.org/D13637

llvm-svn: 250176
2015-10-13 16:34:14 +00:00
Rui Ueyama e717a7195b ELF2: Rename ElfKind -> EKind.
ELFKind as a type name and ElfKind is a variable name was too subtle.

llvm-svn: 250172
2015-10-13 16:20:50 +00:00
Rui Ueyama 7b94893cec ELF2: Fix typos in comment.
llvm-svn: 250171
2015-10-13 16:15:50 +00:00
Rui Ueyama adf666010f Remove trailing whitespaces.
llvm-svn: 250170
2015-10-13 16:13:18 +00:00
George Rimar 9fd8fcb5a4 This patch implements basic variant of lazy loading for x86_x64 and for X86 targets.
What was done:
1) .got.plt section is created for functions that requires PLT. .got.plt has 3 predefined empty entries now that are required for dynamic linker.
Also other new items created are configured to have correct jump to PLT[N].
2) PLT section now has PLT[0] entry, also others ones are configured to support PLT->GOT(.got.plt) calls.
3) Implemented .rel[a].plt sections (based on patch http://reviews.llvm.org/D13569).
4) Fixed plt relocations types (based on patch http://reviews.llvm.org/D13589).

NOTES:
The .plt.got zero entry is still empty now. According to ELF specification it should hold the address of the dynamic structure, referenced with the symbol
_DYNAMIC. The _DYNAMIC entry points to the .dynamic section which contains information used by the ELF interpreter to setup the binary.

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

llvm-svn: 250169
2015-10-13 16:09:55 +00:00
Rui Ueyama 9100439391 ELF2: Move createTarget to Target.cpp.
Now all Target<Arch> classes are used only in Target.cpp.
We can put them in an anonymous namespace. In order to avoid
merge conflict with other people's patches, I'll do that later.

llvm-svn: 250168
2015-10-13 16:08:15 +00:00
Rui Ueyama e7e3348aa3 ELF2: Remove dead code.
This code is completely a stub. We can resurrect when we start working on ARM.

llvm-svn: 250167
2015-10-13 16:03:39 +00:00
George Rimar 53b581c522 Removed undefined and unused member. NFC.
llvm-svn: 250163
2015-10-13 15:16:01 +00:00
Rafael Espindola 7f10746be0 Remove unnecessary include.
llvm-svn: 250161
2015-10-13 14:54:49 +00:00
Rafael Espindola 7a51305c91 Simplify by using Out<ELFT>::Opd.
Also avoid extra dependencies on the section name.

llvm-svn: 250159
2015-10-13 14:45:51 +00:00
Rafael Espindola 2a4b27111d Remove the EKind member variable.
Now that the base class is templated, it is redundant with the type.

llvm-svn: 250139
2015-10-13 01:17:02 +00:00
Rui Ueyama f03f3cc18c Use llvm::sys::path::is_absolute instead of my own.
llvm-svn: 250133
2015-10-13 00:09:21 +00:00
Rui Ueyama 63d8880b38 Fix test breakage on Windows.
llvm-svn: 250127
2015-10-12 23:49:04 +00:00
Michael J. Spencer 18255a333e [elf2] Tighten up test.
llvm-svn: 250126
2015-10-12 23:44:22 +00:00
Michael J. Spencer 350e5b5cc2 [elf2] Inline needsDynamicSections.
llvm-svn: 250125
2015-10-12 23:39:23 +00:00
Hal Finkel daedc12172 [ELF2/PPC64] Resolve local-call relocations using the correct function-descriptor values
Under PPC64 ELF v1 ABI, the symbols associated with each function name don't
point directly to the code in the .text section (or similar), but rather to a
function descriptor structure in a special data section named .opd. The
elements in the .opd structure include a pointer to the actual code, and a the
relevant TOC base value. Both of these are themselves set by relocations.

When we have a local call, we need the relevant relocation to refer directly to
the target code, not to the function-descriptor in the .opd section. Only when
we have a .plt stub do we care about the address of the .opd function
descriptor itself.

So we make a few changes here:

 1. Always write .opd first, so that its relocated data values are available
    for later use when writing the text sections. Record a pointer to the .opd
    structure, and its corresponding buffer.

 2. When processing a relative branch relocation under ppc64, if the
    destination points into the .opd section, read the code pointer out of the
    function descriptor structure and use that instead.

This this, I can link, and run, a dynamically-compiled "hello world"
application on big-Endian PPC64/Linux (ELF v1 ABI) using lld.

llvm-svn: 250122
2015-10-12 23:16:53 +00:00
Davide Italiano 9159ce9327 [ELF2/LinkerScript] Implement parsing of OUTPUT_ARCH() command.
Differential Revision:	 http://reviews.llvm.org/D13675

llvm-svn: 250115
2015-10-12 21:50:08 +00:00
Hal Finkel 87bbd5ffd4 [ELF2] Allow PPC64 to add the TOC-restore after .plt-based relocations
Under the PPC64 ELF ABI, functions that might call into other modules (and,
thus, need to load a different TOC base value into %r2), need to restore the
old value after the call. The old value is saved by the .plt code, and the
caller only needs to include a nop instruction after the call, which the linker
will transform into a TOC restore if necessary.

In order to do this the relocation handler needs two things:

 1. It needs to know whether the call instruction it is modifying is targeting
    a .plt stub that will load a new TOC base value (necessitating a restore after
    the call).

 2. It needs to know where the buffer ends, so that it does not accidentally
    run off the end of the buffer when looking for the 'nop' instruction after the
    call.

Given these two pieces of information, we can insert the restore instruction in
place of the following nop when necessary.

llvm-svn: 250110
2015-10-12 21:19:18 +00:00
Hal Finkel cf58b6a48c [ELF2] Ensure strict weak ordering in section sorting
As pointed out by Rui (post-commit review), we need to always return based on
the section type when the types differ to ensure a strict weak ordering.

llvm-svn: 250109
2015-10-12 21:14:03 +00:00
Hal Finkel ee44e2401b test/elf2/relative-dynamic-reloc-ppc64.s requires ppc
Fix the buildbot; this test also requires ppc target support.

llvm-svn: 250107
2015-10-12 21:11:53 +00:00
Davide Italiano 6836c6182d [ELF2/LinkerScript] Fix OUTPUT_FORMAT directive parsing
Differential Revision:	 http://reviews.llvm.org/D13668

llvm-svn: 250106
2015-10-12 21:08:41 +00:00
Hal Finkel 66a123806e [ELF2] Fixup test case for TOC relocation
Now that the target relocation handle will see R_PPC64_TOC, fix the test case
accordingly.

llvm-svn: 250104
2015-10-12 21:04:40 +00:00
Hal Finkel be0823dcc4 [ELF2] Implement PPC64TargetInfo::isRelRelative
This is essentially pattern-matching against the x86 target, and generates the
analogous PPC64 relocation.

llvm-svn: 250102
2015-10-12 20:58:52 +00:00
Hal Finkel 3c8cc677e6 [ELF2] Add a base set of PPC64 relocations
This is mostly an adaptation of the code in LLVM's
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp, and handles a sufficient
number of relocations to link a 'hello world' program on big-Endian PPC64/Linux
(ELF v1 ABI).

llvm-svn: 250101
2015-10-12 20:56:18 +00:00
Hal Finkel 3bae2d8733 [ELF2] Sort PPC64 special sections
PPC64 has several special sections that are intended to be accessed from the
TOC base pointer. When a .got is present, the TOC base pointer is .got + 0x8000
(as specified by the ABI). Furthermore, the glibc startup code contains an
assumption that a 16-bit relocation can hold the offset from the TOC base value
to the beginning of the .toc section. Thus, we need to make sure that .toc
appears after .got. This much, at least, is required in practice. The other
PPC64 special sections (.toc, .toc1, .opd, etc.) should also be close by to
optimize access by smaller TOC-base-pointer offsets.

llvm-svn: 250100
2015-10-12 20:51:48 +00:00
Rui Ueyama bb3c33609b Continue early to reduce indentation.
llvm-svn: 250096
2015-10-12 20:28:23 +00:00
Rui Ueyama 126d08f891 ELF2: Create a function to get VA from Elf_Rel.
And remove git getLocalSymVA because there's no user of the function anymore.

llvm-svn: 250095
2015-10-12 20:28:22 +00:00
Hal Finkel c848b321fd [ELF2/PPC64] Add a comment about the page size
Rafael requested some additional commentary (post-commit review of r249760), to
make it clear this is intended and necessary.

llvm-svn: 250087
2015-10-12 19:34:29 +00:00
Rui Ueyama 242ddf4037 Instead of computing offset from current and start, use a variable. NFC.
llvm-svn: 250080
2015-10-12 18:56:36 +00:00
Rui Ueyama c538b13a1a Remove break after error because error is _Noreturn.
llvm-svn: 250079
2015-10-12 18:53:12 +00:00
Rui Ueyama 3d45179d56 ELF2: Split SymbolTable::addFile(). NFC.
llvm-svn: 250073
2015-10-12 18:03:21 +00:00
Rui Ueyama 26479c3883 ELF2: Verify that weak undefined symbols won't add DT_NEEDED.
In order to actually verify the condition, we have to use a weak symbol.
If an undefined symbol is not used at all, it is naturally ignored not by
the code for --as-needed but by the code for something else.

llvm-svn: 250062
2015-10-12 16:25:33 +00:00
Rui Ueyama 1613c018d4 ELF2: Do not put temporary files to the test toplevel directory.
llvm-svn: 250057
2015-10-12 15:58:38 +00:00
Rui Ueyama 1c42afcbdc Remove explicit Twine instantiation if possible.
llvm-svn: 250055
2015-10-12 15:49:06 +00:00
Rui Ueyama 361d8b9350 Early return.
llvm-svn: 250054
2015-10-12 15:49:02 +00:00
Rui Ueyama c4b6506521 ELF2: Move createELFFile() from .h to .cpp.
llvm-svn: 250051
2015-10-12 15:31:09 +00:00
Rui Ueyama 2ee8e113ba Remove redundant namespace specifiers.
llvm-svn: 250050
2015-10-12 15:27:09 +00:00
Rui Ueyama 0cef68913e ELF2: Handle default entry name in the driver.
llvm-svn: 250048
2015-10-12 15:23:54 +00:00
Rui Ueyama 4702b86176 Fix indentation.
llvm-svn: 250047
2015-10-12 15:15:45 +00:00
Simon Atanasyan 3b732ac7ee [ELF2][mips] Support R_MIPS_32 relocation
llvm-svn: 250045
2015-10-12 15:10:02 +00:00
Rafael Espindola fb677dfd73 Make getStaticELFKind a member function now that we can.
llvm-svn: 250031
2015-10-12 12:14:30 +00:00
Rafael Espindola b9ca7bb6ab Delete getFirstELF.
llvm-svn: 250030
2015-10-12 11:52:31 +00:00
Rafael Espindola 9b278a1695 This doesn't need to be virtual anymore.
llvm-svn: 250028
2015-10-12 11:26:55 +00:00
Rafael Espindola dfce5a25cb Simplify the InputFile type hierarchy by removing unnecessary middle classses.
llvm-svn: 250006
2015-10-12 02:22:58 +00:00
Rafael Espindola af70764aa1 Simplify the InputFile type hierarchy.
Now that the SymbolTable is templated, we don't need the ELFData class or
multiple inheritance.

llvm-svn: 250005
2015-10-12 01:55:32 +00:00
Rui Ueyama 35da9b6e1c ELF2: Implement --as-needed.
This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit
is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed
bit is off by default. When we adds a symbol to the symbol table for dynamic
linking, we set its SharedFile's IsUsed bit.

If AsNeeded is set but IsUsed is not set, we don't want to write that
file's SO name to DT_NEEDED field.

http://reviews.llvm.org/D13579

llvm-svn: 249998
2015-10-11 20:59:12 +00:00
Rafael Espindola 9afbac479f Handle a crash in conflict detection with archive members.
llvm-svn: 249996
2015-10-11 20:19:20 +00:00
Rui Ueyama a561e78447 Clang-format.
llvm-svn: 249992
2015-10-11 19:46:00 +00:00
Rui Ueyama 536c999d93 Rename phdr{Copy,Set} -> {set,copy}Phdr.
They are functions, so they should be verbs.

llvm-svn: 249991
2015-10-11 19:45:58 +00:00
Rui Ueyama c6e1b97161 ELF2: Remove ArgParser class and define parseArgs() function instead.
ArgParser was a class with only one member function, so it didn't
have to be a class.

llvm-svn: 249988
2015-10-11 18:19:01 +00:00
Rui Ueyama 3486fe53dd ELF2: Use SmallPtrSet instead of unordered_set.
This patch addresses Rafael's review comments to r249955.

llvm-svn: 249987
2015-10-11 17:44:22 +00:00
Davide Italiano 4e47d589e6 [ELF2] Implement -T/--script.
This one tests more carefully SEARCH_DIR() as an added bonus.

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

llvm-svn: 249969
2015-10-11 03:53:36 +00:00
Rafael Espindola 525914defd Detect incompatible files when one of them comes from an archive.
llvm-svn: 249968
2015-10-11 03:36:49 +00:00
Rui Ueyama 52a1509ea7 ELF2: LinkerScript: Interpret -l and = file name prefixes.
In the linker script, -l and = have the same meaning as in the command line.
In addition to that, if a path is not absolute, the path needs to be searched
from the search paths. This patch implements them.

llvm-svn: 249967
2015-10-11 03:28:42 +00:00
Rui Ueyama 4b02ca99d0 ELF: Move utility functions from Driver to DriverUtils.
llvm-svn: 249966
2015-10-11 03:28:39 +00:00
Rui Ueyama cacf967ed5 ELF2: Simplify. NFC.
llvm-svn: 249965
2015-10-11 02:22:31 +00:00
Rui Ueyama a467240309 ELF2: Add --verbose.
It is currently not actually verbose but rather terse,
but that's intentional.

llvm-svn: 249964
2015-10-11 02:03:03 +00:00
Rui Ueyama b973256683 ELF2: Manage BumpPtrAllocator ownership better.
Previously, each ArgParser owned a BumpPtrAllocator, and arguments parsed
by an ArgParser would refer strings allocated using the BumpPtrAllocator
only when response files were used. This could cause a subtle bug because
such ownership was not obvious.

This patch moves the ownership from ArgParser to Driver and make the
ownership explicit.

llvm-svn: 249963
2015-10-11 01:53:07 +00:00
Rui Ueyama a47ee68d8e ELF2: Do not leak MemoryBuffers.
llvm-svn: 249962
2015-10-11 01:53:04 +00:00
Rui Ueyama 00f972728b ELF2: LinkerScript: Handle INPUT as a synonym for GROUP.
In our name resolution algorithm, --start-group and --end-group have
no special meaning.

llvm-svn: 249961
2015-10-11 01:31:57 +00:00
Rui Ueyama 31aa1f83de ELF2: LinkerScript: Implement INCLUDE directive.
llvm-svn: 249960
2015-10-11 01:31:55 +00:00
Rui Ueyama bdca0b1fac ELF2: Use memcpy to vector contents.
llvm-svn: 249959
2015-10-11 00:10:36 +00:00
Rui Ueyama 953c2c4b2d ELF2: Remove Writer member varaibles that are used only by one function.
llvm-svn: 249958
2015-10-10 23:59:57 +00:00
Rui Ueyama 69960baad5 ELF2: Write .interp section on the first page in the exectuable.
Previously, we reserved the first page for the program header, so no
sections would be written to very beginning of the output file.
FreeBSD requires .interp section be exist on the first page, so that
was not good.

This patch calculates the size of the program header and then assign
addresses to the sections. Now the first section is located next to
the program header. Because the first section is .interp, it's very
likely to be on the first page.

llvm-svn: 249957
2015-10-10 23:25:39 +00:00
Rui Ueyama 5bfd7d4e00 ELF2: Remove a variable to which always the same value is assigned.
llvm-svn: 249956
2015-10-10 22:36:36 +00:00
Rui Ueyama 2f1b79fc3a ELF2: Remove ProgramHeader class and use Elf_Phdr directly. NFC.
llvm-svn: 249955
2015-10-10 22:34:30 +00:00
Rui Ueyama ff77768569 ELF2: Move Target and entry initialization from SymbolTable to Driver.
SymbolTable was not a right place for initialization. We had to do that
because Driver didn't know what type of ELF objects are being handled.
We taught Driver that, so we can now move this code to Driver.

llvm-svn: 249904
2015-10-09 21:12:40 +00:00
Rui Ueyama 3ce825ed26 ELF2: Make SymbolTable a template class.
SymbolTable was not a template class. Instead we had switch-case-based
type dispatch to call desired functions. We had to do that because
SymbolTable was created before we know what ELF type objects had been
passed.

Every time I tried to add a new function to the symbol table, I had to
define a dispatcher which consist of a single switch statement.

It also brought an restriction what the driver can do. For example,
we cannot add undefined symbols before any files are added to the symbol
table. That's because no symbols can be added until the symbol table
knows the ELF type, but when it knows about that, it's too late.

In this patch, the driver makes a decision on what ELF type objects
are being handled. Then the driver creates a SymbolTable object for
an appropriate ELF type.

http://reviews.llvm.org/D13544

llvm-svn: 249902
2015-10-09 21:07:25 +00:00
Rui Ueyama 6ccc8ca6d9 Simplify. NFC.
llvm-svn: 249895
2015-10-09 20:32:54 +00:00
Rui Ueyama d888d10cf4 ELF2: Reduce code repetition.
llvm-svn: 249882
2015-10-09 19:34:55 +00:00
Rafael Espindola 444576d4c4 Add support for comdats.
The implementation is a direct translation to c++ of the rules in the ELF spec.

llvm-svn: 249881
2015-10-09 19:25:07 +00:00
Rafael Espindola 26fd69de90 Don't silently ignore an error.
Found by inspection.

llvm-svn: 249843
2015-10-09 16:15:57 +00:00
Rui Ueyama af311c1d01 ELF2: Call OutputSection::finalize() from createSections.
Previously, we did this in assignAddresses(), but finalization was
not part of assigning addresses, so this is a better place.

llvm-svn: 249842
2015-10-09 16:03:53 +00:00
Rui Ueyama bf3fd7c9a0 ELF2: Emit a PT_PHDR header as the first entry of the program header.
PT_PHDR entry points to the program header itself.

llvm-svn: 249839
2015-10-09 15:31:49 +00:00
Rafael Espindola d540919ff1 Revert "[ELF2] - Implemented rel[a].plt sections"
This reverts commit r249816.

It broke building llvm with lld:

$ ./bin/FileCheck
./bin/FileCheck: error while loading shared libraries: unexpected PLT reloc type 0x06

I think the only thing that is wrong with this patch is that it is too soon.

The plt we create (and its relocs) don't support lazy loading, so they have
to be relocated as ordinary dynamic relocations.

llvm-svn: 249835
2015-10-09 14:25:49 +00:00
Igor Kudrin 65bddeaacf [ELF2] Check for TLS mismatch in symbol resolution.
The linker should generate an error if a TLS symbol is resolved
for a non-TLS reference and vice versa.

The patch addresses PR24244 (https://llvm.org/bugs/show_bug.cgi?id=24244)

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

llvm-svn: 249817
2015-10-09 09:58:39 +00:00
George Rimar b352b9ce69 [ELF2] - Implemented rel[a].plt sections
.rela.plt contains list of elements in the PLT, which are liable to the relocation during the dynamic linking.

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

llvm-svn: 249816
2015-10-09 09:58:08 +00:00
Rui Ueyama fe7eeed585 ELF2: Sort. NFC.
llvm-svn: 249803
2015-10-09 02:46:28 +00:00
Rui Ueyama 36f69229e6 Simplify expressions. NFC.
llvm-svn: 249793
2015-10-09 00:50:05 +00:00
Rui Ueyama 49c68a7cf7 Remove getters/setters that don't provide much abstraction.
llvm-svn: 249791
2015-10-09 00:42:06 +00:00
Rui Ueyama 964ffb3e11 Define --output= as an alias to -o.
llvm-svn: 249789
2015-10-09 00:33:44 +00:00
Rui Ueyama 5a9640be32 ELF2: Split Writer::createSections into small functions.
Also added a few comments.

llvm-svn: 249781
2015-10-08 23:49:30 +00:00
Rui Ueyama 00851fdf4c Use uintX_t instead of unsigned int to fix potential cross-linking issue.
llvm-svn: 249765
2015-10-08 22:43:55 +00:00
Hal Finkel e3c2626aa4 [ELF2] Make the system page size a target-dependent property
The required page alignment is different on different targets. On PowerPC, for
example, we need 64K pages (the loader won't set different permissions on a
finer granularity than that). I've set the existing targets to what I believe
to be the correct values, and have updated the regression tests accordingly.

llvm-svn: 249760
2015-10-08 22:23:54 +00:00
Hal Finkel 6c2a3b8368 [ELF2] Make the .plt entry size target dependent
The size of a .plt entry is different on different targets (it is,
specifically, much larger than 8 on all PPC ABIs). There is no functional
change here (later patches to create .plt entries for PPC64 will depend on this
change).

llvm-svn: 249756
2015-10-08 21:51:31 +00:00
Hal Finkel 4729064a1c Revert: r249728 - Roll back r249726 and r249723 because they broke buildbots.
Reapply r249726 (and r249723), hopefully with the correct test fixups this time.

Original commit message:

Address a FIXME in ELF/Writer.cpp: Make VAStart a target-dependent property.
I've set the values for the existing targets to what I believe to be the
correct values, and updated the regression tests accordingly.

llvm-svn: 249752
2015-10-08 21:25:04 +00:00
Rui Ueyama 1890799f0c Re-apply r249630: ELF2: Use `-flavor gnu2` after `not` to fix Windows buildbot.
Thanks to George Rimar's r249696, `not` is now able to find ld.lld2
executable correctly.

llvm-svn: 249746
2015-10-08 20:57:29 +00:00
Rafael Espindola 6390d16fd1 Don't silently ignore an error.
Found by inspection.

llvm-svn: 249744
2015-10-08 20:43:19 +00:00
Rafael Espindola 98af66f9c5 Make this test a bit stricter.
The only way for SecIndex to be zero in here is for an extended section
number to be zero, which would be an error.

llvm-svn: 249736
2015-10-08 20:29:22 +00:00
Rui Ueyama af21d92320 ELF2: Do not pass GotVA because it's accessible as Out<ELFT>::Got->getVA().
llvm-svn: 249729
2015-10-08 20:06:07 +00:00
Rui Ueyama 7114f0597b Roll back r249726 and r249723 because they broke buildbots.
llvm-svn: 249728
2015-10-08 20:00:02 +00:00
Hal Finkel 1cbf51a41b [ELF2] Add missing test fixup after r249723
llvm-svn: 249726
2015-10-08 19:53:12 +00:00
Hal Finkel eb84ce8bd1 [ELF2] Make VAStart a target-dependent property
Address a FIXME in ELF/Writer.cpp: Make VAStart a target-dependent property.
I've set the values for the existing targets to what I believe to be the
correct values, and updated the regression tests accordingly.

llvm-svn: 249723
2015-10-08 19:36:39 +00:00
Hal Finkel cbd21a6ad2 [ELF2] Use EntrySize, not 8, to advance the .plt buffer when writing
In preparation for making the size of a .plt entry target dependent, use the
existing EntrySize variable when writing (instead of a hard-coded value). NFC.

llvm-svn: 249720
2015-10-08 19:16:05 +00:00
George Rimar 48570f1f4b [ELF2] Test for i686 relocations updated with comments.
Reviewed by Rafael. 

llvm-svn: 249719
2015-10-08 18:58:10 +00:00
Rafael Espindola 79e4452535 Test that we handle empty archives.
This was failing before 249709.

llvm-svn: 249710
2015-10-08 18:10:53 +00:00
Davide Italiano 68a39a6565 [ELF2] Implement linker script SEARCH_DIR() directive.
llvm-svn: 249707
2015-10-08 17:51:41 +00:00
Simon Atanasyan 456bd05d97 [ELF2][mips] Support elf32ltsmip/elf32btsmip target emulation as the -m arguments
llvm-svn: 249683
2015-10-08 12:13:38 +00:00
Rafael Espindola d42f4e5389 Add a convenience variable. NFC.
llvm-svn: 249682
2015-10-08 12:02:38 +00:00
Denis Protivensky 90c5099e8a [ELF2] Add ENTRY command to the linker script
Set ENTRY as an entry point if -e is not specified.

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

llvm-svn: 249661
2015-10-08 06:48:38 +00:00
Rui Ueyama 10c415fd63 Remove a default which immediately breaks.
getID()'s return type is unsigned int, so I don't think we need this
default for -Wswitch-enum.

llvm-svn: 249650
2015-10-08 03:21:29 +00:00
Rui Ueyama aca48ffb41 ELF2: Inititalize other symbols only once as well.
llvm-svn: 249645
2015-10-08 00:44:28 +00:00
Rui Ueyama 833ce281db ELF2: Make member variable names shorter.
I'm going to use them in other patches, and the names feel too long
despite their narrow scope.

llvm-svn: 249642
2015-10-08 00:29:00 +00:00
Rui Ueyama 9ea49c7948 ELF2: Initialize SyntheticOptional only once.
llvm-svn: 249636
2015-10-07 23:46:11 +00:00
Rui Ueyama e66e001c90 ELF2: Use the same name as COFF.
llvm-svn: 249635
2015-10-07 23:20:23 +00:00
Davide Italiano 8d9ace60ca [ELF/AArch64] Add tests to verify we handle overflow correctly for relocs.
llvm-svn: 249634
2015-10-07 23:15:22 +00:00
Rui Ueyama f82a0eef13 ELF2: Use `-flavor gnu2` after `not` to fix Windows buildbot.
`not` command on Windows is not able to find an executable from PATH
if a given command already has an extension even if the extension is
not ".exe".

llvm-svn: 249630
2015-10-07 22:20:43 +00:00
Davide Italiano c3858ab82e [ELF2] Garbage collect or{16,64}le. They're now unused.
llvm-svn: 249628
2015-10-07 22:11:20 +00:00
Davide Italiano 06d843226b [ELF2/AArch64] _ABS* relocations don't read contents. Fix it.
Spotted by: Rafael Espindola.

llvm-svn: 249627
2015-10-07 22:10:02 +00:00
Rui Ueyama e1f91529c8 ELF2: Rename dupError() -> reportConflict().
llvm-svn: 249622
2015-10-07 21:37:24 +00:00
Rui Ueyama 0d0bcf7433 ELF2: Stop using SymbolTableSection as a container for SymbolTable.
`Symtab` is better than `Out<ELFT>::SymTab->getSymTable()`.

llvm-svn: 249619
2015-10-07 21:25:39 +00:00
Rui Ueyama 2cac5843a0 ELF2: Define a utility function to handle simple command line options.
llvm-svn: 249592
2015-10-07 19:34:51 +00:00
Rui Ueyama 15ef5e174b ELF2: Make singleton output sections globally accessible.
Previously, output sections that are handled specially by the linker
(e.g. PLT or GOT) were created by Writer and passed to other classes
that need them. The problem was that because these special sections
are required by so many classes, the plumbing work became too much
burden.

This patch is to simply make them accessible from anywhere in the
linker to eliminate the plumbing work once and for all.

http://reviews.llvm.org/D13486

llvm-svn: 249590
2015-10-07 19:18:16 +00:00
George Rimar 730c27894a [ELF2] - fix to use PLT/GOT for DSO function calls (X86TargetInfo)
Differential Revision: http://reviews.llvm.org/D13522

llvm-svn: 249588
2015-10-07 18:46:13 +00:00
Rui Ueyama 75230398c2 ELF2: De-templatize writeResult for simplicity.
llvm-svn: 249586
2015-10-07 18:29:51 +00:00
Rui Ueyama 58d7d704d8 Style fix.
llvm-svn: 249584
2015-10-07 18:22:46 +00:00
Rafael Espindola 87c647aee1 Remove remaining uses of "-flavor gnu2".
llvm-svn: 249582
2015-10-07 18:20:07 +00:00
Rui Ueyama 60fe7fcc6b ELF2: Use ld.lld2 instead of lld -flavor gnu2.
llvm-svn: 249573
2015-10-07 17:31:39 +00:00
Rui Ueyama b4908761f8 ELF2: Rename local variable name `Out` in preparation to define `Out` global var.
llvm-svn: 249568
2015-10-07 17:04:18 +00:00
Rui Ueyama 0db335fd5e ELF2: Move functions out of line.
llvm-svn: 249566
2015-10-07 16:58:54 +00:00
George Rimar 97aad172b8 [ELF2] -z now option implemented
When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called.

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

llvm-svn: 249551
2015-10-07 15:00:21 +00:00
Denis Protivensky 1ef7b3ff55 [ELF2] Handle -m option
Parse and apply emulation given with -m option.
Check input files to match ELF type and machine architecture provided with -m.

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

llvm-svn: 249529
2015-10-07 09:13:03 +00:00
Denis Protivensky 92aa1c02df [ELF2] Fix gcc build error
llvm-svn: 249524
2015-10-07 08:21:34 +00:00
Rafael Espindola cea0b3b45d Don't create dynamic relocations for weak undefined symbols.
llvm-svn: 249520
2015-10-07 04:22:55 +00:00
Rafael Espindola e782f673a8 Skip entries handled by the dynamic linker.
We were writing got entries in the first positions, not in the positions
corresponding to locally defined symbols.

llvm-svn: 249518
2015-10-07 03:56:05 +00:00
Rafael Espindola c05ad3dedb Create linker generated symbols earlier.
We were incorrectly deciding that a dynamic relocation was needed for them.

llvm-svn: 249512
2015-10-07 02:51:44 +00:00
Rafael Espindola cbffa8cc97 Add missing % to t2.so.
llvm-svn: 249505
2015-10-07 02:01:47 +00:00
Rafael Espindola 52dca345db Create simpler dynamic relocations for local symbols in got.
If the symbol is not preemptable, we can use a R_X86_64_RELATIVE.

llvm-svn: 249496
2015-10-07 00:58:20 +00:00
Rui Ueyama ee59282bfd ELF2: Implement OUTPUT() linker script directive.
llvm-svn: 249491
2015-10-07 00:25:09 +00:00
Rafael Espindola 3378526f34 Fix typo.
llvm-svn: 249488
2015-10-07 00:15:43 +00:00
Rafael Espindola a662738e02 Don't create dynamic relocations when its known what the got points to.
llvm-svn: 249485
2015-10-06 23:56:53 +00:00
Rafael Espindola 4b81795c2a Update tests for upcoming change.
I am about to change lld to avoid creating unnecessary got entries for locally
defined symbols when creating executables.

Update tests that were depending on the current behavior.

llvm-svn: 249474
2015-10-06 21:52:48 +00:00
Michael J. Spencer f32446fb65 [elf2] Correctly determine if we should ignore missing __tls_get_addr.
llvm-svn: 249462
2015-10-06 20:39:09 +00:00
Davide Italiano aad4402097 [ELF2] Address r249428 post comit review. Style + test trim.
llvm-svn: 249451
2015-10-06 20:02:15 +00:00
Michael J. Spencer fcacad263a [elf2] Fix style.
llvm-svn: 249450
2015-10-06 19:57:05 +00:00
Rui Ueyama ee8c53bbe2 ELF2: Inline small functions.
llvm-svn: 249449
2015-10-06 19:57:01 +00:00
Rui Ueyama b5fb88584a ELF2: Update README.
llvm-svn: 249447
2015-10-06 19:21:13 +00:00
Davide Italiano ef4be6b4fe [ELF2/AArch64] Function names should start with a verb (lower case).
Pointed out by: Rafael Espindola.

llvm-svn: 249443
2015-10-06 19:01:32 +00:00
Rui Ueyama 87bc41bcee ELF2: Use shorter names before this file grows larger.
llvm-svn: 249441
2015-10-06 18:54:43 +00:00
Rui Ueyama 33bb1a23b3 ELF2: or{16,32,64}le should really do bitwise-OR.
llvm-svn: 249436
2015-10-06 18:11:18 +00:00
Rui Ueyama 190beb3144 ELF2: Define or{16,32,64}le that are analogous to add32le.
llvm-svn: 249435
2015-10-06 18:08:03 +00:00
Davide Italiano c39c75dee4 [ELF2] Implement --{enable, disable}-new-dtags options.
llvm-svn: 249428
2015-10-06 16:20:00 +00:00
Rafael Espindola 85a6e0f870 Never fetch members for weak undefined symbols.
We were still fetching them when the archive was seen first.

We should experiment with just letting lazy symbols get to compare, it
might be cleaner for ELF.

llvm-svn: 249417
2015-10-06 15:18:50 +00:00
Rafael Espindola b90582dbbd Avoid recursive calls to init (we would crash).
llvm-svn: 249412
2015-10-06 15:03:52 +00:00
Rafael Espindola 8614c566e2 Handle strong undefined symbols fetching members after a weak undefined.
This is a case that requires --start-group --end-group with regular ELF
linkers. Fortunately it is still possible to handle it with lazy symbols without
taking a second look at archives.

Thanks to Michael Spencer for the bug report.

llvm-svn: 249406
2015-10-06 14:33:58 +00:00
Rafael Espindola 6f4bd532d3 Rearrange a bit for clarity. NFC.
llvm-svn: 249404
2015-10-06 14:17:53 +00:00
Rafael Espindola 03ab3368a0 External symbols need a full dynamic reloc, not R_X86_64_RELATIVE.
We were already doing the right thing if the symbol was seen in a shared
library, but not if it was completely missing.

llvm-svn: 249397
2015-10-06 12:39:58 +00:00
George Rimar d01ffbdb1b Fixed typo
llvm-svn: 249393
2015-10-06 12:08:08 +00:00
Michael J. Spencer 6e78d16b3b [elf2] Address style comments.
llvm-svn: 249368
2015-10-06 02:13:54 +00:00
Michael J. Spencer 95538ca99a [elf2] Add __preinit_array, and __fini_array start and end symbols.
llvm-svn: 249367
2015-10-06 01:16:17 +00:00
Michael J. Spencer 4c46f57a49 [elf2] Ignore __tls_get_addr when static linking.
llvm-svn: 249365
2015-10-06 00:45:42 +00:00
Rafael Espindola 41127ad7af Fix R_X86_64_RELATIVE for local symbols that refer to other sections.
We were mixing up the relocated and target sections.

llvm-svn: 249360
2015-10-05 22:49:16 +00:00
Davide Italiano b4606e183e [ELF2/AArch64] Read the right amount of bytes.
This was clearly wrong (thanks Rui for spotting), and I honestly would 
like to get this tested so such mistakes won't repeat. Unfortunately, I
wasn't (easily) able to craft a test that exposes the bad behavior.
Ideally, we would like to get tests of this kind for all relocations, but
at the time of writing, this is not true. So, for now just fix this bug
and try to re-evaluate a way to test this in the future.

llvm-svn: 249359
2015-10-05 22:43:42 +00:00
Rafael Espindola 9c3e4d2af5 Handle a common symbol needing a R_X86_64_RELATIVE.
llvm-svn: 249357
2015-10-05 21:23:08 +00:00
Rafael Espindola 3c83e2bbfb Include existing addend when computing R_X86_64_RELATIVE.
llvm-svn: 249353
2015-10-05 21:09:37 +00:00
Rafael Espindola d75fbd221d Make this test a bit more strict.
Before the ADDR variables could match the empty string.

llvm-svn: 249350
2015-10-05 20:54:39 +00:00
Rafael Espindola ae24400424 Create R_X86_64_RELATIVE when needed.
The dynamic relocation code needs refactoring, but it is probably better
to do it with this test passing.

llvm-svn: 249340
2015-10-05 19:30:12 +00:00
Rafael Espindola d1cf421bd5 Don't copy STT_SECTION from the inputs.
This matches the behavior of gold and bfd ld.

llvm-svn: 249326
2015-10-05 16:25:43 +00:00
Igor Kudrin 024c84c77c Remove an extra blank line.
llvm-svn: 249324
2015-10-05 16:05:18 +00:00
Rafael Espindola 4f674ed138 Include hidden and internal symbols in the regular symbol table.
This matches the behavior of bfd ld and gold. It is also convenient for
testing other changes.

llvm-svn: 249323
2015-10-05 15:24:04 +00:00
Igor Kudrin b1f2b51a89 [ELF2] Add DT_INIT and DT_FINI dynamic table entries
The entries are added if there are "_init" or "_fini" entries in
the symbol table respectively. According to the behavior of ld,
entries are inserted even for undefined symbols.

Symbol names can be overridden by using -init and -fini command
line switches. If used, these switches neither add new symbol table
entries nor require those symbols to be resolved.

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

llvm-svn: 249297
2015-10-05 10:29:46 +00:00
Denis Protivensky 22220d5d5f [ELF2] Add --undefined option
Add symbol specified with -u as undefined which may cause additional
object files from archives to be linked into the resulting binary.

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

llvm-svn: 249295
2015-10-05 09:43:57 +00:00
Davide Italiano b00e523d00 [ELF2/AArch64] R_AARCH64_ABS{16,32} can fail.
Add tests to ensure we handle this case this case gracefully.

llvm-svn: 249255
2015-10-04 01:08:58 +00:00
Davide Italiano df88f968e3 [ELF2/AArch64] Add support for AARCH64_ABS{16,32,64} relocations.
I saw these in the wild while trying to link shared libraries.

llvm-svn: 249254
2015-10-04 00:59:16 +00:00
Davide Italiano 0b6974bfe0 [ELF/AArch64] Support R_AARCH64_ADR_PREL_PG_H121 relocation.
llvm-svn: 249246
2015-10-03 19:56:07 +00:00
Ed Maste 2c86fb4bde Accept --dynamic-linker in addition to -dynamic-linker.
This matches what bfd ld accepts.

llvm-svn: 249234
2015-10-03 09:32:48 +00:00
Ed Maste 21e4e148c6 Add -rpath= alias for -rpath
llvm-svn: 249230
2015-10-03 06:54:24 +00:00
Michael J. Spencer 7744d9a201 [elf2] Remove unused flag in test.
llvm-svn: 249204
2015-10-02 22:39:35 +00:00
Davide Italiano d9b5be4c83 [ELF/AArch64] Fix a couple of typos. My bad, sorry.
llvm-svn: 249201
2015-10-02 22:17:09 +00:00
Rui Ueyama 5713b8d0db ELF2: Use less templates so that we can use struct assignment. NFC.
llvm-svn: 249200
2015-10-02 22:17:07 +00:00
Davide Italiano 318ca22914 [ELF2/AArch64] Add comment and change name to match the one of the ABI.
Fix style while I'm here.

llvm-svn: 249198
2015-10-02 22:13:51 +00:00
Davide Italiano 1f31a2c11c [ELF2/AArch64] Add support for R_AARCH64_ADR_PREL_PG_H121
llvm-svn: 249195
2015-10-02 22:00:42 +00:00
Michael J. Spencer ed3476b79f [elf2] Add STB_GNU_UNIQUE support.
llvm-svn: 249193
2015-10-02 21:57:52 +00:00
Rui Ueyama 04dae558f4 ELF2: Make Writer::assignAddress() a bit shorter. NFC.
llvm-svn: 249190
2015-10-02 21:23:17 +00:00
Rui Ueyama 0fb1ee0c77 Fix variable names.
llvm-svn: 249188
2015-10-02 21:13:19 +00:00
Ed Maste 75c2feb753 Rename alias definitions by both aliased and alias name
Differential Revision: http://reviews.llvm.org/D13397

llvm-svn: 249186
2015-10-02 21:01:59 +00:00
Rafael Espindola 7757224466 Add static initialization/finalization array support.
This adds entries in the dynamic table for .init_array, .fini_array and
.preinit_array.

llvm-svn: 249175
2015-10-02 19:37:55 +00:00
Hal Finkel 58d7ee397d [ELF2] Simplify test from r249150
As Rafael pointed out, we don't need quite so many flags on the llvm-readobj
RUN line here.

llvm-svn: 249162
2015-10-02 17:57:29 +00:00
Rafael Espindola b2a5cafb37 Weak undefined symbols should not fetch archive members.
llvm-svn: 249160
2015-10-02 17:41:22 +00:00
Hal Finkel d26da9258f [ELF2] Fix mixed-Endian handling in DynamicSection<ELFT>::writeTo
Using the "raw" Elf64_Dyn or Elf32_Dyn structures in
DynamicSection<ELFT>::writeTo does not correctly handle mixed-Endian
situations. Instead, use the corresponding llvm::object::* structures which
have Endian-converting members (like the rest of the code).

This fixes all currently-failing elf2 tests when running on big-Endian
PPC64/Linux (I've added a big-Endian test case which should fail on
little-Endian machines in the same way that test/elf2/shared.s failed on
big-Endian machines prior to this change).

llvm-svn: 249150
2015-10-02 16:21:30 +00:00
Rafael Espindola 4876c886fc Ignore --version-script.
llvm-svn: 249149
2015-10-02 16:20:39 +00:00
Ed Maste 2dab6c9bcc Allow -soname arg in addition to -soname=arg
Differential Revision: http://reviews.llvm.org/D13387

llvm-svn: 249146
2015-10-02 15:45:26 +00:00
Ed Maste 9c95ac2946 Ignore --enable-new-dtags and --no-fatal-warnings
Found while testing a FreeBSD base system build with lld.  Ignored for
now while we continue to identify missing options and functionality.

llvm-svn: 249144
2015-10-02 15:29:31 +00:00
Rafael Espindola fc96a263a1 Ignore options used during a clang build.
llvm-svn: 249135
2015-10-02 14:25:26 +00:00
Rafael Espindola 327b178dd6 Accept some options with both -- and -.
This matches what both gold and bfd ld accept.

llvm-svn: 249134
2015-10-02 14:21:24 +00:00
Rafael Espindola 7d76847da3 Simplify. NFC.
llvm-svn: 249128
2015-10-02 13:23:29 +00:00
Rafael Espindola 98efd89e7e Use ld.lld2 as a argv[0] alias.
The reason for the name is so that we can run

./build/bin/clang -fuse-ld=lld2 test.o -o t

llvm-svn: 249122
2015-10-02 12:57:34 +00:00
Rui Ueyama 8c205d5394 ELF2: Merge duplicates using lambdas. NFC.
llvm-svn: 249118
2015-10-02 01:33:31 +00:00
Rui Ueyama 43155d0d48 [LLD] Fix Clang-tidy modernize-use-nullptr warnings; other minor cleanups.
Patch from Eugene Zelenko!

llvm-svn: 249111
2015-10-02 00:36:00 +00:00
Michael J. Spencer b660b61954 [elf2] Ignore --{start,end}-group.
llvm-svn: 249093
2015-10-01 22:54:37 +00:00
Rafael Espindola 8f13bef575 Ignore --no-add-needed.
llvm-svn: 249089
2015-10-01 22:31:38 +00:00
Rafael Espindola dc7f5f2b77 Remove dead file.
llvm-svn: 249080
2015-10-01 21:51:07 +00:00
Rafael Espindola 5d41326751 Still define __init_array_(start|end) if there is no .init_array.
This matches the behavior of other linkers and seems necessary to link
in some older systems.

llvm-svn: 249077
2015-10-01 21:22:26 +00:00
Rafael Espindola d31088b37a Simplify instantiation. NFC.
llvm-svn: 249074
2015-10-01 21:18:37 +00:00
Michael J. Spencer 52bf0ebfdf [lld][elf2] Sort output sections.
Sort by:
ALLOC
ALLOC && NOBITS
ALLOC & EXEC
ALLOC & EXEC && NOBITS
ALLOC & WRITE
ALLOC & WRITE && NOBITS
<nothing> (ignoring NOBITS)

The dynamic section is finalized early because it adds strings to the dynamic string table, which comes before the dynamic table.

llvm-svn: 249071
2015-10-01 21:15:02 +00:00
Rafael Espindola 3e60379fd9 Don't crash on files with no symbol table.
Thanks to Roman Divacky for the test.

llvm-svn: 249066
2015-10-01 20:26:37 +00:00
George Rimar 57e40deb8d [ELF2] Implement --no-undefined flag.
llvm-svn: 249064
2015-10-01 20:14:45 +00:00
Rafael Espindola ff1dcc59d9 Make the test a bit stronger.
This shows that it is really DT_SONAME that is used to detect dups.

llvm-svn: 249062
2015-10-01 20:04:31 +00:00
Rafael Espindola 6a3b5ded8a Don't include shared libraries multiple times.
llvm-svn: 249061
2015-10-01 19:52:48 +00:00
Rui Ueyama b9287b1fba ELF2: Use -soname to create a test .so file. Remove the .so binary from repository.
llvm-svn: 249059
2015-10-01 19:39:02 +00:00
Rui Ueyama 7de3f3719a ELF2: Add -soname option.
llvm-svn: 249058
2015-10-01 19:36:04 +00:00