Commit Graph

2784 Commits

Author SHA1 Message Date
Chandler Carruth 9244582b8d Update makefile to reflect that the Passes directory is gone here.
llvm-svn: 231557
2015-03-07 09:03:17 +00:00
Rui Ueyama 9b21ded6c8 Resolver: optimize fallback atoms.
Atoms with fallback atoms are never be added to the symbol table.
However, we added such atoms to _undefines array. We had to call
isCoalescedAway to identify and skip them. We should just stop
adding them in the first place.

This seems to make the linker ~1% faster in my test case.

llvm-svn: 231552
2015-03-07 04:23:46 +00:00
Rui Ueyama abd39f0549 Resolver: Reduce number of SymbolTable::isDefined function calls.
If an undefined symbol is added to the symbol table by the previous
call of SymbolTable::add, SymbolTable::isDefined will always return
false for the same symbol.

llvm-svn: 231551
2015-03-07 03:55:32 +00:00
Rui Ueyama 923147b954 Resolver: Reduce number of hash function call.
This is yet another optimization patch. Previously we called
SymbolTable::isDefined() and SymbolTable::findByName() from a very
frequently executed function. Because isDefined calls findByName,
findByName is called twice on each iteration.

findByName is not a cheap function. It computes a hash value for a
given symbol name. When linking C++ programs, it can be expensive
because of C++ mangled long symbols.

This patch reduces the number of call from 2 to 1. Performance
improvements by this patch was larger than I expected. Linking time
of chrome.dll gets almost 5% shorter.

llvm-svn: 231549
2015-03-07 03:22:37 +00:00
Rui Ueyama e9d646d448 PECOFF: Do not add extraneous symbols to the dead strip root.
Previously we added all undefined symbols found in object files to
the dead strip root. This patch makes the linker to stop doing that.
Undefined symbols would be resolved anyway, so this patch doesn't
change the linker behavior. It should slightly improve performance
but it's really marginal. This is a cleanup.

llvm-svn: 231545
2015-03-07 01:35:50 +00:00
Rui Ueyama d4dc7d5739 Remove unused typedefs.
llvm-svn: 231543
2015-03-07 01:04:40 +00:00
Rui Ueyama 48c134ecd9 Use multimap<T, U> instead of map<T, set<U>>. NFC.
llvm-svn: 231542
2015-03-07 01:00:44 +00:00
Rui Ueyama 2039fc1f42 Resolver: move code inside an assert.
llvm-svn: 231518
2015-03-06 21:15:06 +00:00
Rui Ueyama 93ceadfb7b PECOFF: Optimize the writer using parallel_for.
Previously applying 1 million relocations took about 2 seconds on my
Xeon 2.4GHz 8 core workstation. After this patch, it takes about 300
milliseconds. As a result, time to link chrome.dll becomes 23 seconds
to 21 seconds.

llvm-svn: 231454
2015-03-06 06:53:13 +00:00
Davide Italiano 5dfe0ffb0c We want to add the entry point to the root set unconditionally, but these
asserts don't allow us to do it. Remove them, they're not really needed
anyway. 

llvm-svn: 231445
2015-03-06 02:05:03 +00:00
Rui Ueyama 41ee2e3ff9 Remove unused function.
llvm-svn: 231444
2015-03-06 01:44:07 +00:00
Rui Ueyama 13003d7774 Core: Make the resolver faster.
In the resolver, we maintain a list of undefined symbols, and when we
visit an archive file, we check that file if undefined symbols can be
resolved using files in the archive. The archive file class provides
find() function to lookup a symbol.

Previously, we call find() for each undefined symbols. Archive files
may be visited multiple times if they are in a --start-group and
--end-group. If we visit a file M times and if we have N undefined
symbols, find() is called M*N times. I found that that is one of the
most significant bottlenecks in LLD when linking a large executable.

find() is not a very cheap operation because it looks up a hash table
for a given string. And a string, or a symbol name, can be pretty long
if you are dealing with C++ symbols.

We can eliminate the bottleneck.

Calling find() with the same symbol multiple times is a waste. If a
result of looking up a symbol is "not found", it stays "not found"
forever because the symbol simply doesn't exist in the archive.
Thus, we should call find() only for newly-added undefined symbols.
This optimization makes O(M*N) O(N).

In this patch, all undefined symbols are added to a vector. For each
archive/shared library file, we maintain a start position P. All
symbols [0, P) are already searched. [P, end of the vector) are not
searched yet. For each file, we scan the vector only once.

This patch changes the order in which undefined symbols are looked for.
Previously, we iterated over the result of _symbolTable.undefines().
Now we iterate over the new vector. This is a benign change but caused
differences in output if remaining undefines exist. This is why some
tests are updated.

The performance improvement of this patch seems sometimes significant.
Previously, linking chrome.dll on my workstation (Xeon 2.4GHz 8 cores)
took about 70 seconds. Now it takes (only?) 30 seconds!

http://reviews.llvm.org/D8091

llvm-svn: 231434
2015-03-06 00:28:41 +00:00
Rui Ueyama 25d5abdb3a Optimize resolver by using std::unordered_multimap.
_reverseRef is a multimap from atoms to atoms. The map contains
reverse edges of "layout-before" and "group" edges for dead-stripping.

The type of the variable was DenseMap<Atom *, DenseSet<Atom *>>.
This patch changes that to std::unordered_multimap<Atom *, Atom *>.

A DenseMap with a value type of DenseSet was not fast. Inserting 900k
items to the map took about 1.6 seconds on my workstation.
unordered_multimap on the other hand took only 0.6 seconds.
Use of the map also got faster -- originally markLive took 1.3 seconds
in the same test case, and it now took 1.0 seconds. In total we shove
off 1.3 seconds out of 27 seconds in that test case.

