Commit Graph

446 Commits

Author SHA1 Message Date
Benjamin Kramer bd521201b7 Apply clang-tidy's misc-move-constructor-init to lld.
No functionality change intended.

llvm-svn: 271686
2016-06-03 16:57:13 +00:00
Rafael Espindola a5cefffc33 Update for llvm change.
llvm-svn: 270907
2016-05-26 20:31:06 +00:00
Eugene Zelenko 1a299eab32 Fix Clang-tidy misc-unused-using-decls and Include What You Use warnings.
Differential revision: http://reviews.llvm.org/D19348

llvm-svn: 267008
2016-04-21 17:14:10 +00:00
Nico Weber a7a848f10d Revert unintentionally commited bits in r266935.
llvm-svn: 266942
2016-04-21 01:31:37 +00:00
Nico Weber 848334704d unbreak COFF/out.test after r266929
llvm-svn: 266935
2016-04-20 23:30:14 +00:00
Nico Weber 5660de7877 lld-link: Fix default output name with /dll flag.
If /dll is passed, the default output filename should be foo.dll,
not foo.exe.
http://reviews.llvm.org/D19321

llvm-svn: 266929
2016-04-20 22:34:15 +00:00
Duncan P. N. Exon Smith 28d8d04657 LTO: Adapt to LLVM API changes in r266713
llvm-svn: 266714
2016-04-19 04:57:40 +00:00
Rui Ueyama afb1901e42 COFF: Support /manifestinput command line option.
Manifest file is a separate or embedded XML file having metadata
of an executable. As it is XML, it can contain various types of
information. Probably the most popular one is to request escalated
priviledges.

Usually the linker creates an XML file and embed that file into
an executable. However, there's a way to supply an XML file from
command line. /manifestniput is it.

Apparently it is over-designed here, but if you supply two or more
manifest files, then the linker needs to merge the files into a
single XML file. A good news is that we don't need to do that ourselves.
MT.exe command can do that, so we call the command from the linker
in this patch.

llvm-svn: 266704
2016-04-19 01:21:58 +00:00
Duncan P. N. Exon Smith 2c66b23d79 LTO: Merge debug info types when linking bitcode
Make sure lld enables ODR type uniquing for debug info when invoking
LTO, as a follow-up to LLVM r266549.

llvm-svn: 266555
2016-04-17 07:35:38 +00:00
Rui Ueyama 34b60f1c40 Do not use llvm::getGlobalContext().
llvm-svn: 266375
2016-04-14 21:41:44 +00:00
Mehdi Amini 03a5042e4c Revert "Do not use llvm::getGlobalContext(), trying to nuke it from LLVM"
This reverts commit r266365 and r266367, the contexts in the two
places have to match.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266373
2016-04-14 21:31:46 +00:00
Mehdi Amini 9a15293ec1 Use fully qualified name to refer to LLVMContext
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266367
2016-04-14 21:09:10 +00:00
Mehdi Amini f1e7ff9d0e Do not use llvm::getGlobalContext(), trying to nuke it from LLVM
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266365
2016-04-14 20:53:39 +00:00
Davide Italiano 3774afba07 [COFF] Simplify the code leveraging implicit conversion.
Suggested by: David Blaikie!

llvm-svn: 266140
2016-04-12 22:05:38 +00:00
Davide Italiano eeae124faf [COFF] SmallVector<char, 0> -> SmallString<0>.
This way we're consistent between ELF and COFF.

llvm-svn: 265885
2016-04-09 23:00:31 +00:00
Kevin Enderby 439453679c Needed change to lld for the change to createBinary() now returning Expected<...>
With the llvm change in r265606 this is the matching needed change to the lld
code now that createBinary() is returning Expected<...> .

llvm-svn: 265607
2016-04-06 22:15:23 +00:00
Reid Kleckner 9cd77ce169 [coff] Accept and ignore another link.exe flag for compatibility
This flag disables link.exe's crash handler so that normal windows error
reporting and crash dumping occurs. For now it is reasonable for LLD to
ignore the flag.

Chromium is currently using this flag to collect minidumps of link.exe
crashing, and it breaks the LLD build.

