[Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
definition below all of the header #include lines, LLD edition.

IF you want to know more details about this, you can see the recent
commits to Debug.h in LLVM. This is just the LLD segment of a cleanup
I'm doing globally for this macro.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@206851 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Better handling of /OPT option.

Previously LLD would fail if /OPT:icf, /OPT:lbr or such are specified,
because these command line flags would be handled as unknown ones. We
rather want LLD to ignore these known but yet-to-be-implemented options
for now.

Added tests for the driver as well.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@206863 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Skip IMAGE_SYM_DEBUG sections correctly.

We don't use sections with IMAGE_SYM_DEBUG attribute so we basically
want to the symbols for them when reading symbol table. When we skip
them, we need to skip auxiliary symbols too. Otherwise weird error
would happen because aux symbols would be interpreted as regular ones.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@206931 91177308-0d34-0410-b5e6-96231b3b80d8
winlib should be lib.exe, not just lib.

This avoids setting the winlib feature on machines with a lib dir in a
$PATH dir.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@206940 91177308-0d34-0410-b5e6-96231b3b80d8
XFAIL the Mips tests when we don't have the target.

These tests shouldn't even try to use the Mips target, but let's make
them not fail when we don't have it while they don't get fixed.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@206947 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Allow symbols not starting with '_' in x86

Not all symbols are decorated with an underscore in x86. You can
write undecorated symbols in assembly, for example. Thus this
assertion is too strong.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207125 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Define implicit symbols for exported ones.

This patch is to fix a compatibility issue with MSVC link.exe as to
use of dllexported symbols inside DLL.

A DLL exports two symbols for a function. One is non-decorated one,
and the other is with __imp_ prefix. The former is a function that
you can directly call, and the latter is a pointer to the function.
These dllexported symbols are created by linker for programs that
link against the DLL. So, I naturally believed that __imp_ symbols
become available when you once create a DLL and link against it, but
they don't exist until then. And that's not true.

MSVC link.exe is smart enough to allow users to use __imp_ symbols
locally. That is, if a symbol is specified with /export option, it
implicitly creates a new symbol with __imp_ prefix as a pointer to
the exported symbol. This feature allows the following program to
be linked and run, although _imp__hello is not defined in this code.

  #include <stdio.h>

  __declspec(dllexport)
  void hello(void) { printf("Hello\n"); }

  extern void (*_imp__hello)(void);

  int main() {
    _imp__hello();
    return 0;
  }

MSVC link.exe prints out the following warning when linking it.

  LNK4217: locally defined symbol _hello imported in function _main

Using __imp_ symbols locally is I think not a good coding style. One
should just take an address using "&" operator rather than appending
__imp_ prefix. However, there are programs in the wild that depends
on this link.exe's behavior, so we need this feature.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207141 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Do not copy-construct ExportDesc.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207154 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Assign unique ordinals to __imp_ symbols.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207168 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Add /IMPLIB command line option.

This option is to override the default import file path.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207175 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Fix off-by-one error in .def file parser.

I'm fixing another bug in the parser, and I wanted to submit this
fix as a separate change as it's logically independent from the other.
I'll add a test for this shortly.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207294 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Allow multiple directives in one module-definition file.

I'm a bit surprised that I have not implemented this yet. This is
definitely needed to handle real-world module definition files.
This patch contains a unit test for r207294.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207297 91177308-0d34-0410-b5e6-96231b3b80d8
lld: Silence CMake warning about a target that doesn't exist

lld-test.deps doesn't exist in a non-standalone build.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207431 91177308-0d34-0410-b5e6-96231b3b80d8
[Mips] Add the 'const' qualifier to the couple RelocationPass class
member functions.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207434 91177308-0d34-0410-b5e6-96231b3b80d8
[Mips] Convert MipsDynamicSymbolTable to the class template.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207435 91177308-0d34-0410-b5e6-96231b3b80d8
[Mips] Rewrite the R_MIPS_COPY relocation test using yaml2obj tool.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207436 91177308-0d34-0410-b5e6-96231b3b80d8
[Mips] Rename the test case.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207437 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Fix _imp_ implicit symbols.

Implicit symbol for local use implemented in r207141 was not fully
compatible with MSVC link.exe. In r207141, I implemented the feature
in such way that implicit symbols are defined only when they are
exported with /EXPORT option.

After that I found that implicit symbols are defined not only for
dllexported symbols but for all defined symbols. Actually _imp_
implicit symbols have no relationship with the dllexport feature. You
could add _imp_ to any symbol to get a pointer to the symbol, whether
the symbol is dllexported or not.  It looks pretty weird to me but
that's what we want if link.exe behaves that way.

Here is a bit about the implementation: Creating all implicit symbols
beforehand is going to be a huge waste of resource. This feature is
rarely used, and MSVC link.exe even prints out a warning message when
it finds this feature is being used. So we create implicit symbols
on demand. There is an archive file that creates implicit symbols when
they are needed.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207476 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] /export accepts non-decorated symbols.

You usually have to specify the exact name of a symbol to export it,
but for stdcall functions you can omit the @numbers suffix.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@207491 91177308-0d34-0410-b5e6-96231b3b80d8
[Mips] 80 column.

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