llvm-svn: 231432
2015-03-06 00:22:48 +00:00
Rui Ueyama 6780cea628 Early return. NFC.
llvm-svn: 231403
2015-03-05 20:22:14 +00:00
Rui Ueyama e5bf769443 Resolver: Update preload map after File::beforeLink().
We maintain a map from symbols to archive files for the archive file
pre-loading. That map is created at the beginning of the resolve()
and is never updated. However, the input file list may be updated by
File::beforeLink(). This is a patch to update the map after beforeLink.

llvm-svn: 231395
2015-03-05 19:25:58 +00:00
Rui Ueyama 3ba3e7131e Remove dead code.
This hook is called from one of the hottest loops in LLD and does nothing.

llvm-svn: 231345
2015-03-05 02:58:13 +00:00
Rui Ueyama 97d8bec7ea Remove else if a last block ends with return.
llvm-svn: 231330
2015-03-05 01:02:20 +00:00
Rui Ueyama 4dfb0f0079 Remove redundant virtual destructor.
DefinedAtom, which is the base class of ELFCommonAtom, has a
virtual destructor, so this is redundant.

llvm-svn: 231329
2015-03-05 00:55:04 +00:00
Rui Ueyama 5d75b6346d Use range-based for loops to iterate over file nodes.
I converted them to non-range-based loops in r226883 and r226893
because at that moment File::parse() may have side effects and
may update the vector that the reference returned from
LinkingContext::nodes().

Now File::parse() is free from side effects. We can use range-based
loops again.

llvm-svn: 231321
2015-03-05 00:07:38 +00:00
Rui Ueyama 0eb0efbb63 PECOFF: Update comments on .drectve section encoding.
llvm-svn: 231316
2015-03-04 23:22:48 +00:00
Rui Ueyama 57c62e6ab9 PECOFF: Do not add layout-after edges.
The last use of layout-after edge for PE/COFF was removed in r231290.
Now layout-after edges do nothing. We can stop adding them to the graph.
No functionality change intended.

llvm-svn: 231301
2015-03-04 22:13:25 +00:00
Rui Ueyama 77a4da1991 Define DefinedAtom::sectionSize.
Merge::mergeByLargestSection is half-baked since it's defined
in terms of section size, there's no way to get the section size
of an atom.

Currently we work around the issue by traversing the layout edges
to both directions and calculate the sum of all atoms reachable.
I wrote that code but I knew it's hacky. It's even not guaranteed
to work. If you add layout edges before the core linking, it
miscalculates a size.

Also it's of course slow. It's basically a linked list traversal.

In this patch I added DefinedAtom::sectionSize so that we can use
that for mergeByLargestSection. I'm not very happy to add a new
field to DefinedAtom base class, but I think it's legitimate since
mergeByLargestSection is defined for section size, and the section
size is currently just missing.

http://reviews.llvm.org/D7966

llvm-svn: 231290
2015-03-04 21:40:46 +00:00
Rui Ueyama addf8ebd97 Remove "inline" from inlined functions.
llvm-svn: 231271
2015-03-04 18:51:19 +00:00
Rui Ueyama 394d10e34d Make File non-const in the resolver.
File objects are not really const in the resolver. We set ordinals to
them and call beforeLink hooks. Also, File's member functions marked
as const are not really const. ArchiveFile never returns the same
member file twice, so it remembers files returned before. find() has
side effects.

In order to deal with the inconsistencies, we sprinkled const_casts
and marked member varaibles as mutable.

This patch removes const from there to reflect the reality.

llvm-svn: 231212
2015-03-04 04:36:46 +00:00
Rui Ueyama cf8b003314 Revert "temporary"
This reverts accidental commit r231205.

llvm-svn: 231208
2015-03-04 02:12:55 +00:00
Rui Ueyama 5cc41029a2 Simplify FileArchive. NFC.
This patch moves local variable definitions so that their scope get narrower.
Also uses range-based loop. Both are for readability.

llvm-svn: 231206
2015-03-04 02:09:22 +00:00
Rui Ueyama f810b554ab temporary
llvm-svn: 231205
2015-03-04 02:09:21 +00:00
Rui Ueyama 302119effc Make a private function private.
llvm-svn: 231196
2015-03-04 01:26:32 +00:00
Rui Ueyama 791db5f0a3 Implement our own future and use that for FileArchive::preload().
std::promise and std::future in old version of libstdc++ are buggy.
I think that's the reason why LLD tests were flaky on Ubuntu 13
buildbots until we disabled file preloading.

In this patch, I implemented very simple future and used that in
FileArchive. Compared to std::promise and std::future, it lacks
many features, but should serve our purpose.

http://reviews.llvm.org/D8025

llvm-svn: 231153
2015-03-03 22:19:46 +00:00
Rui Ueyama 82ca5e72d2 Fix -Wcast-qual warning.
llvm-svn: 231139
2015-03-03 21:38:38 +00:00
Davide Italiano 7a89462158 [ELF] Implement R_X86_64_PC16 relocation.
Yet another chapter in the story. We're getting there, finally.
Note for the future: the tests for relocation have a lot of duplication
and probably can be unified in a single file. Let's reevaluate this once
the support will be complete (hopefully, soon).

llvm-svn: 231057
2015-03-03 07:38:20 +00:00
Rui Ueyama dbd7f2740c Make ArchiveLibraryFile::~ArchiveLibraryFile virtual.
"virtual" was present at a wrong place. FileArchive is a subclass of
ArchiveLibraryFile, and a FileArchive can be deleted through a
pointer of ArchiveLibraryFile. We want to make the destructor of the
base class virtual.

