Commit Graph

5003 Commits

Author SHA1 Message Date
Pete Cooper 4a92469260 Atomize the ObjC category list section.
__DATA, __objc_catlist contains a list of pointers to categories.

We want to atomize it so that the ObjC pass can later optimize and remove
categories.  That will be a later patch.

llvm-svn: 259386
2016-02-01 19:10:10 +00:00
Rui Ueyama 3c8d049d88 Move template instantiations to end of the file.
llvm-svn: 259276
2016-01-29 23:59:15 +00:00
Rui Ueyama cf375935a9 Update comments about the entries in .got.plt.
The original comments were a bit inaccurate because there was no 4 addends.

llvm-svn: 259274
2016-01-29 23:58:03 +00:00
Rui Ueyama 8364c6269a Add comments on a mysterious value in MIPS GOT[1].
Thanks to Simon Atanasyan and Igor Kudrin for describing the code!

llvm-svn: 259259
2016-01-29 22:55:38 +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 16ba669c87 ELF: Report duplicate symbols as many as possible instead of the first one.
http://reviews.llvm.org/D16647

llvm-svn: 259233
2016-01-29 19:41:13 +00:00
George Rimar 2c9b7bd326 Replace StringRef with std::string in LinkerDriver::addLibrary(StringRef Name) because std::string is destroyed after assigning what fills the buffer with garbage and StringRef is no more valid.
That fixes few failing tests under windows+msvs2015(debug).

llvm-svn: 259186
2016-01-29 10:52:52 +00:00
Rui Ueyama 9398f86a2a Remove a parameter from Target::writePlt.
llvm-svn: 259158
2016-01-29 04:15:02 +00:00
Rui Ueyama 012eb783b3 ELF: Provide default implemenatations for simple functions.
llvm-svn: 259157
2016-01-29 04:05:09 +00:00
Rui Ueyama 57b676c546 Define stub functions instead of pure virtual functions.
To remove empty functions.

llvm-svn: 259155
2016-01-29 03:51:51 +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 69c30edb5e Add a comment.
llvm-svn: 259149
2016-01-29 03:00:30 +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 1940424632 ELF: Report multiple errors from the driver.
This patch let the driver keep going until it parses all
command line options.

http://reviews.llvm.org/D16645

llvm-svn: 259143
2016-01-29 01:54:52 +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
Rui Ueyama 74b7df016f Remove unused variable.
llvm-svn: 259140
2016-01-29 01:49:29 +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 0e36e09b9c Update comments.
llvm-svn: 259127
2016-01-29 00:20:09 +00:00
Rui Ueyama c2a0d7e351 ELF: Report more than one undefined symbols if exist.
http://reviews.llvm.org/D16643

llvm-svn: 259107
2016-01-28 22:56:29 +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
Hans Wennborg c89f805ca6 getting_started.rst: fix 'unknown target name' error
llvm-svn: 258953
2016-01-27 17:54:35 +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
Eugene Zelenko 3f81a9c654 Fix Clang-tidy modernize-use-nullptr warnings in include/lld/Core/range.h; other minor fixes.
Differential revision: http://reviews.llvm.org/D16565

llvm-svn: 258829
2016-01-26 18:27:37 +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
Pete Cooper e420dd4d84 Use an ilist instead of std::list. NFC.
The TrieNode/TrieEdge data structures here are allocated in a bumpptrallocator.

Unfortunately, TrieNode contained a std::list<TrieEdge> and as the allocator doesn't
call the TrieNode destructor, we ended up leaking the memory allocated by the std::list
itself.

Instead we can use an intrusive list as then we save the extra allocations anyway.

llvm-svn: 258725
2016-01-25 21:50:54 +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
Pete Cooper 580ccca192 Initialize member variable.
Found by Rafael using valgrind in https://llvm.org/bugs/show_bug.cgi?id=21466.

llvm-svn: 258718
2016-01-25 20:41:48 +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
Pete Cooper 351164504a Add support for export_dynamic cmdline option and behaviour.
This option matches the behaviour of ld64, that is it prevents globals
from being dead stripped in executables and dylibs.

Reviewed by Lang Hames

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

llvm-svn: 258554
2016-01-22 21:13:24 +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 c3e54cf17b [ELF][MIPS] Update test case to reflect recent changes in llvm-readobj
llvm-svn: 258340
2016-01-20 20:01:28 +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
Pete Cooper 90dbab0b0d Add an ObjCPass to the MachO linker.
This pass currently emits an objc image info section if one is required.

