Commit Graph

60 Commits

Author SHA1 Message Date
Greg Fitzgerald 4b6a7e355b Fix five of the shared library build targets
Before this patch there was a cyclic dependency between lldCore and
lldReaderWriter.  Only lldConfig could be built as a shared library.

* Moved Reader and Writer base classes into lldCore.
* The following shared libraries can now be built:
     lldCore
     lldYAML
     lldNative
     lldPasses
     lldReaderWriter

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

From: Greg Fitzgerald <garious@gmail.com>
llvm-svn: 226732
2015-01-21 22:54:56 +00:00
Rui Ueyama d4730ea555 Run the resolver in parallel with the reader.
This patch makes File::parse() multi-thread safe. If one thread is running
File::parse(), other threads will block if they try to call the same method.
File::parse() is idempotent, so you can safely call  multiple times.

With this change, we don't have to wait for all worker threads to finish
in Driver::link(). Previously, Driver::link() calls TaskGroup::sync() to
wait for all threads running File::parse(). This was not ideal because
we couldn't start the resolver until we parse all files.

This patch increase parallelism by making Driver::link() to not wait for
worker threads. The resolver calls parse() to make sure that the file
being read has been parsed, and then uses the file. In this approach,
the resolver can run with the parser threads in parallel.

http://reviews.llvm.org/D6994

llvm-svn: 226281
2015-01-16 15:54:13 +00:00
Rui Ueyama 883afba228 Remove InputGraph and use std::vector<Node> instead.
In total we have removed more than 1000 lines!

llvm-svn: 226149
2015-01-15 08:46:36 +00:00
Rui Ueyama 61635440a9 Rename InputElement Node.
InputElement was named that because it's an element of an InputGraph.
It's losing the origin because the InputGraph is now being removed.
InputElement's subclass is FileNode, that naming inconsistency needed
to be fixed.

llvm-svn: 226147
2015-01-15 08:31:46 +00:00
Rui Ueyama 861c2d6c3a Remove InputGraph::addInputElement{,Front}.
They were the last member functions of InputGraph (besides members()).
Now InputGraph is just a container of a vector. We are ready to replace
InputGraph with plain File vector.

llvm-svn: 226146
2015-01-15 08:18:14 +00:00
Rui Ueyama 423177a54b Remove WrapperNode.
WrapperNode was a useless subclass of FileNode. We should just use
FileNode instead.

llvm-svn: 226145
2015-01-15 08:10:10 +00:00
Rui Ueyama df3fca2520 Remove FileNode::parse.
FileNode::parse was just a forwarder to File::parse so we could remove that.
Also removed dead code.

llvm-svn: 226144
2015-01-15 07:56:14 +00:00
Rui Ueyama cdb1071be5 Remove InputGraph::size().
llvm-svn: 226140
2015-01-15 07:20:39 +00:00
Rui Ueyama 56206368f5 Simplify FileNode.
The member function was defined to allow subclasses to customize
error message. But since we only have one FileNode type, there's
no actual need for that.

llvm-svn: 226139
2015-01-15 07:15:36 +00:00
Rui Ueyama 8054342f9e Merge SimpleFileNode with WrapperNode.
llvm-svn: 226137
2015-01-15 07:05:46 +00:00
Rui Ueyama 80c04431ca Re-commit r225766, r225767, r225769, r225814, r225816, r225829, and r225832.
These changes depended on r225674 and had been rolled back in r225859.
Because r225674 has been re-submitted, it's safe to re-submit them.

llvm-svn: 226132
2015-01-15 06:49:21 +00:00
Rui Ueyama df230b21e3 Re-commit r225674: Convert other drivers to use WrapperNode.
The original commit had an issue with Mac OS dylib files. It didn't
handle fat binary dylib files correctly. This patch includes a fix.
A test for that case has already been committed in r225764.

llvm-svn: 226123
2015-01-15 04:34:31 +00:00
Rui Ueyama cfb2534ef8 Revert "Convert other drivers to use WrapperNode" and subsequent commits.
r225764 broke a basic functionality on Mac OS. This change reverts
r225764, r225766, r225767, r225769, r225814, r225816, r225829, and r225832.

llvm-svn: 225859
2015-01-14 00:21:34 +00:00
Rui Ueyama d5bb5c2bfe Remove dead code.
Now every InputElement has exactly one File in it, so "expand"
method is now no-op.

llvm-svn: 225769
2015-01-13 05:59:17 +00:00
Rui Ueyama e8ecb2b144 Convert other drivers to use WrapperNode.
llvm-svn: 225764
2015-01-13 04:33:07 +00:00
Rui Ueyama a5f2816b1c Convert CoreInputGraph.
This is a part of InputGraph cleanup to represent input files as a flat
list of Files (and some meta-nodes for group etc.)

