Commit Graph

2789 Commits

Author SHA1 Message Date
Simon Atanasyan d13587f671 [Mips] Suppress "right shift by too large amount" warning
Visual C++ shows the "right shift by too large amount" warning if
`MipsELFReference` is instantiated for 32-bit target and `Elf_Rel_Impl::getType`
method has `unsigned char` return type. We can freely suppress the warning in
that case because MIPS 32-bit ABI does not pack multiple relocation types into
the single field `r_type` and the `MipsELFReference::_tag` should be always
zero in that case.

No functional changes.

llvm-svn: 233088
2015-03-24 15:49:59 +00:00
Simon Atanasyan 396ce8fbe0 [Mips] Do not use inheriting constructor due build problem on Windows
No functional changes.

llvm-svn: 233058
2015-03-24 10:25:21 +00:00
Simon Atanasyan 623d3b0043 [Mips] Support MIPS N64 relocation record format
N64 ABI relocation record r_info field in fact consists of five subfields:
* r_sym   - symbol index
* r_ssym  - special symbol
* r_type3 - third relocation type
* r_type2 - second relocation type
* r_type  - first relocation type

Up to three these relocations applied one by one. The first relocation
uses an addendum from the relocation record. Each subsequent relocation
takes as its addend the result of the previous operation. Only the final
operation actually modifies the location relocated. The first relocation
uses as a reference symbol specified by the `r_sym` field. The third
relocation assumes NULL symbol.

The patch represents these data using LLD model and takes in account
additional relocation types during a relocation calculation.

Additional relocations do not introduce any new relations between two
atoms and just specify operations need to be done during a relocation
calculation. The first relocation type (`r_type`) stored in the
`Reference::_kindValue`. The rest of relocations and `r_ssym` value are
stored in the new `Reference::_tag` field "as-is". I decided to do not
"decode" these data on the core LLD level to prevent pollution of the
core LLD model by very target specific data.

Also I have to override writing of relocation records in the `RelocationTable`
class to convert MIPS N64 ABI relocation information from the `Reference`
class back to the ELF relocation record.

http://reviews.llvm.org/D8533

llvm-svn: 233057
2015-03-24 09:57:05 +00:00
Simon Atanasyan 25122a3c57 [Mips] Fix typo in the error message
llvm-svn: 233054
2015-03-24 09:05:35 +00:00
Davide Italiano 20f3da11e8 [ELF/X86_64] Fix handling of R_X86_64_GOTTPOFF relocation.
The aforementioned relocation generate a GOT entry with a
R_X86_64_TPOFF64. The new relocation is processed at startup
time by the loader. lld didn't generate the outstanding relocation,
now it does. This bug was found while trying to link ls(1) on FreeBSD.

Simplified repro:
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>

int
main(void)
{
    wchar_t wc = 98;
    if (!iswprint(wc))
        printf("blah\n");
    else
        printf("foo\n");
    return (0);
}

which incorrectly outputs "blah" when linked with lld before this patch.

llvm-svn: 233051
2015-03-24 06:22:45 +00:00
Rafael Auler 515fd61692 [ELF] Remove extraneous semicolon in DefaultLayout
llvm-svn: 232985
2015-03-23 18:39:37 +00:00
Benjamin Kramer e13f47e8aa Fix the CMake shared build.
The ELF backends now depend on lld::script::Sema, which is in libReaderWriter.
Link it explicitly.

llvm-svn: 232953
2015-03-23 15:55:00 +00:00
Denis Protivensky a2e5b2cea7 [ARM] Fix entry point for Thumb code
Test cases for both entry functions in ARM and Thumb
code are added.

llvm-svn: 232942
2015-03-23 11:38:24 +00:00
Simon Atanasyan 5d82380e82 [ELF] Add missing override keyword
No functional changes.

llvm-svn: 232938
2015-03-23 10:33:46 +00:00
Simon Atanasyan 283629a0f7 [Mips] Pass type of relocation and addendum to the `calculateRelocation`
separately