This section contains the aggregated version and flags for all of the input
files.

llvm-svn: 258197
2016-01-19 21:54:21 +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
Pete Cooper 0872e46c9d Set the objc constraint on the context based on the parsed files.
Like arch, os, etc, when we know we are going to use a file, we check
that the file has compatible objc constraints to the context, throw
appropriate errors where that is not the case, and hopefully set the
objc constraints on the context for use later.

Added 2 tests to ensure that we don't have incompatibilities between
host and simulator code as both will get x86 based architectures.

llvm-svn: 258173
2016-01-19 19:46:41 +00:00
Pete Cooper feaa967ee8 Cache the objc image info constraints in file.
Image info flags describe the objc constraint which is GC/retain/release/etc.

These need to be parsed and stored in the file so that we can do error checking.

That will come in a later commit.

llvm-svn: 258160
2016-01-19 18:46:40 +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
Pete Cooper 12b094d5f4 Only emit files with subsections_via_symbols if all inputs had that set.
When generating a relocatable file, its only valid to set this flag if
all of the inputs also had the flag.  Otherwise we may atomize incorrectly
when we link the relocatable file again.

Reviewed by Lang Hames.

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

llvm-svn: 257976
2016-01-16 01:09:23 +00:00
Pete Cooper 4b6bed98e2 Give error on binaries containing GC objc image infos.
The image info struct contains flags for what kind of GC/retain/release is required.

Give an error if we parse GC flags as these are unsupported.

llvm-svn: 257974
2016-01-16 00:57:07 +00:00
Pete Cooper a014ffef87 Add checking of differing swift versions in input files.
Swift versions are part of the objc image info section, and must match
for all files linked which actually have an image info section

llvm-svn: 257964
2016-01-16 00:07:22 +00:00
Pete Cooper 78f7907953 Remove unnecessary extra linked file in RUN line. NFC.
This test case was already suitably self-contained that linking against the
helloworld file added no value.

llvm-svn: 257954
2016-01-15 23:25:40 +00:00
Pete Cooper 20de822232 Check that the objc image info version is exactly 0
llvm-svn: 257953
2016-01-15 23:25:37 +00:00
Pete Cooper 2735783090 Add the GC commandline options and throw errors if they are used
llvm-svn: 257907
2016-01-15 17:39:02 +00:00
Pete Cooper 7162e8c597 Remove out of bounds reloc from reduced file.
This file was failing to build with asan enabled.  The reason being that
applyFixupFinal was writing 4-bytes worth of fixup in to an atom only
a single byte in length.

The test case didn't actually need this particular reloc so i've removed
it, although i'll follow up with future commits to actually verify that
relocs are to an address with enough space for the fixup to be applied.

llvm-svn: 257906
2016-01-15 17:25:12 +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
Pete Cooper 00de8b5a1a Don't use explicit paths in my own test check lines
llvm-svn: 257842
2016-01-14 23:44:00 +00:00
Pete Cooper d7b5c5bcef Error check the size of the __objc_imageinfo section
llvm-svn: 257841
2016-01-14 23:35:05 +00:00
Pete Cooper 99f3b9494b Check for mismatched arch and OS when linking MachO files.
This patch makes use of the handleLoadedFile hook added in r257814.

That method is used to check the arch and the OS of the files we are linking
against the arch and OS on the context.

The first test to use this ensures that we do not try to combine i386 Mac OS code
with i386 simulator code.

llvm-svn: 257837
2016-01-14 23:25:06 +00:00
Pete Cooper f0c0f3c477 Add File::kind's for all subclasses of File.
This is to enable isa<> support for any files which need it.

It will be used in an upcoming patch to differentiate MachOFile from other implicitly generated files.

Reviewed by Lang Hames.

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

llvm-svn: 257830
2016-01-14 22:55:38 +00:00
Rui Ueyama 528a56eb0d Remove XFAIL:win32 from a test which does not fail on win32.
This test uses a regexp so that it matches both Unix output and
Windows output.

llvm-svn: 257817
2016-01-14 22:04:35 +00:00
Pete Cooper 80c0974c6b Add handleLoadedFile hook to the context.
This is called from the resolver on each file we decide we actually want to use.

Future commits will make use of this to extract useful information from the files and do
error checking against the context.  For example, ensure that files are the same arch as
each other.

Reviewed by Lang Hames.

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