We cannot achieve that goal in one gigantic patch, so I split the task
into small steps as shown below.

(Recap the progress so far: Currently InputGraph contains a list of
InputElements. Each InputElement contain one File (that used to have
multiple Files, but I eliminated that use case in r223867). Files are
currently instantiated in Driver::link(), but I already made a change
to separate file parsing from object instantiation (r224102), so we
can safely instantiate Files when we need them, instead of wrapping
a file with the wrapper class (FileNode class). InputGraph used to
act like a generator class by interpreting groups by itself, but it's
now just a container of a list of InputElements (r223867).)

1. Instantiate Files in the driver and wrap them with WrapperNode.
WrapperNode is a temporary class that allows us to instantiate Files
in the driver while keep using the current InputGraph data structure.

This patch demonstrates how this step 1 looks like, using Core driver
as an example.

2. Do the same thing for the other drivers.

When step 2 is done, an InputGraph consists of GroupEnd objects or
WrapperNodes each of which contains one File. Other types of
FileNode subclasses are removed.

3. Replace InputGraph with std::vector<std::unique_ptr<InputElement>>.
InputGraph is already just a container of list of InputElements,
so this step removes that needless class.

4. Remove WrapperNode.

We need some code cleanup between each step, because many classes
do a bit odd things (e.g. InputGraph::getGroupSize()). I'll straight
things up as I need to.

llvm-svn: 225313
2015-01-06 23:06:49 +00:00
Rui Ueyama 00eb257f2e Re-commit r223330: Rewrite InputGraph's Group
llvm-svn: 223867
2014-12-10 00:33:00 +00:00
Rui Ueyama 5ae2050420 Revert "Rewrite InputGraph's Group"
This reverts commit r223330 because it broke Darwin and ELF
linkers in a way that we couldn't have caught with the existing
test cases.

llvm-svn: 223373
2014-12-04 18:29:03 +00:00
Rui Ueyama 60df72ff61 Rewrite InputGraph's Group
The aim of this patch is to reduce the excessive abstraction from
the InputGraph. We found that even a simple thing, such as sorting
input files (Mach-O) or adding a new file to the input file list
(PE/COFF), is nearly impossible with the InputGraph abstraction,
because it hides too much information behind it. As a result,
we invented complex interactions between components (e.g.
notifyProgress() mechanism) and tricky code to work around that
limitation. There were many occasions that we needed to write
awkward code.

This patch is a first step to make it cleaner. As a first step,
this removes Group class from the InputGraph. The grouping feature
is now directly handled by the Resolver. notifyProgress is removed
since we no longer need that. I could have cleaned it up even more,
but in order to keep the patch minimum, I focused on Group.

SimpleFileNode class, a container of File objects, is now limited
to have only one File. We shold have done this earlier.
We used to allow putting multiple File objects to FileNode.
Although SimpleFileNode usually has only one file, the Driver class
actually used that capability. I modified the Driver class a bit,
so that one FileNode is created for each input File.

We should now probably remove SimpleFileNode and directly store
File objects to the InputGraph in some way, because a container
that can contain only one object is useless. This is a TODO.

Mach-O input files are now sorted before they are passe to the
Resolver. DarwinInputGraph class is no longer needed, so removed.

PECOFF still has hacky code to add a new file to the input file list.
This will be cleaned up in another patch.

llvm-svn: 223330
2014-12-04 01:09:06 +00:00
Shankar Easwaran 2895527ec2 [Core] Add flag to check if RoundTripPasses need to be run.
This would allow other flavor specific contexts to override the default value,
if they want to optionally run the round trip passes.

There is some information lost like the original file owner of the atom with
RoundTripPasses. The Gnu flavor needs this information inorder to implement
LinkerScript matching and for other diagnostic outputs such as Map files.

The flag also can be used to record information in the Atom if the information
to the Writer needs to be conveyed through References too.

llvm-svn: 222983
2014-12-01 01:04:11 +00:00
Shankar Easwaran 2b67fca033 Sort include files according to convention.
llvm-svn: 220131
2014-10-18 05:33:55 +00:00
Rui Ueyama abea8fa61d Change the signature of insertElementAt and rename addInputElementFront
insertElementAt(x, END) does the identical thing as addInputElement(x),
so the only reasonable use of insertElementAt is to call it with the
other possible argument, BEGIN. That means the second parameter of the
function is just redundant. This patch is to remove the second
parameter and rename the function accordingly.