llvm-svn: 231033
2015-03-02 23:03:33 +00:00
Rui Ueyama 25b87a4b5b Remove include/lld/Core/Endian.h and use llvm/Support/Endian.h instead.
llvm-svn: 231005
2015-03-02 20:31:43 +00:00
Davide Italiano d333c36e8a Update the list of relocations that need to be implemented.
While at it, point the correct document where the missing TLS
relocation(s) are described.

llvm-svn: 230937
2015-03-02 06:17:38 +00:00
Benjamin Kramer 06a42af61e Add missing includes for make_unique, lld edition.
llvm-svn: 230925
2015-03-02 00:48:06 +00:00
Rui Ueyama 990bb16036 Revert "PECOFF: Don't parse files in .drectve asynchronously."
This reverts commit r228955. Previously files appear in a .drectve
section are parsed synchronously to avoid threading issues. I believe
it's now safe to do that asynchronously.

llvm-svn: 230905
2015-03-01 20:48:14 +00:00
Rui Ueyama 0c177051b7 Revert "PECOFF: Temporarily add a lock to un-break buildbot."
This reverts commit r230086. I added a lock to guard FileCOFF::doParse(),
which killed parallel file parsing. Now the buildbots got back to green,
I believe the threading issue was resolved, so it's time to remove the
guard to see if it works with the buildbots.

llvm-svn: 230886
2015-03-01 04:25:04 +00:00
Rui Ueyama b2e16973df Do s/_context/_ctx/ to Resolver.cpp.
llvm-svn: 230814
2015-02-27 23:40:00 +00:00
Rui Ueyama cb1c4d1a9a Remove a varaible that's used only once. NFC.
llvm-svn: 230813
2015-02-27 23:36:05 +00:00
Rui Ueyama c817fd2273 Call File::beforeLink hook even if the file is in an archive.
Previously we didn't call the hook on a file in an archive, which
let the PE/COFF port fail to link files in archives. It was a
simple mistake. Added a call to the hook and also added a test to
catch that error.

const_cast is an unfortunate hack. Files in the resolver are usually
const, but they are not actually const objects, since they are
mutated if either a file is taken from an archive (an archive file
does never return the same file twice) or the beforeLink hook is
called. Maybe we should just remove const from there -- because they
are not const.

llvm-svn: 230808
2015-02-27 23:15:11 +00:00
Rui Ueyama 400385c8be PECOFF: Move a call of WinLinkDriver::parse from FileCOFF::doParse to FileCOFF::beforeLink
In doParse, we shouldn't do anything that has side effects. That function may be
called speculatively and possibly in parallel.

We called WinLinkDriver::parse from doParse to parse a command line in a .drectve
section. The parse function updates a linking context object, so it has many side
effects. It was not safe to call that function from doParse. beforeLink is a
function for a File object to do something that has side effects. Moving a call
of WinLinkDriver::parse to there.

llvm-svn: 230791
2015-02-27 20:39:20 +00:00
Rui Ueyama 9f872a80c7 PECOFF: Use StringRef::find_first_of instead of a hand-written loop.
llvm-svn: 230770
2015-02-27 18:06:41 +00:00
Davide Italiano b65719ae78 [ELF] Set up initial live symbol(s) to avoid incorrect reclaim of atoms.
If no initial live symbols are set up, and deadStrip() == true,
the Resolver ends up reclaiming all the symbols that aren't absolute. This is wrong.
This patch fixes the issue by setting entrySymbolName() as live, and this allows
us to self-host lld when --gc-sections is enabled. There are still quite a few problems
with --gc-sections (test failures), so the option can't be enabled by default.

Differential Revision:	D7926
Reviewed by:	ruiu, shankarke

llvm-svn: 230737
2015-02-27 06:41:46 +00:00
Rui Ueyama 0bde1de3bd Temporarily disable FileArchive::preload().
It is observed that the function throws std::future_error on a few buildbots.
That cannot be easily reproducible on local machines. Kill the feature
temporarily to see if this is going to fix the buildbot issue.

llvm-svn: 230735
2015-02-27 05:26:05 +00:00
Rui Ueyama 6c39e77896 Partially revert "PECOFF: Do not add layout-after edges."
This reverts commit r230732.

sectionSize() in lib/Core/SymbolTable.cpp still depends on the layout-
after edges, so we couldn't remove them yet.

llvm-svn: 230734
2015-02-27 05:22:19 +00:00
Shankar Easwaran 93c7fa209c [ELF] Remove includes that are not used
This remove(s) include of the filename twice.

llvm-svn: 230733
2015-02-27 05:12:30 +00:00
Rui Ueyama 584abaee67 PECOFF: Do not add layout-after edges.
Previously we needed to create atoms as a doubly-linked link, but it's
no longer needed. Also we don't use layout-after edges in PE/COFF.
Creating such edges is just waste.

llvm-svn: 230732
2015-02-27 05:05:38 +00:00
Shankar Easwaran 60aa7985cc [CMake] Cleanup
llvm-svn: 230731
2015-02-27 04:39:16 +00:00
Rui Ueyama 41c8b56a2a Twine should be used within a statement.
llvm-svn: 230730
2015-02-27 04:23:23 +00:00
Rui Ueyama 5b3d935fce Update comments, fix typos.
llvm-svn: 230729
2015-02-27 04:23:21 +00:00
Rui Ueyama e088a0f989 Use read{le,be}{16,32}. NFC.
llvm-svn: 230728
2015-02-27 04:21:40 +00:00
Rui Ueyama 4a528dd5be Remove unused #includes.
llvm-svn: 230726
2015-02-27 03:23:52 +00:00
Rui Ueyama 7cea026a63 Add {read,write}{16,32,64}{le,be} functions.
Nothing wrong with reinterpret_cast<llvm::support::ulittle32_t *>(loc),
but that's redundant and not great from readability point of view.
The new functions are wrappers for that kind of reinterpet_casts.