llvm-svn: 257814
2016-01-14 21:53:13 +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
George Rimar 3d737e45c0 Reapply r257588
Fix: Added missed input file.

Initial commit message:
[ELF/AArch64] - Implemented R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 and R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC relocations

* R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 is calculated as Page(G(GTPREL(S+A))) – Page(P), set an ADRP immediate field to bits [32:12] of X; check –2^32 ≤ X < 2^32;
* R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC is calculated as G(GTPREL(S+A)), set an LD offset field to bits [11:3] of X. No overflow check; check that X&7 = 0.

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

llvm-svn: 257596
2016-01-13 13:04:46 +00:00
George Rimar cc6c093f6f Revert r257588 as it broke buildbot
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/18715/steps/test_lld/logs/stdio

llvm-svn: 257595
2016-01-13 12:58:51 +00:00
George Rimar 253dbf5405 [ELF/AArch64] - Implemented R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 and R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC relocations
* R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 is calculated as Page(G(GTPREL(S+A))) – Page(P), set an ADRP immediate field to bits [32:12] of X; check –2^32 ≤ X < 2^32;
* R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC is calculated as G(GTPREL(S+A)), set an LD offset field to bits [11:3] of X. No overflow check; check that X&7 = 0.

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

llvm-svn: 257588
2016-01-13 11:29:45 +00:00
Rui Ueyama 4b00e7310f COFF: Update test for recent llvm-objdump change (r257539).
This test now correctly checks if the specified forwarding-to
symbol exists in the export table.

llvm-svn: 257540
2016-01-12 23:29:42 +00:00
Rui Ueyama ab12361c4e Merge two consecutive if's. NFC.
llvm-svn: 257527
2016-01-12 21:57:44 +00:00
Rui Ueyama 09eb0b3b3f Rename IgnoredUndef -> Ignored since it is not an undefined symbol.
Also rename Ignored -> IgnoredWeak and IgnoredStrong -> Ignored,
since strong symbol is a norm.

llvm-svn: 257507
2016-01-12 19:24:55 +00:00
Simon Atanasyan 3a5b6e2750 [ELF][MIPS] Do not create dynamic relocations against _gp_disp symbol
MIPS _gp_disp designates offset between start of function and gp pointer
into GOT therefore any relocations against it do not require dynamic
relocation.

llvm-svn: 257492
2016-01-12 17:31:45 +00:00
Simon Atanasyan 49f98c742c [ELF][MIPS] Do not use 'sed' to modify binary files
On Windows different versions of 'sed' work in different text/binary
mode by default. If default mode is text, sed produces corrupted binary
files. Unfortunately there is no standard command line option to select
the mode. Some 'sed' support '-b' to switch to binary mode, while other
ones support '--text' option and does not have '-b' option at all.

llvm-svn: 257471
2016-01-12 12:38:43 +00:00
Simon Atanasyan db147eb5ac [ELF][MIPS] Fix a typo in the comment
llvm-svn: 257450
2016-01-12 06:24:02 +00:00
Simon Atanasyan 188558e5eb [ELF][MIPS] Prevent substitution of _gp_disp symbol
On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
start of function and gp pointer into GOT. To make seal with such symbol
we add new method addIgnoredStrong(). It adds ignored symbol with global
binding to prevent the symbol substitution. The addIgnored call is not
enough here because this call adds a weak symbol which might be
substituted by symbol from shared library.

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

llvm-svn: 257449
2016-01-12 06:23:57 +00:00
Davide Italiano 15414cd0a7 [ELF] FreeBSD has slightly different emulation strings for PPC.
Teach lld about them.

llvm-svn: 257437
2016-01-12 02:58:59 +00:00
Rui Ueyama 94b08e3bf0 Simplify. NFC.
llvm-svn: 257432
2016-01-12 01:33:23 +00:00
Rui Ueyama 902c75cd7b Remove dead code.
llvm-svn: 257421
2016-01-12 00:32:49 +00:00
Rui Ueyama f949f7f15e Merge two small functions. NFC.
llvm-svn: 257418
2016-01-11 23:50:55 +00:00
Tom Stellard 3b8cde69aa [old ELF] Remove AMDGPU target
Summary: This is no longer needed now that the new ELF implementation supports AMDGPU.

Reviewers: ruiu, rafael

Subscribers: llvm-commits

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

llvm-svn: 257390
2016-01-11 21:40:40 +00:00
Davide Italiano 8c344436c4 Initial support for PPC target in the new ELF linker.
Differential Revision:	http://reviews.llvm.org/D15968