This change reduce difference between the trunk and upcoming patch and
simplify the future code review.

No functional changes.

llvm-svn: 232919
2015-03-22 16:35:08 +00:00
Simon Atanasyan 73fef59b20 [Mips] Rename template argument ELFType => ELFT
No functional changes.

llvm-svn: 232915
2015-03-22 15:41:16 +00:00
Simon Atanasyan 579fde1d83 [Mips] Use allocator from the base class
No functional changes.

llvm-svn: 232914
2015-03-22 15:41:10 +00:00
Shankar Easwaran 37d5add8a3 [ELF] GLOBAL_OFFSET_TABLE is a hidden symbol
llvm-svn: 232868
2015-03-20 23:47:08 +00:00
Shankar Easwaran 14726cd11b [ELF] Dont add local symbols for dynamic lookup.
Unable to add a unit test for this, as there is only one local undefined
symbol in regular shared libraries without a name.

llvm-svn: 232867
2015-03-20 23:47:05 +00:00
Shankar Easwaran 07f6ce0b83 [ELF] OrderPass : Order atoms only by ordinals.
Move the init array/fini array sorting to the Output ELF writer.

AFAIK, this is only needed by the X86_64/ARM ABI.

This shaves time taken to self host lld by 0.2 seconds.

Before patch
----------------
4791.062059 task-clock                #    1.634 CPUs utilized            ( +-  0.28% )
     61,107 context-switches          #    0.013 M/sec                    ( +-  0.56% )
2.932902671 seconds time elapsed                                          ( +-  0.84% )

After patch
-------------
4608.417248 task-clock                #    1.669 CPUs utilized            ( +-  0.30% )
     61,616 context-switches          #    0.013 M/sec                    ( +-  0.63% )
2.761012703 seconds time elapsed                                          ( +-  0.63% )

llvm-svn: 232866
2015-03-20 23:47:03 +00:00
Shankar Easwaran 33c979d685 [ELF][X86_64] Use anonymous namespace only for class declarations
llvm-svn: 232865
2015-03-20 23:47:01 +00:00
Shankar Easwaran b9c3bacb3b [ELF] Use unordered_map for AdditionalSegments
Fix a leftover class during implementation.

llvm-svn: 232864
2015-03-20 23:47:00 +00:00
Shankar Easwaran 1f869d0e1a [ELF] Use MapVector.
Order is still deterministic and we dont need a sorted order.

llvm-svn: 232863
2015-03-20 23:46:58 +00:00
Shankar Easwaran 208ac3d6e5 [ELF][X86_64] Remove relative references to include files
llvm-svn: 232862
2015-03-20 23:46:56 +00:00
Shankar Easwaran f65b60e806 [ELF][X86_64] Sort includes
llvm-svn: 232861
2015-03-20 23:46:54 +00:00
Simon Atanasyan 12e9f8cd11 [Mips] Create special PLT entry in case of MIPS R6 ABI
llvm-svn: 232806
2015-03-20 11:28:22 +00:00
Simon Atanasyan c823c9523c [Mips] Add comments to the relocation calculation functions
No functional changes.

llvm-svn: 232761
2015-03-19 20:56:34 +00:00
Simon Atanasyan caadcc3f27 [Mips] Implement R_MIPS_PCHI16 / R_MIPS_PCLO16 relocations handling
llvm-svn: 232757
2015-03-19 19:59:17 +00:00
Simon Atanasyan 48e088f354 [Mips] Implement R_MIPS_PC18_S3 relocation handling
llvm-svn: 232756
2015-03-19 19:59:06 +00:00
Simon Atanasyan 5472ea1270 [Mips] Implement R_MIPS_PC19_S2 / R_MIPS_PC26_S2 relocations handling
llvm-svn: 232755
2015-03-19 19:58:58 +00:00
Denis Protivensky 91141e87b1 [ARM] Implement static (initial exec) TLS model
This includes handling of R_ARM_TLS_IE32 and R_ARM_TLS_LE32 relocs.

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

