Commit Graph

946 Commits

Author SHA1 Message Date
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 81e05525e3 Handle local symbols in discarded sections.
We were reserving space for them but never writing them out.

llvm-svn: 258948
2016-01-27 17:09:37 +00:00
Rafael Espindola 0e92f24880 Remove redundant variable.
llvm-svn: 258940
2016-01-27 16:41:24 +00:00
Rui Ueyama 231b5e23c5 Simplify. NFC.
llvm-svn: 258796
2016-01-26 07:17:29 +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 02ca17906d [ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.
Main executable did not export symbols that exist both in the main executable and in DSOs before this patch.
Symbols from object files that override symbols in DSO should be added to .dynsym table.

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

llvm-svn: 258672
2016-01-25 08:44:38 +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
Pete Cooper 6025933789 Fix bug in handling of quoted linker script tokens and update tests to use it.
There was an off by one error because the StringRef.substr functions
second argument is a length, not the end index.

Also updated a few ELF files which failed when run on Jenkins with paths
including the @ character.  This is often used in Jenkins for shared
workspace plugin.

Reviewed by Rui Ueyama

llvm-svn: 258583
2016-01-22 23:46:37 +00:00
Rafael Espindola 25472ee9c2 Remove unnecessary object:: prefix.
llvm-svn: 258563
2016-01-22 21:49:07 +00:00
Rui Ueyama ac2b0a168d Remove dead code.
llvm-svn: 258539
2016-01-22 19:55:01 +00:00
George Rimar 237b218770 [ELF] - fix possible UB when dereferencing null
In InputSection.cpp it was possible to dereference null.
Had to change signature of relocateTlsOptimize to accept pointer instead of reference.

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

llvm-svn: 258508
2016-01-22 18:02:28 +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
Rui Ueyama 88d79a06b7 Style change. NFC.
llvm-svn: 258427
2016-01-21 20:18:36 +00:00
George Rimar bfd29a1567 [ELF] - Refactoring of Writer<ELFT>::scanRelocs()
Code for handling TLS relocations was moved out scanRelocs() to new function handleTlsRelocations().
That is because scanRelocs already too large to put more TLS code into it.

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

llvm-svn: 258392
2016-01-21 09:14: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
Rui Ueyama 90f76fbb54 Return early before iterating over local symbols. NFC.
llvm-svn: 258385
2016-01-21 03:07:38 +00:00
Rui Ueyama c5e372db40 Simplify function signature. NFC.
StringTable is a member variable, so we don't need to pass it around.

llvm-svn: 258382
2016-01-21 02:10:12 +00:00
Rui Ueyama 1e056ebe3c Fix indentation.
llvm-svn: 258374
2016-01-21 00:45:39 +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
Rafael Espindola 65e80b963a Rename IgnoredWeak to Ignored.
Thanks to Rui for the suggestion.

llvm-svn: 258189
2016-01-19 21:19:52 +00:00
George Rimar ffb673515e [ELF] - R_386_GOT32 relocation calculation fix.
R_386_GOT32 has multiple descriptions:

"System V Application Binary Interface Intel386 Architecture Processor Supplement Version 1.1" (https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-1.1.pdf), p36 contains next calculation for R_386_GOT32: G + A - GOT.
SYSTEM V APPLICATION BINARY INTERFACE 4 (https://refspecs.linuxfoundation.org/elf/abi386-4.pdf, p78) tolds us its G + A - P.
Oracle docs (https://docs.oracle.com/cd/E19455-01/816-0559/chapter6-26/index.html) says its should be G + A.

gold/bfd calculates it as "G + A - GOT", but GOT means the end of the GOT section.
Patch fixes current calculation to gold/ld behavior.

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

llvm-svn: 258115
2016-01-19 11:00:48 +00:00
Rafael Espindola 3a6a0a0109 Delete addIgnoredStrong.
It is not needed now that we resolve symbols is shared libraries
correctly.

llvm-svn: 258104
2016-01-19 00:05:54 +00:00
Rafael Espindola 0bc0c02387 Prefer symbols from .o over .so.
This matches the behavior of gold and bfd ld.

llvm-svn: 258102
2016-01-18 23:54:05 +00:00
Rafael Espindola 591c6cefae Delete dead code.
llvm-svn: 258078
2016-01-18 20:50:28 +00:00
Rafael Espindola f312d89f50 Clarify the comment and code a bit. NFC.
llvm-svn: 258069
2016-01-18 20:06:59 +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
Davide Italiano 2dfc5fd1ea [ELF/AArch64] Add support for R_AARCH64_LDST16_ABS_LO12_NC relocation.
Found while trying to self-host the toolchain that libLTO needs it.

llvm-svn: 257854
2016-01-15 01:49:51 +00:00
Simon Atanasyan ca558ea627 [ELF][MIPS] Create dynamic relocations for R_MIPS_32/64 relocations
llvm-svn: 257806
2016-01-14 21:34:50 +00:00
Rui Ueyama 489a806965 Update for LLVM function name change.
llvm-svn: 257801
2016-01-14 20:53:50 +00:00
Simon Atanasyan 682aeea9de [ELF][MIPS] Ignore 'hint' relocations like R_MIPS_JALR in the `scanRelocs` method
MIPS ABI has relocations like R_MIPS_JALR which is just a hint for
linker to make some code optimization. Such relocations should not be
handled as a regular ones and lead to say dynamic relocation creation.

The patch introduces new virtual `Target::isHintReloc` method, overrides
it in the `MipsTargetInfo` class and calls it in the `Writer<ELFT>::scanRelocs`
method.

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

llvm-svn: 257798
2016-01-14 20:42:09 +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
Davide Italiano 0d4fbae0e7 [ELF/AArch64] Support R_AARCH64_LDST128_ABS_LO12_NC relocation.
llvm-svn: 257731
2016-01-14 01:30:21 +00:00
Rui Ueyama df1545163f Update comment for __cxa_demangle again to make it precise.
Thanks for Ed Maste for the suggestion.

llvm-svn: 257685
2016-01-13 22:09:09 +00:00
Rui Ueyama e16d1b0a9c Update comment for __cxa_demangle.
llvm-svn: 257678
2016-01-13 21:39:40 +00:00
Rui Ueyama 5fa978b4c0 Attempt to make FreeBSD buildbot green.
It seems that __cxa_demangle function on the buildbot tried to demangle
a variable "tlsvar" as a C++ symbol. Do not call that function unless
it does not start with "_Z" which is the prefix of mangled names.

llvm-svn: 257661
2016-01-13 19:40:13 +00:00
Rui Ueyama a4a628fb51 Demangle symbols when including them in error messages.
llvm-svn: 257647
2016-01-13 18:55:39 +00:00