[PECOFF] /safeseh:no on x64 is not an error

I made LLD to report an error if /safeseh:no option is given on x64,
but it turned out MSVC link.exe doesn't report error on it.
Removing the check.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218077 91177308-0d34-0410-b5e6-96231b3b80d8
Fix buggy Twine storage in ELFLinkingContext::searchLibrary()

This patch fixes a forbidden use of Twine. It should only be used
as an intermediary value, but never stored.

This caused a bug in lld when running on Linux and compiled with
optimizations - it couldn't properly search libs.

Patch from Rafael Auler!

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218083 91177308-0d34-0410-b5e6-96231b3b80d8
Fixes wrong Twine uses in FileNode::errStr() and in LayoutPass.cpp

Patch from Rafael Auler!

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218088 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] __tls_used is _tls_used on x64.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218090 91177308-0d34-0410-b5e6-96231b3b80d8
ReaderWriter: print magic in hex

When we encounter an unknown machine type, we print out the machine type magic.
However, we would print out the magic in decimal rather than hex.  Perform this
conversion to make it easier to identify what machine is unsupported.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218103 91177308-0d34-0410-b5e6-96231b3b80d8
PECOFF: loosen assumptions about x86-only targets

Rather than saving whether we are targeting 64-bit x86 (x86_64), simply convert
the single use of that information to the actual relocation type.  This will
permit the selection of non-x86 relocation types (e.g. for WoA support).

Inline the access of the machine type field as it is relatively cheap (a couple
of pointer dereferences) rather than storing the relocation type as a member
variable.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218104 91177308-0d34-0410-b5e6-96231b3b80d8
Driver: accept /machine:arm for Windows linker

Accept /machine:arm as an argument.  This is changed to support ARM NT.
Although there is no way to differentiate between ARM (Windows CE) and ARM NT
(Windows on ARM), since LLVM currently only supports Windows on ARM, simply take
/machine:arm to mean Windows on ARM.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218105 91177308-0d34-0410-b5e6-96231b3b80d8
PECOFF: loosen another assumption of x86 only

Cache the machine type value of the linking context.  We need this in order to
calculate the virtual address of the atom when resolving function symbols.
Windows on ARM must check if the atom is a function and if so, set the Thumb bit
for the returned virtual address.  Failure to do so will result in an abnormal
exit due to a trap caused by invalid instruction decoding.  The same information
can be used to determine the relocation type that was previously being done via
is64 to select between x86 and x86_64.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218106 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Set ordinal to alias atoms

Atoms are ordered in the output file by ordinal. File has file ordinal,
and atom has atom ordinal which is unique within the file.
No two atoms should have the same combination of ordinals.

However that contract was not satisifed for alias atoms. Alias atom
is defined by /alternatename:sym1=sym2. In this case sym1 is defined
as an alias for sym2. sym1 always got ordinal 0.

As a result LLD failed with an assertion failure.

This patch assigns ordinal to alias atoms.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218158 91177308-0d34-0410-b5e6-96231b3b80d8
Silence these C4715 warnings from Visual C++ (NFC)

llvm\tools\lld\lib\readerwriter\macho\macholinkingcontext.cpp(647):
warning C4715: 'lld::MachOLinkingContext::exportSymbolNamed' :
not all control paths return a value

llvm\tools\lld\lib\readerwriter\macho\machonormalizedfilefromatoms.cpp(723):
warning C4715: '`anonymous namespace'::Util::getSymbolTableRegion' :
not all control paths return a value

While all enum values do appear in the switch, an uninitialized or corrupted
enum variable would not be caught without the default: case in the switch.



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218197 91177308-0d34-0410-b5e6-96231b3b80d8
Modified per David Blakie suggestion.



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218198 91177308-0d34-0410-b5e6-96231b3b80d8
[ELF] Fix linking when a regular object defines a symbol that is used in a DSO

Patch from Rafael Auler!

When a shared lib has an undefined symbol that is defined in a regular object
(the program), the final executable must export this symbol in the dynamic
symbol table. However, in the current logic, lld only puts the symbol in the
dynamic symbol table if the symbol is weak. This patch fixes lld to put the
symbol in the dynamic symbol table regardless if it is weak or not.

This caused a problem in FreeBSD10, whose programs link against a crt1.o
that defines the symbol __progname, which is, in turn, undefined in libc.so.7
and will only be resolved in runtime.

http://reviews.llvm.org/D5424

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218259 91177308-0d34-0410-b5e6-96231b3b80d8
Revert "[ELF] Fix linking when a regular object defines a symbol that is used in a DSO"

This commit reverts r218259 because it needed to be checked in with
a few binary files for the test.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218272 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Handle PRIVATE keyword in the module definition file

A symbol in a module definition file may be annotated with the
PRIVATE keyword like this.

  EXPORTS
    func PRIVATE

The PRIVATE keyword does not affect the resulting .dll file.
But it prevents the symbol to be listed in the .lib (import
library) file.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218273 91177308-0d34-0410-b5e6-96231b3b80d8
Make -core/-flavor options have higher priority than linker name

Also allows -core/flavor to appear at any position in the command line.
Patch from Oleg Ranevskyy!

http://reviews.llvm.org/D5384

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218321 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Fix duplicate /export options

If two or more /export options are given for the same symbol, we should
always print a warning message and use the first one regardless of other
parameters.
Previously there was a case that the first parameter is not used.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218342 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Change export table type.

This patch changes the type of export table set from std::set to
std::vector. The new code is slightly inefficient, but because
export table elements are actually mutable, std::vector is better
here. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218343 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Simplify /machine option handling

/machine:ebc was previously recognized but rejected. Unknown architecture
names were handled differently but eventually rejected too. We don't need
to distinguish them.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@218344 91177308-0d34-0410-b5e6-96231b3b80d8
[PECOFF] Keep unmangled name in the export table descriptor

The export table descriptor is a data structure to keep information
about the export table. It contains a symbol name, and the name may
or may not be mangled.

We need unmangled names for the export table, so we demangle them
before writing them to the export table.

Obviously this is not a correct round-trip conversion. That could
drop a leading underscore from a symbol because that's
indistinguishable from a mangled name.

What we need to do is to keep unmangled names. This patch does that.

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