Commit Graph

1543 Commits

Author SHA1 Message Date
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 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
Michael J. Spencer 18255a333e [elf2] Tighten up test.
llvm-svn: 250126
2015-10-12 23:44:22 +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 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 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
Simon Atanasyan 3b732ac7ee [ELF2][mips] Support R_MIPS_32 relocation
llvm-svn: 250045
2015-10-12 15:10:02 +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
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 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 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 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
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
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
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 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
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
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
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
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
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
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
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
Rafael Espindola cea0b3b45d Don't create dynamic relocations for weak undefined symbols.
llvm-svn: 249520
2015-10-07 04:22:55 +00:00