llvm-svn: 232708
2015-03-19 06:47:44 +00:00
Simon Atanasyan 14afb83952 [Mips] Implement R_MIPS_PC21_S2 relocation handling
llvm-svn: 232707
2015-03-19 05:44:22 +00:00
Simon Atanasyan 14b5217cc6 [Mips] Recognize and check compatibility MIPS32R6 / MIPS64R6 ISA's
llvm-svn: 232706
2015-03-19 05:44:13 +00:00
Simon Atanasyan 8343c2c9ec [Mips] Replace "hand-made" function by the `llvm::SignExtend32()` routine
No functional changes.

llvm-svn: 232705
2015-03-19 05:44:04 +00:00
Rui Ueyama ddf77ce2bf PECOFF: Do not copy all undefined symbols to a set. NFC.
llvm-svn: 232646
2015-03-18 16:28:33 +00:00
Rui Ueyama 8cc20307e1 Remove unused parameter.
llvm-svn: 232639
2015-03-18 15:12:55 +00:00
Shankar Easwaran f06086a912 [ELF][ARM] Place gotSymbol in an anonymous namespace
Address comments from Espindola.

llvm-svn: 232497
2015-03-17 16:40:14 +00:00
Denis Protivensky 5a106191fa [ARM] Read initial addend for REL32 and PREL31 relocs
llvm-svn: 232474
2015-03-17 13:51:32 +00:00
Denis Protivensky e458ab4577 [ARM] Implement relocations: R_ARM_REL32, R_ARM_THM_JUMP11, R_ARM_PREL31
Test case for every relocation is added.

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

llvm-svn: 232464
2015-03-17 09:18:24 +00:00
Shankar Easwaran baf1aaaf1f [ELF] Use parallel_for_each for writing.
This changes improves performance of lld, when self-hosting lld, when compared
with the bfd linker. BFD linker on average takes 8 seconds in elapsed time.
lld takes 3 seconds elapased time average. Without this change, lld takes ~5
seconds average. The runtime comparisons were done on a release build and
measured by running linking thrice.

lld self-host without the change
----------------------------------
real    0m3.196s
user    0m4.580s
sys     0m0.832s

lld self-host with lld
-----------------------
user    0m3.024s
user    0m3.252s
sys     0m0.796s

time taken to build lld with bfd
--------------------------------
real    0m8.419s
user    0m7.748s
sys     0m0.632s

llvm-svn: 232460
2015-03-17 03:29:32 +00:00
Rui Ueyama cc6b381651 Make it compile with MSVC 2013.
MSVC 2013 cannot compile this code because of C1001 "internal error".
Stop using initializer list without type name.

llvm-svn: 232448
2015-03-17 01:10:12 +00:00
Rui Ueyama 3c2e306a5c PECOFF: Make FileCOFF:findAtomAt from O(n) to O(1).
I knew I cut corners when I wrote this. Turned out that it is
actually slow when a file being read has many symbols. This patch
is to stop doing linear search and instead do map lookup.

llvm-svn: 232436
2015-03-16 23:43:11 +00:00
Shankar Easwaran 9b7374b821 [Core] Add parallel_for_each
This adds a parallel_for_each similar to functionality in MSVC concurrency
library.

This was very patiently reviewed by Rui and credits go to him for this patch.

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

llvm-svn: 232419
2015-03-16 21:27:32 +00:00
Simon Atanasyan 4b4706b601 [ELF] Use pcrel format for eh_frame_ptr field encoding
The `eh_frame_ptr` field in the `.eh_frame_hdr` section contains an address
of the `.eh_frame` section. Using an absolute 32-bit format for encoding
of this field does not work for 64-bit targets. It is better to use a
relative format because it covers both 32-bit and 64-bit cases. Sure
this work if a distance between `.eh_frame_hdr` and `.eh_frame` sections
is less than 4 Gb but it is a rather correct assumption.