Surprisingly or unsurprisingly, there was no use of big endian read
and write. {read,write}{16,32,64}be have no user. But I think they
still worth to be there in the header for completeness.

http://reviews.llvm.org/D7927

llvm-svn: 230725
2015-02-27 03:18:46 +00:00
Rui Ueyama 53a93c6c39 PECOFF: allow more than one /alternatename for the same symbol.
Previously we have a string -> string map to keep the weak alias
symbol mapping. Naturally we can't define more than one weak alias
with that data structure.

This patch is to allow multiple aliases for the same symbol by
changing the map type to string -> set of string map.

llvm-svn: 230702
2015-02-26 23:43:04 +00:00
Reid Kleckner 48e04e492f Give enum an unsigned type to silence -Wmicrosoft clang-cl warning
llvm-svn: 230687
2015-02-26 21:10:01 +00:00
Simon Atanasyan 82ae48eeb5 [Driver] Use paths explicitly provided by the -L option before default paths
User should be able to override default search paths using the -L
option.

http://reviews.llvm.org/D7902

llvm-svn: 230679
2015-02-26 20:09:50 +00:00
Simon Atanasyan 27967c843b [ELF] Reduce the code indentation
No functional changes.

llvm-svn: 230678
2015-02-26 20:09:42 +00:00
Simon Atanasyan 009c28a231 [Mips] Mark some MipsELFFile member functions as constant
No functional changes.

llvm-svn: 230677
2015-02-26 20:09:37 +00:00
Davide Italiano a82ae9146e [Core] Do not reclaim absolute atoms in resolver.
This fixes a linker crash (found out while testing --gc-sections,
testcase provided by Rafael Avila de Espindola).
While this behaviour was found while testing ELF, it' not necessarily
ELF specific and this change is (apparently) harmless on all the
other drivers.

Differential Revision:  D7823
Reviewed by:    ruiu

llvm-svn: 230614
2015-02-26 05:39:57 +00:00
Michael J. Spencer 09358d247a Add Example Sub Target.
llvm-svn: 230594
2015-02-26 00:48:10 +00:00
Michael J. Spencer 6a272cdc83 [ELF][x86-64] Make the X86_64LinkingContext and X86_64TargetHandler derivable.
llvm-svn: 230593
2015-02-26 00:47:34 +00:00
Michael J. Spencer 39c30439c1 Remove unused variables.
llvm-svn: 230578
2015-02-25 23:48:33 +00:00
Michael J. Spencer 751bb41be4 [ELF][x86] Detemplatify ELFT. There's only a single valid instantiation.
llvm-svn: 230574
2015-02-25 23:27:13 +00:00
Davide Italiano 9793956644 [ELF][X86_64] Handle R_X86_64_PC64 relocation
Differential Revision:	D7820
Reviewed by:	shankarke, ruiu

llvm-svn: 230465
2015-02-25 05:56:05 +00:00
Michael J. Spencer b6396eaef9 Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
llvm-svn: 230422
2015-02-25 01:30:13 +00:00
Shankar Easwaran b6c31f3878 [ELF] Create a map from Reference to Symbol.
In LLD's model, symbol is a property of the node (atom) and not a property of
edge (reference). Prior to this patch, we stored the symbol in the reference.
From post-commit comments, it seemed better to create a map from the reference
to the symbol instead and use this mapping wherever desired.

Address comments from Ruiu/Simon Atanasyan.

llvm-svn: 230273
2015-02-23 22:32:12 +00:00
Shankar Easwaran 8198cfd8a7 [ELF][Writer] Use llvm::StringMap instead
Cleanup.

llvm-svn: 230219
2015-02-23 13:50:23 +00:00
Shankar Easwaran 97dae2a0cd [ELF] Add comments in the ELF reader
Address review comments from Ruiu, and add some more TODO's.

llvm-svn: 230218
2015-02-23 13:25:44 +00:00
Shankar Easwaran 9e07346679 [ELF] Add section group/COMDAT support.
SHF_GROUP: Group Member Sections
----------------------------------
A section which is part of a group, and is to be retained or discarded with the
group as a whole, is identified by a new section header attribute: SHF_GROUP
This section is a member (perhaps the only one) of a group of sections, and the
linker should retain or discard all or none of the members. This section must be
referenced in a SHT_GROUP section. This attribute flag may be set in any section
header, and no other modification or indication is made in the grouped sections.
All additional information is contained in the associated SHT_GROUP section.

SHT_GROUP: Section Group Definition
-------------------------------------
Represents a group section.

The section group's sh_link field identifies a symbol table section, and its
sh_info field the index of a symbol in that section. The name of that symbol is
treated as the identifier of the section group.

More information: https://mentorembedded.github.io/cxx-abi/abi/prop-72-comdat.html

Added a lot of extensive tests, that tests functionality.

llvm-svn: 230195
2015-02-23 00:30:00 +00:00
Shankar Easwaran de4a31909f [ELF] Add .gnu.linkonce support.
When the GNU linker sees two input sections with the same name, and the name
starts with ".gnu.linkonce.", the linker will only keep one copy and discard the
other. Any section whose name starts with “.gnu.linkonce.” is a COMDAT section.

Some architectures like Hexagon use this section to store floating point constants,
that need be deduped.

This patch adds gnu.linkonce functionality to the ELFReader.

llvm-svn: 230194
2015-02-23 00:04:49 +00:00
Shankar Easwaran a1d3637f3d [Core,MachO,Test] Remove trailing whitespace.
llvm-svn: 230192
2015-02-22 23:54:38 +00:00
Shankar Easwaran 784b56caac [ELF] Add symbol to ELFReference.
Relocation handling need more information about the Symbol that we are creating
references for.

