Commit Graph

241 Commits

Author SHA1 Message Date
Simon Atanasyan 21b473d490 [ELF] Remove redundant empty line. NFC
llvm-svn: 259479
2016-02-02 09:08:04 +00:00
Rui Ueyama 74937fcd00 Update a comment.
llvm-svn: 259458
2016-02-02 02:53:58 +00:00
Rui Ueyama 5cbf5d207a Replace auto with the real type.
llvm-svn: 259455
2016-02-02 02:29:03 +00:00
Rui Ueyama b5a6970ace ELF: Teach SymbolBody about how to get its addresses.
Previously, the methods to get symbol addresses were somewhat scattered
in many places. You can use getEntryAddr returns the address of the symbol,
but if you want to get the GOT address for the symbol, you needed to call
Out<ELFT>::Got->getEntryAddr(Sym). This change adds new functions, getVA,
getGotVA, getGotPltVA, and getPltVA to SymbolBody, so that you can use
SymbolBody as the central place to ask about symbols.

http://reviews.llvm.org/D16710

llvm-svn: 259404
2016-02-01 21:00:35 +00:00
Rui Ueyama 5e378ddc1e Consistenly use sizeof(uintX_t) instead of ELFT::Is64Bits ? 8 : 4.
llvm-svn: 259250
2016-01-29 22:18:57 +00:00
Rui Ueyama ead75fc84f Add comments.
llvm-svn: 259249
2016-01-29 22:18:55 +00:00
Rui Ueyama 65d98ea473 Replace code duplications with function calls.
llvm-svn: 259238
2016-01-29 20:31:05 +00:00
Rui Ueyama 9398f86a2a Remove a parameter from Target::writePlt.
llvm-svn: 259158
2016-01-29 04:15:02 +00:00
Rui Ueyama 900e2d2578 ELF: Do not pass addresses that can be obtained using Out.
llvm-svn: 259154
2016-01-29 03:51:49 +00:00
Rui Ueyama 6251545683 Rename PltZeroEntrySize -> PltZeroSize.
This patch also fixes parameter name. They points to the beginning
of PLT or GOT tables, so GotAddr or PltAddr are better.)

llvm-svn: 259150
2016-01-29 03:00:32 +00:00
Rui Ueyama c516ae1719 ELF: Make Target's member function names shorter.
llvm-svn: 259147
2016-01-29 02:33:45 +00:00
Rui Ueyama c112c1be69 Rename includeInDynamicSymtab -> includeInDynsym.
llvm-svn: 259144
2016-01-29 02:17:01 +00:00
Rui Ueyama 572a6f74a7 Rename DynamicSymbolTableIndex -> DynsymIndex.
This is the index in .dynsym, so the new name should make sense.

llvm-svn: 259142
2016-01-29 01:49:33 +00:00
Rui Ueyama 724d625c7a ELF: Remove accessors from Target.
These accessors do not provide values. We can simply make the variables public.

llvm-svn: 259141
2016-01-29 01:49:32 +00:00
Rafael Espindola e2c2461a6b Merge identical strings.
This avoids the need to have reserve and addString in sync.

We avoid hashing the global symbols again. This means that we don't
merge a global symbol that has the same name as some other string, but
that doesn't seem very common. The string table size is the same in
clang an scylladb with or without hashing global symbols again.

llvm-svn: 259136
2016-01-29 01:24:25 +00:00
Rui Ueyama baf16512ea Rename isTlsOptimized -> canRelaxTls.
This function is a predicate that a given relocation can be relaxed.
The previous name implied that it returns true if a given relocation
has already been optimized away.

llvm-svn: 259128
2016-01-29 00:20:12 +00:00
Rui Ueyama 64cfffd333 ELF: Rename error -> fatal and redefine error as a non-noreturn function.
In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.

In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.

This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.

In this patch, I rename error to fatal, and introduce another version of
error which doesn't call exit. That function instead sets HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.

I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.

http://reviews.llvm.org/D16641

llvm-svn: 259069
2016-01-28 18:40:06 +00:00
Rui Ueyama 0de86c1659 Do not use return with a function whose return type is void.
Although it is syntactically correct, it is a bit confusing, and
not necessary here.

llvm-svn: 258996
2016-01-27 22:23:44 +00:00
Rafael Espindola 10d71ffc65 Remove another case of almost duplicated code.
Were had very similar code for deciding to keep a local symbol and for
actually writing it.