llvm-svn: 257374
2016-01-11 19:45:33 +00:00
George Rimar 7af0562808 Fixed typo in comment. NFC.
llvm-svn: 257356
2016-01-11 17:19:40 +00:00
George Rimar 1395dbdbc6 [ELF/AARCH64] - Implemented R_AARCH64_TSTBR14 relocation.
R_AARCH64_TSTBR14 is calculated as S+A-P,
Set the immediate field of a TBZ/TBNZ instruction to bits [15:2] of X; check -2^15 ≤ X < 2^15

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

llvm-svn: 257334
2016-01-11 14:27:05 +00:00
George Rimar 4102bfbe71 [ELF/AARCH64] - Implemented R_AARCH64_CONDBR19 relocation.
R_AARCH64_CONDBR19 is calculated as S+A-P,
Set the immediate field of a conditional branch instruction to bits [20:2] of X; check -2^20 ≤ X< 2^20.

Afaik there is no document for AARCH64 instruction encoding from official for unknown reason, so 
I used gold source code and next link as a reference for implementation: http://kitoslab-eng.blogspot.ru/2012/10/armv8-aarch64-instruction-encoding.html. From which is clear that immediate field of a conditional branch instruction is 5 bits off. That is proved by output which is is equal to gold/bfd now.

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