No change in functionality.

llvm-svn: 230191
2015-02-22 23:46:21 +00:00
Shankar Easwaran e44fc87cde [Core] Fix handling of Section Groups.
There is code(added by me) in the YAMLReader which isn't correct when it handles references
for section groups. The test case was also checking for wrong outputs.

This fixes the bug and the testcase so that they check for proper outputs.

llvm-svn: 230190
2015-02-22 23:40:58 +00:00
Shankar Easwaran 45b392d6cf [ELF][X86_64] R_X86_64_16 relocation support
llvm-svn: 230189
2015-02-22 23:32:34 +00:00
Chandler Carruth b9aa3a61c9 Switch to use override, fixes -Winconsistent-missing-override on LLD.
llvm-svn: 230166
2015-02-22 08:34:47 +00:00
Davide Italiano 9483dc21be [ELF] Teach GNU Driver about --stats.
This is mainly for back-compatibility with GNU ld.
Ideally --stats should be a general option in LinkingContext, providing
individual stats for every pass in the linking process.
In the GNU driver, a better wording could be used, but there's no need
to change it for now.

Differential Revision:	D7657
Reviewed by:	ruiu

llvm-svn: 230157
2015-02-22 03:12:21 +00:00
Shankar Easwaran 75ed9746e6 [ELF] Remove FIXME(s) that are already fixed.
FIXME code was left around in few places where its already been taken care of.

This removes the FIXME's that are not needed.

llvm-svn: 230139
2015-02-21 15:51:54 +00:00
Shankar Easwaran 99abafb4af [ELF][Writer] Use Path to create AtomSection.
Now since the correct file path for atoms is available and not clobbered,
commit r222309 which was reverted previously can be added back.

No change in functionality.

llvm-svn: 230138
2015-02-21 15:49:34 +00:00
Shankar Easwaran b8301da4a1 [ELF] Fix References being ignored.
The ELFReader was skipping references for sections that contained relocations.

This fixes the bug.

llvm-svn: 230127
2015-02-21 04:42:43 +00:00
Rui Ueyama 0068408001 PECOFF: Temporarily add a lock to un-break buildbot.
Looks like there's a threading issue in the COFF reader which makes
buildbot unstable. Probability of crash varies depending on the number
of input. If we are linking a big executalbe, LLD almost always crash.

This patch temporarily adds a lock to guard the reader so that LLD
doesn't crash. I'll investigate and fix the issue as soon as possible
because this patch has negative performance impact.

llvm-svn: 230086
2015-02-20 23:22:36 +00:00
Rui Ueyama 2c64aef35f Remove YAML/Native round-trip passes.
The round-trip passes were introduced in r193300. The intention of
the change was to make sure that LLD is capable of reading end
writing such file formats.

But that turned out to be yet another over-designed stuff that had
been slowing down everyday development.

The passes ran after the core linker and before the writer. If you
had an additional piece of information that needs to be passed from
front-end to the writer, you had to invent a way to save the data to
YAML/Native. These passes forced us to do that even if that data
was not needed to be represented neither in an object file nor in
an executable/DSO. It doesn't make sense. We don't need these passes.

http://reviews.llvm.org/D7480

llvm-svn: 230069
2015-02-20 22:10:28 +00:00
Rui Ueyama 7675f06c01 Remove redundant "explicit".
llvm-svn: 230015
2015-02-20 14:57:04 +00:00
Jean-Daniel Dupas 7329636d1b [Mach-O] Remove redundant allocator
llvm-svn: 230007
2015-02-20 11:57:06 +00:00
Justin Bogner de525e76d7 Driver: Fix an incorrect use of llvm::None
This function returns a bool, so llvm::None doesn't make sense here.

llvm-svn: 229997
2015-02-20 08:19:43 +00:00
David Majnemer 62ac78ae3e LinkerScript: Remove leaks in the parser
LinkerScript AST nodes are never destroyed which means that their
std::vector members will never be destroyed.

Instead, allocate the operand list itself in the Parser's
BumpPtrAllocator.  This ensures that the storage will be destroyed along
with the nodes when the Parser is destroyed.