llvm-svn: 213821
2014-07-24 00:08:22 +00:00
Rafael Espindola b1a4d3a26c Don't import error_code into the lld namespace.
llvm-svn: 210785
2014-06-12 14:53:47 +00:00
Rui Ueyama b13cda8f3e Call normalize() in the common driver.
Previously only GNU driver calls InputGraph::normalize, but its
functionality is not and should not be limited to GNU ld. Other
driver should be able to use it.

Currently only linker scripts use the feature, so this change
won't change the existing behavior.

llvm-svn: 208266
2014-05-07 23:33:48 +00:00
Simon Atanasyan a64f34b759 [Driver] Check type of InputElement before request a error message. If the
element is a FileNode, request error description. If the element is Group,
print hard coded error message. We need to implement a better diagnostics
here but even current solution is better than a segmentation fault output.

llvm-svn: 207691
2014-04-30 19:04:01 +00:00
Rui Ueyama 8bd093b1e5 Rename getInputGraph() and getNextFile().
Seems getSomething() is more common naming scheme than just a noun
to get something, so renaming these members.

Differential Revision: http://llvm-reviews.chandlerc.com/D3285

llvm-svn: 205589
2014-04-04 00:14:04 +00:00
Rui Ueyama 69fcde8b0a Expand 'auto' that's hard for human to deduce its real type.
llvm-svn: 205564
2014-04-03 20:47:50 +00:00
Rui Ueyama b0e3b66fa5 Remove ordinals from Input Graph elements.
An ordinal is set to each child of Input Graph, but no one actually
uses it. The only piece of code that gets ordinaly values is
sortInputElements in InputGraph.cpp, but it does not actually do
anything -- we assign ordinals in increasing order just before
calling sort, so when sort is called it's already sorted. It's no-op.
We can simply remove it. No functionality change.

Differential Revision: http://llvm-reviews.chandlerc.com/D3270

llvm-svn: 205501
2014-04-03 02:21:44 +00:00
Rui Ueyama ce749af25b Rename insertOneElementAt -> insertElementAt.
insertElementsAt() is removed, so "One" in insertOneElementAt() no longer
make much sense. Rename it for brevity.

llvm-svn: 205372
2014-04-01 23:17:28 +00:00
Rui Ueyama 5632e26d36 Greatly simplify InputGraph.
InputGraph has too many knobs and controls that are not being used. This
patch is to remove dead code, unused features and a class. There are two
things that worth noting, besides simple dead code removal:

1. ControlNode class is removed. We had it as the base class of Group
class, but it provides no functionality particularly meaningful. We now
have shallower class hierarchy that is easier to understand.

2. InputGraph provides a feature to replace a node with its internal data.
It is being used to "expand" some type of node, such as a Linker Script
node, with its actual files. We used to have two options when replacing
it -- ExpandOnly or ExpandAndReplace. ExpandOnly was to expand it but not
remove the node from the tree. There is no use of that option in the code,
so it was a dead feature.

Differential Revision: http://llvm-reviews.chandlerc.com/D3252

llvm-svn: 205363
2014-04-01 21:55:36 +00:00
Rui Ueyama bc6b52e68e Move RoundTrip tests behind LLVM_RUN_ROUNDTRIP_TEST env flag.
If the environment variable is defined and not empty, RoundTrip tests
are run. The reason to move the tests behind the flag is because they
are too slow to enable by default.

LLD linking time on llvm-tblgen improved from 2m7s to 2.3s. About 60x
faster now in this case.

Differential Revision: http://llvm-reviews.chandlerc.com/D3126

llvm-svn: 204296
2014-03-20 02:49:33 +00:00
Joey Gouly 6eb02ef568 Make SimpleFileNode inherit from FileNode.
This removes a lot of duplicated code.

llvm-svn: 197751
2013-12-19 23:39:02 +00:00
Shankar Easwaran 67e98f5197 [InputGraph] Add capability to process Hidden nodes.
Hidden nodes could be a result of expansion, where a flavor might decide to keep
the node that we want to expand but discard it from being processed by the
resolver.

Verifies with unittests.

llvm-svn: 195516
2013-11-22 23:19:53 +00:00
Rui Ueyama c1800beb55 Remove unnecessary namespace qualifier.
llvm-svn: 194037
2013-11-05 01:37:40 +00:00
Rui Ueyama aa5b4dc868 Remove duplicate calls of pm.add() for RoundTrip tests.
llvm-svn: 193885
2013-11-01 21:05:42 +00:00
Shankar Easwaran 2bc24928d3 [PassManager] add ReaderWriter{Native,YAML} to the Driver.
Enable this for the following flavors

a) core
b) gnu
c) darwin