llvm-svn: 258958
2016-01-27 18:04:26 +00:00
Rafael Espindola 0e92f24880 Remove redundant variable.
llvm-svn: 258940
2016-01-27 16:41:24 +00:00
Rui Ueyama 3ae28a4758 Simplify. NFC.
llvm-svn: 258795
2016-01-26 07:17:27 +00:00
Rui Ueyama d6cea14cbb Simplify. NFC.
This new code should be logically equivalent to the previous code.

llvm-svn: 258792
2016-01-26 04:58:58 +00:00
Rui Ueyama 5ec41f3b74 Add missing template instantiations.
llvm-svn: 258767
2016-01-26 01:32:00 +00:00
Rafael Espindola cc3ae413ce Fix MSVC build.
llvm-svn: 258766
2016-01-26 01:30:07 +00:00
Rui Ueyama 1546fb2d65 Move code to create RELATIVE reloc for TLS_IE to one place.
llvm-svn: 258760
2016-01-26 01:03:21 +00:00
Rui Ueyama b0210e83b3 ELF: Move code for GNU_IFUNC to one place. NFC.
This does not solve the problem that we call isGnuIFunc function
both from RelocationSection and from the Writer::scanRelocs, but
this at least should improve readability. I'm taking an incremental
approach to reduce complexity.

llvm-svn: 258753
2016-01-26 00:24:57 +00:00
Rui Ueyama ac9fb458fb Define a helper function to make it visually shorter. NFC.
llvm-svn: 258748
2016-01-25 23:38:34 +00:00
Rui Ueyama 304d135f56 Use Symtab.find() instead of Symtab.getSymbols().lookup().
This was the only place we directly called lookup on the internal table
of the symbol table.

llvm-svn: 258724
2016-01-25 21:47:25 +00:00
Rafael Espindola de06936f28 Avoid almost duplication in .dynamic finalize and write.
There are a few cases where we have almost duplicated code.

This patches fixes the simplest: the finalize and write of dynamic
section. Right now they have to have exactly the same structure to
decide if a DT_* entry is needed and then to actually write it.

We cannot just write it to a std::vector in the first pass since
addresses have not been computed yet.

llvm-svn: 258723
2016-01-25 21:32:04 +00:00
George Rimar 45ca88dbdf Fix: added assert condition to EhFrameHeader<ELFT>::assignEhFrame().
Thanks to David Blaikie who found that issue.

llvm-svn: 258707
2016-01-25 19:27:50 +00:00
George Rimar 06415e97f2 Use of assert instead of llvm_unreachable in EhFrameHeader<ELFT>::assignEhFrame().
llvm-svn: 258670
2016-01-25 08:20:16 +00:00
Sean Silva f1c5a0f09c [ELF] Avoid unnecessary global variable.
Summary: It looks like this snuck through in r256143/D15383.

Reviewers: ruiu, grimar

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

llvm-svn: 258599
2016-01-23 01:49:37 +00:00
George Rimar d0cb85b62d Use of llvm_unreachable instead of warning in EhFrameHeader<ELFT>::assignEhFrame().
llvm-svn: 258499
2016-01-22 10:57:39 +00:00
Rui Ueyama bef81f3a70 ELF: Move code to emit copyrel to one place. NFC.
In this code, we avoid calling needsCopyRel in writeTo because
we called that function already in scanRelocs. Making the same
decision twice is a waste and has a risk of a bug that we get
inconsistent resuts.

llvm-svn: 258430
2016-01-21 20:59:22 +00:00
Simon Atanasyan 56ab5f0289 [ELF][MIPS] Initial support of MIPS local GOT entries
Some MIPS relocation (for now R_MIPS_GOT16) requires creation of GOT
entries for symbol not included in the dynamic symbol table. They are
local symbols and non-local symbols with 'local' visibility. Local GOT
entries occupy continuous block between GOT header and regular GOT
entries.

The patch adds initial support for handling local GOT entries. The main
problem is allocating local GOT entries for local symbols. Such entries
should be initialized by high 16-bit of the symbol value. In ideal world
there should be no duplicated entries with the same values. But at the
moment of the `Writer::scanRelocs` call we do not know a value of the
symbol. In this patch we create new local GOT entry for each relocation
against local symbol, though we can exhaust GOT quickly. That needs to
be optimized later. When we calculate relocation we know a final symbol
value and request local GOT entry index. To do that we maintain map
between addresses and local GOT entry indexes. If we start to calculate
relocations in parallel we will have to serialize access to this map.

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

llvm-svn: 258388
2016-01-21 05:33:23 +00:00
Simon Atanasyan 0d5e1b753e [ELF] Do not keep STT_FILE symbols in the symbol table
STT_FILE symbols usually contain source file names. It is redundant
to keep this information in the output file.

