[ELF] Fix bug in ELFFile::createAtoms() that caused lld to mislink musl

When creating the graph edges of the atoms of an ELF file, special care must be
taken with atoms that represent weak symbols. They cannot be the target of any
Reference::kindLayoutAfter edge because they can be merged and point to other
code, screwing up the final layout of the atoms. ELFFile::createAtoms()
correctly handles this corner case. The problem is that createAtoms() assumed
that there can be no zero-sized weak symbols, which is not true. Consider:

my_weak_func1:
my_weak_func2:
my_weak_func3:
code

In this case, we have two zero-sized weak symbols, my_weak_func1 and
my_weak_func2, and one non-zero weak symbol my_weak_func3. createAtoms() would
correctly handle my_weak_func3, but not the first two symbols. This problem
happens in the musl C library when a zero-sized weak symbol is merged and
screws up the file layout. Since this musl code lives at the finalization hooks,
any C program linked with LLD and musl was correctly executing, but segfaulting
at the end.

Reviewers: shankarke

http://reviews.llvm.org/D5606



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219034 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Add support for -dependency_info command line option

This option is added by Xcode when it runs the linker.  It produces a binary
file which contains the file the linker used.  Xcode uses the info to
dynamically update it dependency tracking.

To check the content of the binary file, the test case uses a python script
to dump the binary file as text which FileCheck can check.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219039 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] add -iphoneos_version_min as alias for -ios_version_min

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219041 91177308-0d34-0410-b5e6-96231b3b80d8
PE/COFF: remove another use of PECOFFLinkingContext::is64bit

In order to support more than x86/x86_64, we need to change the behaviour to use
the actual machine type rather than checking the bitness and assuming that we
are on X86.  This replaces the use of is64bit in applyAllRelocations with a
check on the machine type.  This will enable adding support for handling ARM
relocations.

Rename the existing applyRelocation methods to be similarly named and to make it
clear the types of relocations they will process.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219088 91177308-0d34-0410-b5e6-96231b3b80d8
Core: switch error mapping to switches

Rather than a series of cascading ifs, use a switch statement to convert the
error code to a string.  This has the benefit of allowing the compiler to inform
us if we ever add a new error code but fail to update the string representation.

Add in stringified versions for a couple of missing InputGraphErrors.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219089 91177308-0d34-0410-b5e6-96231b3b80d8
PE/COFF: add a check to ensure that we dont mix up architectures

Previously, we would not check the target machine type and the module (object)
machine type.  Add a check to ensure that we do not attempt to use an object
file with a different target architecture.

This change identified a couple of tests which were incorrectly mixing up
architecture types, using x86 input for a x64 target.  Adjust the tests
appropriately.  The renaming of the input and the architectures covers the
changes to the existing tests.

One significant change to the existing tests is that the newly added test input
for x64 uses the correct user label prefix for X64.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219093 91177308-0d34-0410-b5e6-96231b3b80d8
Do not use llvm_unreachable at reachable code.

These lines can be reachable if we give a broken or unsupported
input object file.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219176 91177308-0d34-0410-b5e6-96231b3b80d8
PE/COFF: add ARM NT reference kinds

Teach the reader about ARM NT relocation types.  Although the writer cannot yet
perform the actual application of these relocations, the reader can at least now
identify the relocation types.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219178 91177308-0d34-0410-b5e6-96231b3b80d8
PE/COFF: rename applyRelocations* family

Use x86 and x64 which is the canonical Microsoft vernacular for the targets.
Addresses post-commit review comments from Rui.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219179 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Infer machine type from input object file

If /machine option is omitted, the linker needs to infer that from
input object files. This patch implements that.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219180 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Remove yet another use of _is64

No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219246 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Move a function out of a class

I'm going to use this function both for the import table and the
delay-import table.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219267 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Support fat archives

mach-o supports "fat" files which are a header/table-of-contents followed by a
concatenation of mach-o files (or archives of mach-o files) built for
different architectures.  Previously, the support for fat files was in the
MachOReader, but that only supported fat .o files and dylibs (not archives).

The fix is to put the fat handing into MachOFileNode.  That way any input file
kind (including archives) can be fat.  MachOFileNode selects the sub-range
of the fat file that matches the arch being linked and creates a MemoryBuffer
for just that subrange.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219268 91177308-0d34-0410-b5e6-96231b3b80d8
Add support to print version.

Summary: Add support in the universal driver to print the lld version and the
repository version.

Test Plan: A driver test is added

Reviewers: kledzik, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

Projects: #lld

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219277 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF][AllArchs] Fix includes

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219278 91177308-0d34-0410-b5e6-96231b3b80d8
Revert "[ELF][AllArchs] Fix includes"

This reverts commit e137dd93e1291a2d2fa7f41c8f8bcdb59c8b3225.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219313 91177308-0d34-0410-b5e6-96231b3b80d8
Fix typo in comment

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219326 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF] Implement --export-dynamic/-E

When creating a dynamic executable and receiving the -E flag, the linker should
export all globally visible symbols in its dynamic symbol table.

This commit also moves the logic that exports symbols in the dynamic symbol
table from OutputELFWriter to the ExecutableWriter class. It is not correct to
leave this at OutputELFWriter because DynamicLibraryWriter, another subclass of
OutputELFWriter, already exports all symbols, meaning we can potentially end up
with duplicated symbols in the dynamic symbol table when creating shared libs.

Reviewers: shankarke

http://reviews.llvm.org/D5585



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219334 91177308-0d34-0410-b5e6-96231b3b80d8
Use llvm::StringSwitch.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219341 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Remember DLL names given with /delayload option.

This is a step toward full support of /delayload.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@219344 91177308-0d34-0410-b5e6-96231b3b80d8