Its disabled for the flavor PECOFF. Convenient markers are added with FIXME
comments in the Driver that would be removed and code removed from each flavor.

llvm-svn: 193585
2013-10-29 05:12:14 +00:00
Rui Ueyama 671c8013ed Revert "r193300 - [PassManager] add ReaderWriter{Native, YAML} to the Driver"
The patch have completely broken COFF port and disabled many tests.
This also reverts r193302 (comment fix).

llvm-svn: 193362
2013-10-24 18:22:16 +00:00
Shankar Easwaran 89c2d8faca [PassManager] add ReaderWriter{Native,YAML} to the Driver.
Disable tests to be run with REQUIRES: disable. Note disable is not added to the
config by the test runner Mkaefiles, so essentially disables the test.

Code changes would be required to fix these tests :-

test/darwin/hello-world.objtxt
test/elf/check.test
test/elf/phdr.test
test/elf/ppc.test
test/elf/undef-from-main-dso.test
test/elf/X86_64/note-sections-ro_plus_rw.test
test/pecoff/alignment.test
test/pecoff/base-reloc.test
test/pecoff/bss-section.test
test/pecoff/drectve.test
test/pecoff/dynamic.test
test/pecoff/dynamicbase.test
test/pecoff/entry.test
test/pecoff/hello.test
test/pecoff/imagebase.test
test/pecoff/importlib.test
test/pecoff/lib.test
test/pecoff/multi.test
test/pecoff/reloc.test
test/pecoff/weak-external.test

llvm-svn: 193300
2013-10-24 03:30:03 +00:00
Shankar Easwaran 2595e71849 [cleanup] Remove single-statement if blocks
llvm-svn: 192614
2013-10-14 19:58:12 +00:00
Rui Ueyama a1490d616f Prune unused local variable.
llvm-svn: 192509
2013-10-11 22:02:58 +00:00
Rui Ueyama f1e266846d Remove excessive allowRemainingUndefines() check.
allowRemainingUndefines() is already checked in Resolver::resolve(), so we
don't need to check it again after returning from it. It's actually not only
superfluous but buggy because a failure of resolve() does not always mean that
there is a remaining undefines.

llvm-svn: 192423
2013-10-11 06:16:35 +00:00
Rui Ueyama ee366042e9 Return true from Resolver::resolve() on success.
llvm-svn: 192422
2013-10-11 06:16:33 +00:00
Shankar Easwaran 1d3c48f1fc [Layout] Assign ordinals in Resolution order.
llvm-svn: 192277
2013-10-09 05:23:23 +00:00
Rui Ueyama 74cc8e1e80 Fix flaky elf/X86_64/dynlib-search.test.
Output to llvm::err() is not guaranteed to be thread-safe, so it needs
to be guarded with a lock.

Differential Revision: http://llvm-reviews.chandlerc.com/D1862

llvm-svn: 192250
2013-10-08 23:01:52 +00:00
Shankar Easwaran 7f1146c494 [LinkingContext] make LinkingContext non-const
llvm-svn: 192183
2013-10-08 15:43:48 +00:00
Shankar Easwaran a96f3a3da4 [lld][InputGraph] Change the Resolver to use inputGraph
Changes :-

a) Functionality in InputGraph to insert Input elements at any position
b) Functionality in the Resolver to use nextFile
c) Move the functionality of assigning file ordinals to InputGraph
d) Changes all inputs to MemoryBuffers
e) Remove LinkerInput, InputFiles, ReaderArchive

llvm-svn: 192081
2013-10-07 02:47:09 +00:00
Rui Ueyama 8db1eddc07 Make Driver::link and LinkingContext::validate return true on success.
This patch inverts the return value of these functions, so that they return
"true" on success and "false" on failure. The meaning of boolean return value
was mixed in LLD; for example, InputGraph::validate() returns true on success.
With this patch they'll become consistent.

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1748

llvm-svn: 191341
2013-09-24 23:26:34 +00:00
Joerg Sonnenberger 5e235de9d3 Change the parseFile argument from MemoryBuffer pointer to LinkerInput
reference. Move readFile logic into FileNode::createLinkerInput.

llvm-svn: 190253
2013-09-07 17:55:28 +00:00
Shankar Easwaran 2eaa47a008 [lld][Driver] remove return after llvm_unreachable
llvm-svn: 189891
2013-09-04 00:05:46 +00:00
Shankar Easwaran 3df170b84e [lld][Driver] The driver was creating linker inputs twice
Also add a llvm_unreachable call so that the linker will trip on unhandled
inputElement types.

llvm-svn: 189887
2013-09-03 23:52:05 +00:00