llvm-svn: 258331
2016-01-20 18:59:45 +00:00
George Rimar f6bc65a3b2 Reapply r257753 with fix:
Added check for terminator CIE/FDE which has zero data size.
void EHOutputSection<ELFT>::addSectionAux(
...
 // If CIE/FDE data length is zero then Length is 4, this
 // shall be considered a terminator and processing shall end.
    if (Length == 4)
      break;
...

After this "Bug 25923 - lld/ELF2 linked application crashes if exceptions were used." is fixed for me. Self link of clang also works.

Initial commit message:
[ELF] - implemented --eh-frame-hdr command line option.

--eh-frame-hdr
Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header.

Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr.
This section contains a lookup table for quick binary search of FDEs.
Detailed info can be found here:
http://www.airs.com/blog/archives/462

Differential revision: http://reviews.llvm.org/D15712

llvm-svn: 257889
2016-01-15 13:34:52 +00:00
Rui Ueyama 489a806965 Update for LLVM function name change.
llvm-svn: 257801
2016-01-14 20:53:50 +00:00
Rui Ueyama 5f91ace828 Revert r257753: "[ELF] - implemented --eh-frame-hdr command line option."
This reverts commit r257753 because we cannot link Clang with this patch.

llvm-svn: 257797
2016-01-14 20:32:19 +00:00
George Rimar 28f4fbe480 [ELF] - implemented --eh-frame-hdr command line option.
--eh-frame-hdr
Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header.

Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr.
This section contains a lookup table for quick binary search of FDEs.
Detailed info can be found here:
http://www.airs.com/blog/archives/462

Differential revision: http://reviews.llvm.org/D15712

llvm-svn: 257753
2016-01-14 10:30:32 +00:00
George Rimar 7af0562808 Fixed typo in comment. NFC.
llvm-svn: 257356
2016-01-11 17:19:40 +00:00
Rui Ueyama 6ffb42ad0f Revert "Remove unnecessary type casts."
This reverts commit r257080 because it caused GCC to emit "enumeral
and non-enumeral type in conditional expression" warning.

llvm-svn: 257096
2016-01-07 20:53:30 +00:00
Rui Ueyama d97e5c4db0 Fix local variable name.
sh_type and sh_flags are valid names as members of ELF structs,
but they are not as variables in LLVM.

llvm-svn: 257082
2016-01-07 18:33:11 +00:00
Rui Ueyama d1e92aafa0 Remove useless local variable.
llvm-svn: 257081
2016-01-07 18:20:02 +00:00
Rui Ueyama 07fc399654 Remove unnecessary type casts.
llvm-svn: 257080
2016-01-07 18:17:29 +00:00
Rui Ueyama 7562d0e490 Fix typo.
They happened to be anagrams.

llvm-svn: 257072
2016-01-07 16:41:06 +00:00
Tom Stellard 80efb16aad [ELF] Add AMDGPU support
Summary: This will allow us to remove the AMDGPU support from old ELF.

Reviewers: rafael, ruiu

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

llvm-svn: 257023
2016-01-07 03:59:08 +00:00
Rui Ueyama 76c0063eeb ELF: Improve performance of string table construction.
String tables in unstripped executable files are fairly large in size.
For example, lld's executable file is about 34.4 MB in my environment,
and of which 3.5 MB is the string table. Efficiency of string table
construction matters.

Previously, the string table was built in an inefficient way. We used
StringTableBuilder to build that and enabled string tail merging,
although tail merging is not effective for the symbol table (you can
only make the string table 0.3% smaller for lld.) Tail merging is
computation intensive task and slow.

This patch eliminates string tail merging.

I changed the way of adding strings to the string table in this patch
too. Previously, strings were added using add() and the same strings
were then passed to getOffset() to get their offsets in the string table.
In this way, getOffset() needs to look up a hash table to get offsets
for given strings. This is a violation of "we look up the symbol table
(or a hash table) only once for each symbol" dogma of the new LLD's
design. Hash table lookup for long C++ mangled names is slow.
I eliminated that lookup in this patch.

In total, this patch improves link time of lld itself about 12%
(3.50 seconds -> 3.08 seconds.)

llvm-svn: 257017
2016-01-07 02:35:32 +00:00
Rui Ueyama f71358dcc9 Define align() and use that instead of RoundUpToAlignment().
The name "RoundUpToAlignment" is too long compared to what it does.

llvm-svn: 256993
2016-01-06 23:25:42 +00:00
Rui Ueyama cf07a31107 Remove redundant `llvm::ELF::`.
llvm-svn: 256986
2016-01-06 22:53:58 +00:00