[mach-o] Add support for using export tries

On Darwin at runtime, dyld will prefer to use the export trie of a dylib instead
of the traditional symbol table (which is large and requires a binary search).

This change enables the linker to generate an export trie and to prefer it if
found in a dylib being linked against.  This also simples the yaml for dylibs
because the yaml form of the trie can be reduced to just a sequence of names.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217066 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Improve x86_64 reference kind switch statements.

The use of default: was disabling the warning about unused enumerators. Fix
that, then fix the one enumerator that was not handled. Add coverage for
it in test suite.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217078 91177308-0d34-0410-b5e6-96231b3b80d8
If lld binary is named 'ld' on darwin, use darwin driver mode

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217112 91177308-0d34-0410-b5e6-96231b3b80d8
Fix unit test now that 'ld' is host specific

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217114 91177308-0d34-0410-b5e6-96231b3b80d8
Move function. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217121 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Let darwin driver infer arch from .o files if -arch not used.

Mach-O has a "fat" (or "universal") variant where the same contents built for
different architectures are concatenated into one file with a table-of-contents
header at the start.  But this leaves a dilemma for the linker - which
architecture to use.

Normally, the linker command line -arch is used to force which slice of any fat
files are used.  The clang compiler always passes -arch to the linker when
invoking it.  But some Makefiles invoke the linker directly and don’t specify
the -arch option.  For those cases, the linker scans all input files in command
line order and finds the first non-fat object file.  Whatever architecture it
is becomes the architecture for the link.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217189 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Run cvtres.exe with /machine:x64.

If we are creating a PE+ executable, we need to run cvtres with
/machine:x64 instead of /machine:x86. Otherwise the resulting executable
would be invalid.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217214 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Run lib.exe with /machine:x64.

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

Moved code used only by isDataSymbol from find to isDataSymbol member
function. Also changed the return type of isDataSymbol because
previously "if (isDataSymbol(...))" meant "if it is *not* a data symbol"
which is opposite from what you'd expect.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217324 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF][Cleanup] Remove unused functions

Remove unused functions in the Target relocation handler.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217354 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF] Undefined symbols should be allowed when building dynamic libraries

When dynamic libraries are built, undefined symbols should always be allowed and
the linker should not exit with an error.

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

By default linker would not create a separate segment to hold read only data.

This option overrides that behavior by creating the a separate read only segment
for read only data.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217358 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF][Driver] Produce a proper error when file is not found

When a file is not found, produce a proper error message. The previous error
message produced a file format error, which made me wonder for a while why
there is a file format error, but essentially the file was not found.

This fixes the problem by producing a proper error message.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217359 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF] Export strong defined symbol if it coalesces away a weak symbol
defined in a shared library.

Now LLD does not export a strong defined symbol if it coalesces away a
weak symbol defined in a shared library. This bug affects all ELF
architectures and leads to segfault:

  % cat foo.c
  extern int __attribute__((weak)) flag;
  int foo() { return flag; }

  % cat main.c
  int flag = 1;
  int foo();
  int main() { return foo() == 1 ? 0 : -1; }

  % clang -c -fPIC foo.c main.c
  % lld -flavor gnu -target x86_64 -shared -o libfoo.so ... foo.o
  % lld -flavor gnu -target x86_64 -o a.out ... main.o libfoo.so
  % ./a.out
  Segmentation fault

The problem is caused by the fact that we lose all information about
coalesced symbols after the `Resolver::resolve()` method is finished.

The patch solves the problem by overriding the
`LinkingContext::notifySymbolTableCoalesce()` method and saving names
of coalesced symbols. Later in the `buildDynamicSymbolTable()` routine
we use this information to export these symbols.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217363 91177308-0d34-0410-b5e6-96231b3b80d8
Update current LLD status for MIPS target.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217372 91177308-0d34-0410-b5e6-96231b3b80d8
Partially roll back r217324.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217392 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Add support for -pie and -no_pie

There is a bit (MH_PIE) in the flags field of the mach_header which tells
the kernel is a program was built position independent (for ASLR).  The linker
automatically attempts to build programs PIE if they are built for a recent
OS version.  But the -pie and -no_pie options override that default behavior.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217408 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Fix so no options causes usage message to be printed

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@217409 91177308-0d34-0410-b5e6-96231b3b80d8
[mach-o] Fix missing { }

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