Commit Graph

346 Commits

Author SHA1 Message Date
Denis Protivensky 0c8beb1c95 [LinkerScript] Process program header in PHDRS command
Add PT_PHDR segment depending on its availability in linker script's
PHDRS command, fallback if no linker script is given.
Handle FILEHDR, PHDRS and FLAGS attributes of program header.

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

llvm-svn: 244743
2015-08-12 12:31:35 +00:00
Denis Protivensky 1aaf736d89 [LinkerScript] Add matching of output sections to segments
Add method to query segments for specified output section name.
Return error if the section is assigned to unknown segment.
Check matching of sections to segments during layout on the subject of correctness.
NOTE: no actual functionality of using custom segments is implemented.

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

llvm-svn: 239719
2015-06-15 08:00:51 +00:00
Denis Protivensky 02fc0b1d64 [ARM] Move out .ARM.exidx related things to ARM backend
llvm-svn: 238191
2015-05-26 10:26:15 +00:00
Leny Kholodov bde4144338 [ARM] Generation of .ARM.exidx/.ARM.extab sections
This patch provides generation of .ARM.exidx & .ARM.extab sections which are
used for unwinding. The patch adds new content type typeARMExidx for atoms from
.ARM.exidx section and integration of atoms with such type to the ELF
ReaderWriter. exidx.test has been added with checking of contents of .ARM.exidx
section and .ARM.extab section.

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

llvm-svn: 236873
2015-05-08 16:04:11 +00:00
Rafael Espindola 6759319c3c Use MemoryBufferRef instead of MemoryBuffer&. NFC.
This just reduces the noise from another patch.

llvm-svn: 235776
2015-04-24 21:10:50 +00:00
Rafael Espindola ab5696ba82 Return ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235744
2015-04-24 18:51:30 +00:00
Rafael Espindola c1d535af05 Remove unused enum value. NFC.
llvm-svn: 235742
2015-04-24 18:36:57 +00:00
Rafael Espindola dedab912c3 Return an ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235741
2015-04-24 18:33:50 +00:00
Rafael Espindola c08ab8e6e4 Delete unnecessary generality in loadFile.
loadFile could load mulitple files just because yaml has a feature for
putting multiple documents in one file.

Designing a linker around what yaml can do seems like a bad idea to
me. This patch changes it to read a single file.

There are further improvements to be done to the api and they
will follow shortly.

llvm-svn: 235724
2015-04-24 15:51:45 +00:00
Rui Ueyama e75e50c045 Define make_dynamic_error_code(const char *).
The function took either StringRef or Twine. Since string literals are
ambiguous when resolving the overloading, many code calls used this
function with explicit type conversion. That led awkward code like
make_dynamic_error_code(Twine("Error occurred")).

This patch adds a function definition for string literals, so that
you can directly call the function with literals.

llvm-svn: 234841
2015-04-14 02:34:09 +00:00
Rui Ueyama aabd7ca452 Do s/_context/_ctx/g globally.
I believe this patch eliminates all remaining uses of _context
or _linkingContext variable names. Consistent naming improves
readability.

llvm-svn: 234645
2015-04-10 21:40:59 +00:00
Rui Ueyama aa7b304ea7 Remove the Native file format.
The Native file format was designed to be the fastest on-memory or
on-disk file format for object files. The problem is that no one
is working on that. No LLVM tools can produce object files in
the Native, thus the feature of supporting the format is useless
in the linker.

This patch removes the Native file support. We can add it back
if we really want it in future.

llvm-svn: 234641
2015-04-10 21:23:51 +00:00
Davide Italiano b63c9c32dc Reapply r234378, with test fixed (by emaste).
Hopefully this time the build won't be broken.

llvm-svn: 234553
2015-04-10 01:40:25 +00:00
Rui Ueyama de40bd4cf9 Rename atom_collection -> AtomVector.
Type names should start with an uppercase letter in the LLVM coding style.

llvm-svn: 234452
2015-04-08 23:05:59 +00:00
Rui Ueyama 1a6ec93616 Merge atom_collection_vector with atom_collection.
atom_collection_vector is the only derived class of atom_collection.
This patch merges the two.