llvm-svn: 229967
2015-02-20 05:10:06 +00:00
Rui Ueyama 11f42aa285 PECOFF: Fix base relocation for ImageBase.
This is yet another edge case of base relocation for symbols. Absolute
symbols are in general not target of base relocation because absolute
atom is a way to point to a specific memory location. In r229816, I
removed entries for absolute atoms from the base relocation table
(so that they won't be fixed by the loader).

However, there was one exception -- ImageBase. ImageBase points to the
start address of the current image in memory. That needs to be fixed up
at load time. This patch is to treat the symbol in a special manner.

llvm-svn: 229961
2015-02-20 03:35:59 +00:00
Greg Fitzgerald cdaea4db26 Fix heap-buffer-overflow bugs identified by the Address Sanitizer
Differential Revision: http://reviews.llvm.org/D7733

llvm-svn: 229912
2015-02-19 20:42:23 +00:00
Jean-Daniel Dupas c31da7010b [Mach-O] Rename enum typename for consistency. NFC
Typename shouldn't mix camel case and underscore.
Thanks to Rui for the remark.

llvm-svn: 229848
2015-02-19 12:38:54 +00:00
Rui Ueyama 3966c61536 PECOFF: Fix base relocation for an absolute symbol.
Previously we wrongly emitted a base relocation entry for an absolute symbol.
That made the loader to rewrite some instruction operands with wrong values
only when a DLL is not loaded at the default address. That caused a
misterious crash of some executable.

Absolute symbols will of course never change value wherever the binary is
loaded to memory. We shouldn't emit base relocations for absolute symbols.

llvm-svn: 229816
2015-02-19 04:22:27 +00:00
Rui Ueyama 3e6490f1e8 PECOFF: use llvm-readobj to dump .reloc section
When this test was written, no llvm tool could print out contents
of base relocation section. Now llvm-readobj is able to dump it in
a text format. Use that tool to make this test readable.

llvm-svn: 229814
2015-02-19 04:02:17 +00:00
Rui Ueyama 92b5979cb5 PECOFF: Fix symbol aliases
Weak aliases defined using /alternatename command line option were getting
wrong RVAs in the final output because of wrong atom ordinal. Alias atoms
were assigned large ordinals than any other regular atoms because they were
instantiated after other atoms and just got new (larger) ordinals.

Atoms are sorted by its file and atom ordinals in the order pass. Alias
atoms were located after all other atoms in the same file.

An alias atom's ordinal needs to be smaller than its alias target but larger
than the atom appeared before the target -- so that the alias is located
between the two. Since an alias has no size, the alias target will be located
at the same location as the alias.

In this patch, I made a gap between two regular atoms so that we can put
aliases after instantiating them (without re-numbering existing atoms).

llvm-svn: 229762
2015-02-18 23:11:48 +00:00
Greg Fitzgerald 7f1c7e1bef Fix use-after-free bug identified by the Address Sanitizer
atomContent's memory is freed at the end of the stack frame,
but it is referenced by the atom pushed into _definedAtoms.

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

llvm-svn: 229749
2015-02-18 21:54:32 +00:00
Davide Italiano 6d86bb2f8b [ELF] Demangle: don't expose raw info when getter is available.
Differential Revision:	D7693
Reviewed by:	shankarke

llvm-svn: 229635
2015-02-18 03:54:21 +00:00
Will Newton 8d62e098ef Fix AArhc64 ELF test failure on Windows
The atoms may be processed in different orders on different systems
based on allocated addresses. This is a bit unfortunate as it would
be nice to have error messages emitted in order of file contents.
However we are emitting errors inside a parallel_for_each so even if
we stabilize the order of atom processing we would need to do some
further work in order to ensure that thread scheduling doesn't perturb
the order of errors. For now switch to using CHECK-DAG instead of CHECK.

llvm-svn: 229487
2015-02-17 11:16:54 +00:00
Simon Atanasyan f83bd0341d [Mips] Replace a magic number by enumeration
No functional changes.

llvm-svn: 229453
2015-02-16 23:08:20 +00:00
Simon Atanasyan fbe1348ef4 [Mips] Read GP0 value from .MIPS.options section
llvm-svn: 229442
2015-02-16 21:52:43 +00:00
Simon Atanasyan 371e1128b3 [Mips] Show error if MIPS_REGINFO section has invalid size
llvm-svn: 229441
2015-02-16 21:52:35 +00:00
Simon Atanasyan 00400f252d [Mips] Factor out the code to search section by type and flags into the
separate functions

No functional changes.

llvm-svn: 229440
2015-02-16 21:52:27 +00:00
Aaron Ballman 4d0397382c MSVC no longer requires the explicit cast operation to obtain a function pointer from this capture-less lambda. NFC.
llvm-svn: 229426
2015-02-16 19:38:52 +00:00
Aaron Ballman d816003d2b MSVC 2013 appears to be able to compile make_ptr_range without issue, so removing that guard in the unit test.
llvm-svn: 229410
2015-02-16 18:00:11 +00:00
Aaron Ballman 80c1239f1b Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; lld edition.
llvm-svn: 229341
2015-02-15 23:10:05 +00:00
Jean-Daniel Dupas 9c222630e4 Update ARM and x86 ArchHandler to check switch completeness. NFC
Define an explicit type for arch specific reference kinds to make sure all cases are covered in switch statements.

llvm-svn: 229314
2015-02-15 15:23:48 +00:00
Jean-Daniel Dupas 1536f0641b Break some test. Revert until I got a proper fix
llvm-svn: 229249
2015-02-14 09:10:25 +00:00
Jean-Daniel Dupas 8860b8d70c Update ARM and x86 ArchHandler to match 64bits counterparts. NFC
Summary:
Define an explicit type for arch specific reference kind and use it in switch statement to make the compiler emit warnings if some case is not cover.
It will help to catch such errors when we add new mach-o reference kind.

Reviewers: shankarke, kledzik

Reviewed By: shankarke

Subscribers: shankarke, aemerson, llvm-commits

Projects: #lld

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

llvm-svn: 229246
2015-02-14 08:34:37 +00:00
Shankar Easwaran 8911240c9e [ELF] Replace std::set with StringSet.
Wrap functionality was using a std::set to record symbols that need to be
wrapped. This changes the implementation to use a StringSet instead.

No change in functionality.

llvm-svn: 229165
2015-02-13 22:26:51 +00:00
Jean-Daniel Dupas 5716bb9faa Remove file not used anywhere.
llvm-svn: 229109
2015-02-13 14:30:22 +00:00
Jean-Daniel Dupas 48bc169f04 Using 'isa' instead of 'dyn_cast'
llvm-svn: 229107
2015-02-13 14:28:18 +00:00
Will Newton 6b3f59b6a9 ELF/AArch64: Add support for checking for ABS32 overflow
Add support for checking overflow when applying a R_AARCH64_ABS32
relocation and add a test to ensure it behaves correctly.

llvm-svn: 229072
2015-02-13 06:22:31 +00:00
Rui Ueyama d9cb620330 Remove unused parameters.
llvm-svn: 229055
2015-02-13 04:02:55 +00:00
Rui Ueyama 8e19879f5a Remove KindArcH::PowerPC and sort enums alphabetically.
llvm-svn: 229051
2015-02-13 03:47:34 +00:00
Rui Ueyama dcd61c2d14 Remove class that really does nothing.
llvm-svn: 229030
2015-02-13 02:34:08 +00:00
Rui Ueyama acbe51a0e3 PECOFF: Fix dummy symbol table in executable.
If the name field of a symbol table entry is all zero, it's interpreted
as it's pointing to the beginning of the string table. The first four
bytes of the string table is the size field, so dumpbin dumps that number
as an ASCIZ string.

This patch fills a dummy value to name field.

llvm-svn: 228971
2015-02-12 22:46:16 +00:00
Shankar Easwaran 7d71622c8f [ELF] Insert wrap symbols into a set.
Symbols specified by --wrap was being inserted into a vector, change this to
insert into a set, so that we have unique entries.

llvm-svn: 228968
2015-02-12 22:37:27 +00:00
Rui Ueyama 3c3c7d8911 PECOFF: Don't parse files in .drectve asynchronously.
Looks like there's a race condition around here that caused LLD to crash
on Windows. Currently we are parsing libraries specified by .drectve section
asynchronously, and something is wrong in that process. Disable the feature
for now to make buildbots happy.

llvm-svn: 228955
2015-02-12 20:33:40 +00:00
Shankar Easwaran 5c094b8751 [ELF][Cleanup] Remove unused function
We can add this function when we really have a need.

llvm-svn: 228907
2015-02-12 05:29:50 +00:00
Shankar Easwaran 2df0c3efd6 [ELF] Support --wrap option
Use a wrapper function for symbol. Any undefined reference to symbol will be
resolved to "__wrap_symbol". Any undefined reference to "__real_symbol" will be
resolved to symbol.

This can be used to provide a wrapper for a system function. The wrapper
function should be called "__wrap_symbol". If it wishes to call the system
function, it should call "__real_symbol".

Here is a trivial example:

void * __wrap_malloc (size_t c)
{
  printf ("malloc called with %zu\n", c);
  return __real_malloc (c);
}

If you link other code with this file using --wrap malloc, then all calls
to "malloc" will call the function "__wrap_malloc" instead. The call to
"__real_malloc" in "__wrap_malloc" will call the real "malloc" function.

llvm-svn: 228906
2015-02-12 05:02:46 +00:00
Shankar Easwaran f7a8da3384 [ELF] Add LinkingContext to the ELFReader.
This adds the LinkingContext parameter to the ELFReader. Previously the flags in
that were needed in the Context was passed to the ELFReader, this made it very
hard to access data structures in the LinkingContext when reading an ELF file.

This change makes the ELFReader more flexible so that required parameters can be
grabbed directly from the LinkingContext.

Future patches make use of the changes.

There is no change in functionality though.

llvm-svn: 228905
2015-02-12 05:02:41 +00:00
Rui Ueyama 1a40b2062c PECOFF: make dumpbin tool happy.
The dumpbin tool in the MSVC toolchain cannot handle an executable created
by LLD if the executable contains a long section name.

In PE/COFF, a section name is stored to a section table entry. Because the
section name field in the table is only 8 byte long, a name longer than
that is stored to the string table and the offset in the string table is
stored to the section table entry instead.

In order to look up a string from the string table, tools need to handle
the symbol table, because the string table is defined as it immediately
follows the symbol table.

And seems the dumpbin doesn't like zero-length symbol table.

This patch teaches LLD how to emit a dummy symbol table. The dummy table
has one dummy entry in it.

llvm-svn: 228900
2015-02-12 02:50:05 +00:00
Rui Ueyama 30c5387983 Remove unused parameter.
llvm-svn: 228887
2015-02-11 23:22:34 +00:00
Denis Protivensky d6fe5b3005 [ELF][ARM] Fix veneer symbol names in Release build
The fix is for r228680.
This makes tests also work.

llvm-svn: 228837
2015-02-11 15:02:43 +00:00
Rui Ueyama 123ad4cde7 GNU: Rename parseZOption because it actually parses only -z max-page-size.
llvm-svn: 228753
2015-02-10 21:40:51 +00:00
Rui Ueyama ea6c8e9c1f Unittest: Do s/_context/_ctx/g.
llvm-svn: 228750
2015-02-10 21:28:52 +00:00
Rui Ueyama 2050b61451 GNU: Add --no-export-dynamic command line option.
llvm-svn: 228749
2015-02-10 21:27:31 +00:00
Rui Ueyama c008539736 Driver: move non-positional parameters out of switch. NFC.
llvm-svn: 228743
2015-02-10 20:57:43 +00:00
Rui Ueyama 4c30cb3d2f Use override rather than virtual.
llvm-svn: 228723
2015-02-10 18:59:37 +00:00
Rui Ueyama 375c5e2353 GNU: Use StringRef::empty instead of a boolean flag.
This local variable name did not follow the style guide,
and it is not actually needed.

llvm-svn: 228722
2015-02-10 18:55:39 +00:00
Rui Ueyama d003ab3207 Driver: use hasArg instead of getLastArg if return value is not used.
llvm-svn: 228717
2015-02-10 18:34:46 +00:00
Denis Protivensky e35908b18f [ELF][ARM] Add veneer generation to branch instructions
When calling ARM code from Thumb and vice versa,
a veneer that switches instruction set should be generated.
Added veneer generation for ARM_JUMP24 ARM_THM_JUMP24 instructions.

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

llvm-svn: 228680
2015-02-10 09:31:42 +00:00
Rui Ueyama 7960d04f13 Driver: Replace switch cases with ifs.
We used to do like this instead of putting all command line processing
code within one gigantic switch statement. It is converted to a switch
in r188958, which introduced InputGraph.

In this patch I roll that change back. Now all "break"s are removed,
and the nesting is one level shallow.

llvm-svn: 228646
2015-02-10 01:10:23 +00:00
Rui Ueyama 55240af6a3 Remove trailing space.
llvm-svn: 228643
2015-02-10 01:06:14 +00:00
Davide Italiano 1fd20ff599 [ELF] Implement --strip-all/-s
Differential Revision:	D7489
Reviewed by:	shankarke

llvm-svn: 228533
2015-02-08 19:42:15 +00:00
Rui Ueyama 669d9486f9 Remove unused parameter.
llvm-svn: 228476
2015-02-07 00:54:46 +00:00
Rui Ueyama f54e4fd3c6 PECOFF: Move error check for invalid command line combination to validateImpl.
llvm-svn: 228461
2015-02-06 23:09:13 +00:00
Rui Ueyama 92634be399 Use make_unique.
llvm-svn: 228453
2015-02-06 22:44:16 +00:00
Rui Ueyama a209f0d892 Remove unused #include.
llvm-svn: 228450
2015-02-06 22:34:29 +00:00
Rui Ueyama 3d68e41d2d ELF: Split OrderPass::compareInitFini for readability. NFC.
llvm-svn: 228449
2015-02-06 22:32:09 +00:00
Shankar Easwaran d050c50522 [Revert] [ELF] Determine default search directories from Context
It looks like the Driver manages search path for each Target lld would support
on the Gnu flavor.

llvm-svn: 228440
2015-02-06 21:23:50 +00:00
Shankar Easwaran 6aa03e230c Revert "[Core] Update ContentPermissions"
This reverts commit r228381.

The MachO writer uses the permissions as bit masks.

llvm-svn: 228401
2015-02-06 14:55:40 +00:00
Shankar Easwaran fa9eec2e6b [Core] Update ContentPermissions
The values are already arranged in ascending order, and all tests still pass.

Removing the values as its confusing when new enumerations need to be added.

llvm-svn: 228381
2015-02-06 05:29:49 +00:00
Shankar Easwaran c65bd69690 [ELF][TODO] Update TODO.
llvm-svn: 228380
2015-02-06 05:29:48 +00:00
Shankar Easwaran 2ba4f5d9e3 [Cleanup] Remove member functions added to support nostdlib
No change in functionality.

llvm-svn: 228379
2015-02-06 05:01:38 +00:00
Shankar Easwaran c8299e1f15 [ELF] Remove stray semicolon
llvm-svn: 228378
2015-02-06 04:50:22 +00:00
Shankar Easwaran 8825dbdd85 [ELF] Speedup creating program headers.
After the total number of program headers are determined, virtual addresses
and file offsets need not be reassigned for sections whose virtual addresses and
fileoffsets remained the same.

This doesnot change any functionality.

llvm-svn: 228377
2015-02-06 04:15:04 +00:00
Shankar Easwaran 8f1b2d0930 [Core] Remove roundTripPass() function.
Use the environment variable "LLD_RUN_ROUNDTRIP_TEST" in the test that you want
to disable, as

RUN: env LLD_RUN_ROUNDTRIP_TEST= <run>

This was a patch that I made, but I find this a better way to accomplish what we
want to do.

llvm-svn: 228376
2015-02-06 04:15:02 +00:00
Shankar Easwaran e315edd747 [ELF] Fix -nostdlib option.
Only search library directories explicitly specified
on the command line. Library directories specified in linker
scripts (including linker scripts specified on the command
line) are ignored.

llvm-svn: 228375
2015-02-06 04:15:00 +00:00
Rui Ueyama f038a52542 Add methods to get archive file name from member file.
Previously we only have File::path() to get the path name of a file.
If a file was a member of an archive file, path() returns a concatenated
string of the file name in the archive and the archive file name.
If we wanted to get a file name or an archive file name, we had to
parse that string. That's of course not good.

This patch adds new member functions, archivePath and memberPath, to File.

http://reviews.llvm.org/D7447

llvm-svn: 228352
2015-02-05 22:51:36 +00:00
Rui Ueyama 540842ccf5 Cleanup. NFC.
Make customOrder pareamter mandatory because the argument is
always passed.

llvm-svn: 228342
2015-02-05 20:08:04 +00:00
Rui Ueyama 0076215b88 MachO: Move LayoutPass to MachO directory.
The real user of the LayoutPass is now only Mach-O, so move that
pass out of the common directory to Mach-O directory.

"Core" architecture were using the LayoutPass. I modified that
to use a simple OrderPass. I think no one actually have authority
what feature should be in Core and what's not, but I believe the
LayoutPass is not very suitable for Core. Before more code starts
depending on the complex pass, it's better to remove that from
Core.

I could have simplified that pass because Mach-O is the only user
of the LayoutPass. For example, the second parameter of the
LayoutPass constructor can be converted from optional to mandatory.
I didn't do that in this patch to keep it simple. I'll do in a
followup patch.

http://reviews.llvm.org/D7311

llvm-svn: 228341
2015-02-05 20:05:33 +00:00
Rui Ueyama df7d133cdf PECOFF: Fix I386_DIR32 relocation to an absolute symbol
Previously, we incorrectly added the image base address to an absolute
symbol address (that calculation doesn't make any sense) if an
IMAGE_REL_I386_DIR32 relocation is applied to an absolute symbol.

This patch fixes the issue. With this fix, we can link Bochs using LLD.
(Choosing Bochs has no special meaining -- I just picked it up as a
test program and found it didn't work.) This also fixes one of the
issues we currently have to link Chromium using LLD.

llvm-svn: 228279
2015-02-05 07:22:53 +00:00
Shankar Easwaran d67bcb5f5c [ELF] Dont discard sections in the input file.
The reader was discarding certain types of sections from the input file.

llvm-svn: 228268
2015-02-05 02:56:06 +00:00