llvm-svn: 264439
2016-03-25 18:09:29 +00:00
David Majnemer 08af4e56e1 [COFF] Don't call memcpy with a NULL argument
Some declarations of memcpy (like glibc's for example) are attributed
with notnull which makes it UB for NULL to get passed in, even if the
memcpy count is zero.

To account for this, guard the memcpy with an appropriate precondition.

This should fix the last UBSan bug, exposed by the test suite, in the
COFF linker.

llvm-svn: 263919
2016-03-20 23:10:12 +00:00
David Majnemer 2aa29ee7c1 [COFF] Remove undefined behavior from ObjectFile::createWeakExternal
LLD type-punned an integral type and a pointer type using a pointer
field.  This is problematic because the pointer type has alignment
greater than some of the integral values.

This would be less problematic if a union was used but it turns out the
integral values are only present for a short, transient, amount of time.

Let's remove this undefined behavior by skipping the punning altogether
by storing the state in a separate memory location: a vector which
informs us which symbols to process for weak externs.

llvm-svn: 263918
2016-03-20 22:56:31 +00:00
David Majnemer 93bbc7cd66 [COFF] Use coff_section::getAlignment
Use LLVM's section alignment calculation instead of having LLD calculate
it.

llvm-svn: 263724
2016-03-17 16:58:08 +00:00
David Majnemer 272de1e4d1 [COFF] Don't trust a symbol's section number
This fixes a test which exposed an ASan issue.

We assumed that a symbol's section number had a corresponding section
without performing validation.

llvm-svn: 263558
2016-03-15 16:47:28 +00:00
David Majnemer 22dff0aafc [COFF] Don't hard-code the load configuration size
The load configuration directory is a structure whose size varies as the
OS gains additional functionality.  To account for this, the structure's
layout begins with a size field; this allows loaders to know which
fields are available.

However, LLD hard-coded the sizes (112 bytes for 64-bit and 64 for
32-bit).  This means that we might not inform the loader of all the
pertinent fields or we might claim that there are more fields than are
actually present.

To correctly account for this, the size field must be loaded from the
_load_config_used symbol.

N.B.  The COFF spec is either wrong or out of date, the load
configuration directory is not correctly documented in the
specification: it omits the size field.

llvm-svn: 263543
2016-03-15 09:48:27 +00:00
David Majnemer 1706719972 [COFF] Remove an unused function, getFileOff
The function was not used and was not functional: all paths would lead
to report_fatal_error or endless stack recursion.

llvm-svn: 263542
2016-03-15 09:48:18 +00:00
David Majnemer 22a19a9ace [COFF] Use the correct size of the TLS directory
The TLS directory has a different layout depending on the bitness of the
machine the image will run on.  LLD would always use the 64-bit TLS
directory for the data directory entry instead of an appropriately sized
TLS directory.

llvm-svn: 263539
2016-03-15 06:41:02 +00:00
Rui Ueyama 02aa766897 Update the documents of the new LLD.
This patch merges the documents for ELF and COFF into one
and puts it into docs directory.

llvm-svn: 263336
2016-03-12 06:06:40 +00:00
Rui Ueyama a453c0a5ad Merge DarwinLdDriver and Driver.
Now that DarwinLdDriver is the only derived class of Driver.
This patch merges them and actually removed the class because
they can now just be non-member functions. This change simplifies
a common header, Driver.h.

http://reviews.llvm.org/D17788

llvm-svn: 262502
2016-03-02 19:08:05 +00:00
Rafael Espindola 393877d51b Fix BUILD_SHARED_LIBS build.
llvm-svn: 262345
2016-03-01 15:56:53 +00:00
Rui Ueyama 417553d393 Make the entry point function calls consistent. NFC.
llvm-svn: 262191
2016-02-28 19:54:51 +00:00
Rui Ueyama 29d8eef440 Rename so that the function name is consistent between ELF and COFF.
llvm-svn: 261914
2016-02-25 18:49:11 +00:00
Rui Ueyama 489a806965 Update for LLVM function name change.
llvm-svn: 257801
2016-01-14 20:53:50 +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
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 1763c0d3bc COFF: Create an empty but valid PDF file.
MSVC linker considers PDB files created with this patch valid.
So you don't have to remove PDB files created by lld before
running MSVC linker.

This patch has no test since llvm-pdbdump dislikes PDB files
with no metadata streams.

llvm-svn: 255039
2015-12-08 18:39:55 +00:00
Rui Ueyama e737824d8a COFF: Create a PDB file with the correct file signature.
Before this patch, we created an empty PDB file if /debug option is
specified. For MSVC linker, such PDB file is completely broken, and
linker exits without doing anything as soon as it finds an empty PDB
file.

A PDB file created in this patch has the correct file signature.
MSVC linker still thinks that the file is broken, but it then removes
and replaces with its output.

This is an initial patch to support PDB in LLD. We aim to support
PDB in order to make it 100% compatible with MSVC linker. PDB support
is the last missing piece.

llvm-svn: 254796
2015-12-04 23:11:05 +00:00
Rafael Espindola 3d49d7aa22 Update for llvm change.
llvm-svn: 254725
2015-12-04 16:22:09 +00:00
Rafael Espindola 35dad13714 Update for LLVM api change.
llvm-svn: 254697
2015-12-04 02:42:47 +00:00
Rui Ueyama 43e12900d9 COFF: Non-external COMDAT sections sholud not be merged by ICF.
If a section symbol is not external, that COMDAT section should never
be merge with other sections in other compilation unit. Previously,
we didn't take visibility into account.

Note that COMDAT sections with non-external visibility makes sense
because they can be removed by dead-stripping.

Fixes https://llvm.org/bugs/show_bug.cgi?id=25686

llvm-svn: 254578
2015-12-03 02:23:33 +00:00
Rui Ueyama df06d203e5 Update documents.
llvm-svn: 253728
2015-11-20 22:47:42 +00:00
Peter Collingbourne 70507e59fe COFF: Destroy LTOModules as they are linked.
This should help reduce memory consumption during LTO.

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

llvm-svn: 253397
2015-11-17 23:30:59 +00:00
Yunzhong Gao fbee89263f Fixing build failures caused by r253367. Sorry for breaking the build.
llvm-svn: 253374
2015-11-17 20:48:12 +00:00
Rafael Espindola 7bcaec83be Fix a few windows only tests.
This argument must be non-null.

llvm-svn: 252336
2015-11-06 19:57:37 +00:00
Kevin Enderby 35dfc95efe These are the matching changes needed to the lld project for the changes to llvm
in r252192 that changed the Archive and Child interfaces in libObject. These include
Rafael Espindola’s many suggested updates.

llvm-svn: 252193
2015-11-05 19:25:47 +00:00
Rafael Espindola 543f29d1a9 Don't implicitly construct an Archive::child_iterator.
llvm-svn: 252166
2015-11-05 14:34:56 +00:00
Rui Ueyama df985afa14 COFF: De-parallelize ICF for now.
There was a threading issue in the ICF code for COFF. That seems like
a venign bug in the sense that it doesn't produce an incorrect output,
but it oftentimes misses reducible sections. As a result, mergeable
sections could remain in outputs, which makes the output nondeterministic.

Basically the algorithm we are using for ICF is this: We group sections
so that identical sections will eventually be in the same group. Initially,
all sections are in one group. We split the group by relocation targets
until we get a convergence (if relocation targets are in different gruops,
the sections are different). Once a group is split, they will never be
merged.

Each section has a group ID. That variable itself is atomic, so there's
no threading issue at the level that we can use thread sanitizer.
The point is, when we split a group, we re-assign new group IDs to group
of sections. That are multiple separate writes to atomic varaibles.
Thus, splitting a group is not an atomic operation, and there's a small
chance that the other thread observes inconsistent group IDs.

Over-splitting is always "safe", so it will never create incorrect output.

I suspect that the nondeterminism stems from that point. However, I
cannot prove or fix that at this moment, so I'm going to avoid using
threads here.

llvm-svn: 251300
2015-10-26 16:20:00 +00:00
Craig Topper f88d22970d Update lld to match llvm r250901. OptTable constructor now takes an ArrayRef. NFC
llvm-svn: 250904
2015-10-21 16:31:56 +00:00
Rui Ueyama 75656eebb8 COFF: /OPT should accept comma-separated multiple arguments.
/OPT:foo,bar is equivalent to /OPT:foo /OPT:bar.

Reported by alexchandel. https://llvm.org/bugs/show_bug.cgi?id=25228

llvm-svn: 250728
2015-10-19 19:40:43 +00:00
Rui Ueyama 43155d0d48 [LLD] Fix Clang-tidy modernize-use-nullptr warnings; other minor cleanups.
Patch from Eugene Zelenko!

llvm-svn: 249111
2015-10-02 00:36:00 +00:00
Rui Ueyama 548d22c073 COFF: ICF should not merge sectinos if their alignments are not the same.
There's actually a room to improve this patch. Instead of not merging
sections that have different alignements, we can choose the section that
has the largest alignment requirement among all sections that are otherwise
considered the same. Then all section alignments are satisfied, so we can
merge them.

I don't know if that improvement could make any difference for real-world
input, so I'll leave it alone. Would be interesting to revisit later.

llvm-svn: 248581
2015-09-25 16:50:12 +00:00
Rui Ueyama c9e746b9e6 COFF: Fix local varaible type.
This is intended to be 64-bit integer, but size_t is not guranteed
to be the same or larger type than uint64_t.

llvm-svn: 248580
2015-09-25 16:38:13 +00:00