http://reviews.llvm.org/D8352

llvm-svn: 232414
2015-03-16 21:07:46 +00:00
Rafael Auler 01d73c9678 [LinkerScript] Handle symbols defined in linker scripts
Puts symbols defined in linker script expressions in a runtime file that is
added as input to the resolver, making the input object files see symbols
defined in linker scripts.

http://reviews.llvm.org/D8263

llvm-svn: 232409
2015-03-16 20:39:07 +00:00
Rafael Auler 8dd680dcb1 [LinkerScript] Adding test cases for SECTIONS semantics
llvm-svn: 232404
2015-03-16 19:56:42 +00:00
Rafael Auler 9a7e211e8f [LinkerScript] Implement semantics for simple sections mappings
This commit implements the behaviour of the SECTIONS linker script directive,
used to not only define a custom mapping between input and output sections, but
also order input sections in the output file. To do this, we modify
DefaultLayout with hooks at important places that allow us to re-order input
sections according to a custom order. We also add a hook in SegmentChunk to
allow us to calculate linker script expressions while assigning virtual
addresses to the input sections that live in a segment.

Not all SECTIONS constructs are currently supported, but only the ones that do
not use special sort orders. It adds two LIT test as practical examples of
which sections directives are currently supported.

In terms of high-level changes, it creates a new class "script::Sema" that owns
all linker script ASTs and the logic for linker script semantics as well.
ELFLinkingContext owns a single copy of Sema, which will be used throughout
the object file writing process (to layout sections as proposed by the linker
script).

Other high-level change is that the writer no longer uses a "const" copy of
the linking context. This happens because linker script expressions must be
calculated *while* calculating final virtual addresses, which is a very late
step in object file writing. While calculating these expressions, we need to
update the linker script symbol table (inside the semantics object), and, thus,
we are "modifying our context" as we prepare to write the file.

http://reviews.llvm.org/D8157

llvm-svn: 232402
2015-03-16 19:55:15 +00:00
Simon Atanasyan 3c1818c8c0 [Mips] clang-format the code
No functional changes.

llvm-svn: 232364
2015-03-16 09:14:47 +00:00
Simon Atanasyan a1abb2e2c7 [Mips] Do not check the relocation type twice
No functional changes.

llvm-svn: 232363
2015-03-16 09:14:40 +00:00
Simon Atanasyan 622a4bc83b [Mips] Add `const` qualifier to some member functions
No functional changes.

llvm-svn: 232362
2015-03-16 09:14:34 +00:00
Simon Atanasyan 44e9b094e0 [Mips] Implement R_MIPS_TLS_xxx relocation handling in case of N64 ABI
llvm-svn: 232361
2015-03-16 09:14:28 +00:00
Simon Atanasyan 256407d9e2 [Mips] Implement R_MIPS_GOT_DISP/PAGE/OFST relocations handling
llvm-svn: 232360
2015-03-16 09:14:17 +00:00
Simon Atanasyan 08b19d67fa [Mips] Group some cases in the switch statement
No functional changes.

llvm-svn: 232359
2015-03-16 09:14:06 +00:00
Shankar Easwaran 9fdb81d09b [ELF][ARM] Make gotSymbol a member.
The gotSymbol need not be a global static variable. Apart from this reason, This
variable was creating an issue with self hosting lld, as there seems to be an
issue running global initializers, when initializing the guard for this static
variable.

Program received signal SIGTRAP, Trace/breakpoint trap.

llvm-svn: 232341
2015-03-16 00:54:03 +00:00
Davide Italiano de42c18889 Use setVisibility() rather than assigning the value directly.
We don't want to risk to override wrong st_other bits, and when
we need to zero, we can do that explictly.

llvm-svn: 232282
2015-03-14 21:57:15 +00:00