llvm-svn: 257333
2016-01-11 14:22:00 +00:00
George Rimar a48043521f [ELF/AARCH64] - Implemented R_AARCH64_IRELATIVE relocation.
Implemented in the same way as was already done for x86/x64 targets (http://reviews.llvm.org/D15235).

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

llvm-svn: 257332
2016-01-11 14:15:17 +00:00
George Rimar 5644d39165 [ELF] - improved relocation-copy.s test (added R_X86_64_32 relocations)
* Added instructions to generate R_X86_64_32 relocations. Without that next part of code was uncovered by test, code worked without it:
bool X86_64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
  if (needsCopyRel(Type, S))
    return false;
* Removed -e main, added _start

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

llvm-svn: 257331
2016-01-11 13:25:21 +00:00
Rui Ueyama 84425d7289 COFF: Implement DLL symbol forwarding.
DLL export tables usually contain dllexport'ed symbol RVAs so that
applications which use the DLLs can find symbols from the DLLs.
However, there's a minor feature to "forward" DLL symbols to other
DLLs.

If you set an RVA to a string whose form is "<dllname>.<symbolname>"
(e.g. "KERNEL32.ExitProcess") instead of symbol RVA to the export
table, the loader interprets that as a forwarder symbol, and resolve
that symbol from the specified DLL.

This patch implements that feature.

llvm-svn: 257243
2016-01-09 01:22:00 +00:00
Rui Ueyama dba6b576cf COFF: Rename RoundUpToAlignment -> align.
llvm-svn: 257220
2016-01-08 22:24:26 +00:00
Rui Ueyama 52c7c5fa3e Group members to match a comment. NFC.
llvm-svn: 257218
2016-01-08 22:20:00 +00:00
Rui Ueyama 131e0ffa10 Use shorter name. NFC.
llvm-svn: 257217
2016-01-08 22:17:42 +00:00
Rui Ueyama 683564ea63 Update comments.
llvm-svn: 257216
2016-01-08 22:14:15 +00:00
Rui Ueyama 8b4879aec0 Remove an empty constructor.
We used to have code in SymbolTable constructor to add entry symbols, etc.
That code has been moved to Driver. We can remove the constructor.

llvm-svn: 257214
2016-01-08 22:06:25 +00:00
Rui Ueyama b4de595c46 Add comments.
llvm-svn: 257212
2016-01-08 22:01:33 +00:00
Rui Ueyama 79c7373232 ELF: Consistently return SymbolBody * from SymbolTable::add functions.
For historical reasons, some add* functions for SymbolTable returns a
pointer to a SymbolBody, while some are not. This patch is to make them
consistently return a pointer to a newly added symbol.

llvm-svn: 257211
2016-01-08 21:53:28 +00:00
Rui Ueyama b705b10012 ELF: Remove dead code.
R_X86_64_PLT32 is handled in the same way as R_X86_64_PC32 by
relocateOne(), so this function does not seems to be needed.
Without this code, all tests still pass.

http://reviews.llvm.org/D15971

llvm-svn: 257203
2016-01-08 20:11:47 +00:00
Rui Ueyama 885260e480 ELF: Remove SIZE relocs from isRelRelative.
SIZE relocations are not PC-relative, so isRelRelative should return false.

llvm-svn: 257141
2016-01-08 03:25:26 +00:00
Rui Ueyama 2b0edc2fdc Add a comment.
llvm-svn: 257140
2016-01-08 02:41:35 +00:00
Rui Ueyama 3a7c2f6f44 ELF: Simplify Target::isSizeReloc and add comments.
All non-trivial relocation decisions need explanations like this
to help readers understand not only how relocations are handled but
why they are handled these ways. This is a start.

llvm-svn: 257119
2016-01-08 00:13:23 +00:00
Pete Cooper 4ec88b420b Fix offset in test case. NFC
It wasn't actually pointing to the function at the start of the text section, and so the offset in the binary differed when we passed the file through a second time.

The __eh_frame section uses implicit relocations and when reducing this test case from explicit to implicit, I got
the offset wrong.  This makes sure it is correct.

llvm-svn: 257101
2016-01-07 21:12:30 +00:00
Pete Cooper 03bb2e5931 Always generate the fixup content for unwindFDEToFunction as we no
longer emit it.

llvm-svn: 257100
2016-01-07 21:10:06 +00:00
Pete Cooper ac03979000 Don't emit relocs for the __eh_frame section as they can be implicit.
The __eh_frame section contains relocations which can always be implicitly generated.

This patch tracks whether sections have only implicitly relocations and skips emitting them to the object file if that is the case.

The test case here ensures that this is the case for __eh_frame sections.

Reviewed by Lang Hames.

http://reviews.llvm.org/D15594

llvm-svn: 257099
2016-01-07 21:07:26 +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 1300e6b15a Add a comment for AMDGPU relocateOne().
llvm-svn: 257095
2016-01-07 20:34:16 +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 d441d75dad ELF: Make private functions private.
llvm-svn: 257078
2016-01-07 17:54:21 +00:00
Rui Ueyama 0dd684ce88 ELF: Split LinkerDriver::createFiles. NFC.
createFiles was doing more than creating files despite its name.
Now these things are moved to a new function.

llvm-svn: 257077
2016-01-07 17:54:19 +00:00
Rui Ueyama d32c63defa ELF: Move error checking code of the driver into one place. NFC.
llvm-svn: 257076
2016-01-07 17:33:25 +00:00
Rui Ueyama deb154001d ELF: Implement --wrap.
In this patch, all symbols are resolved normally and then wrap options
are applied. Renaming is implemented by mutating `Body` pointers of
Symbols. (As a result, Symtab.find(SymbolName)->getName() may return
a string that's different from SymbolName, but that is by design.
I designed the symbol and the symbol table to allow this kind of
operations.)

http://reviews.llvm.org/D15896

llvm-svn: 257075
2016-01-07 17:20:07 +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 68a55e6c34 [ELF] Fix REQUIRES line in amdgpu tests
'REQUIRES' needs to be in all caps.

Also update lit.cfg so these tests get run when the AMDGPU target is
enabled.

llvm-svn: 257029
2016-01-07 05:02:38 +00:00
Tom Stellard a09245cddb [ELF] Fix amdgpu tests
The triples in these tests were completely wrong, but the tests were
still passing for me locally.

llvm-svn: 257027
2016-01-07 04:22:24 +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
Pete Cooper 69b18f4703 Set CMake ADDITIONAL_HEADER_DIRS on libraries with headers in /include. NFC.
In a UI such as XCode, it can group the headers for a library with that library.
This is done in the CMakeLists.txt for the library itself by setting the path(s)
as ADDITIONAL_HEADER_DIRS.

LLVM already does this for all of its libraries, so just adding this to lld to
make things easier.  Should be NFC.

llvm-svn: 257002
2016-01-07 00:14:09 +00:00
Pete Cooper f154b678c6 Set the folder for libraries to 'lld libraries'. NFC.
In a UI such as XCode, LLVM source files are in 'libraries' while clang
files are in 'clang libraries'.

This change moves the lld source to 'lld libraries' to make code browsing easier.

It should be NFC as the build itself is still the same, just the structure in a
UI differs.

llvm-svn: 257001
2016-01-07 00:14:04 +00:00
Rui Ueyama f1cbb93050 Use RoundUpToAlignment instead of writing the expression to round up.
The original code might be more readable than the new one if you
remember the expression. Otherwise the new one is probably better.

llvm-svn: 256995
2016-01-06 23:34:12 +00:00