Commit Graph

4302 Commits

Author SHA1 Message Date
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