llvm-svn: 234443
2015-04-08 21:59:04 +00:00
Rui Ueyama 2f05640409 Remove atom_collection_empty class.
llvm-svn: 234442
2015-04-08 21:59:00 +00:00
Rui Ueyama e3efa415de Revert "Allow undefined symbols in shared library by default."
This reverts commit r234378 because it broke buildbots.

llvm-svn: 234414
2015-04-08 16:55:03 +00:00
Davide Italiano 0e6a264673 Allow undefined symbols in shared library by default.
It's not our business to resolve those undefined symbols.
We just trust the linker will load the library and its dependencies
correctly, which is actually what happens, modulo bugs in the dynamic
linker itself.

PR:		23035
Differential Revision:	http://reviews.llvm.org/D8886

llvm-svn: 234378
2015-04-08 01:00:19 +00:00
Simon Atanasyan c437888f5a Replace the `createImplicitFiles` method return type with `void`
All instances of the `createImplicitFiles` always return `true` and this
return value is used nowhere.

llvm-svn: 234205
2015-04-06 20:43:35 +00:00
Rui Ueyama 230d2ec75f Remove return after report_fatal_error which has noreturn attribute.
llvm-svn: 234204
2015-04-06 20:25:18 +00:00
Rui Ueyama 55f5b2b277 Remove a parameter for file extension from canParse.
canParse took three parameters -- file magic, filename extension and
memory buffer. All but YAMLReader ignored the second parameter.
This patch removes the parameter.

llvm-svn: 234080
2015-04-04 02:44:36 +00:00
Rui Ueyama 24f2d2a9d5 Remove Makefiles.
Most developers prefer to not have them, and we agreed to
remove them from LLD.
http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-March/083368.html

llvm-svn: 233313
2015-03-26 20:09:47 +00:00
Rafael Auler ad11d4c196 [LinkerScript] Implement linker script expression evaluation
The expression evaluation is needed when interpreting linker scripts, in order
to calculate the value for new symbols or to determine a new position to load
sections in memory. This commit extends Expression nodes from the linker script
AST with evaluation functions, and also contains a unit test.

http://reviews.llvm.org/D8156

llvm-svn: 231707
2015-03-09 21:43:35 +00:00
Rui Ueyama 6a3167d35a Remove dead code.
llvm-svn: 231688
2015-03-09 18:59:55 +00:00
Rui Ueyama d18a97cb7a PECOFF: Create layout-afters instead of layout-befores.
All readers except PE/COFF reader create layout-after edges to preserve
the original symbol order. PE/COFF uses layout-before edges as primary
edges for no reason.

This patch makes PE/COFF reader to create layout-after edges.
Resolver is updated to recognize reverse edges of layout-after edges
in the garbage collection pass.

Now we can retire layout-before edges. I don't do that in this patch
because if I do, I would have updated many tests to replace all
occurrrences of "layout-before" with "layout-after". So that's a TODO.

llvm-svn: 231615
2015-03-09 00:06:07 +00:00
Rui Ueyama 803150c9d0 Revert r231552: Resolver: optimize fallback atoms.
This patch broke a buildbot.

llvm-svn: 231611
2015-03-08 21:31:38 +00:00
Rui Ueyama 0536677ad6 Remove sectionPosition attribute.
This code is simply dead. No one is using it.

http://reviews.llvm.org/D8125

llvm-svn: 231583
2015-03-08 01:01:40 +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 2039fc1f42 Resolver: move code inside an assert.
llvm-svn: 231518
2015-03-06 21:15:06 +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 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 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 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 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 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
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
Shankar Easwaran a1d3637f3d [Core,MachO,Test] Remove trailing whitespace.
llvm-svn: 230192
2015-02-22 23:54:38 +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
Davide Italiano 40680078e7 Style cleanup in compareByPosition().
Differential Revision:	D7394
Reported by:	ruiu
Reviewed by:	ruiu

llvm-svn: 228094
2015-02-04 00:44:52 +00:00
Davide Italiano 836a635764 Avoid two function calls of file() when not needed.
Reported by:	ruiu

llvm-svn: 228069
2015-02-03 23:44:33 +00:00
Davide Italiano df1b821b59 Remove trailing whitespace introduced in r227709.
Reported by:	shankarke

llvm-svn: 227710
2015-02-01 05:27:01 +00:00