Commit Graph

247 Commits

Author SHA1 Message Date
Rui Ueyama 0e53c7dd2c ELF: Make names for TLS module indices shorter.
The previous names contained "Local" and "Current", but what we
are handling is always local and current, so they were redundant.

TlsIndex comes from "tls_index" struct that Ulrich Drepper is using
in this document to describe this data structure in GOT.

llvm-svn: 259852
2016-02-05 00:10:02 +00:00
Rui Ueyama 812293ae1d Simplify. NFC.
llvm-svn: 259848
2016-02-04 23:39:35 +00:00
Rafael Espindola de9857e3c1 Avoid code duplication when creating dynamic relocations.
Another case where we currently have almost duplicated code is the
creation of dynamic relocations. First to decide if we need one, then to
decide what to write.

This patch fixes it by passing more information from the relocation scan
to the section writing code. This is the same idea used for r258723.

I actually think it should be possible to simplify this further by
reordering things a bit in the writer. For example, we should be able to
represent almost every position in the file with an OutputSeciton and
offset. When writing it out we then just need to add the offset to the
OutputSection VA.

llvm-svn: 259829
2016-02-04 21:33:05 +00:00
Rafael Espindola 9e3f84bf95 Fix addend computation for IRELATIVE relocations.
llvm-svn: 259692
2016-02-03 21:02:48 +00:00
Rafael Espindola 38a36c4f1c Simplify. NFC.
llvm-svn: 259660
2016-02-03 16:53:39 +00:00
George Rimar 5c36e5938d [ELF] Implemented -Bsymbolic-functions command line option
-Bsymbolic-functions: 
When creating a shared library, bind references to global 
function symbols to the definition within the shared library, if any.

This patch also fixed behavior of already existent -Bsymbolic:
previously PLT entries were created even if -Bsymbolic was specified.

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

llvm-svn: 259481
2016-02-02 09:28:53 +00:00
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