Commit Graph

38 Commits

Author SHA1 Message Date
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 5768e9fde9 Test: Use layout-after instead of layout-before.
Update the tests so that they use layout-after instead of layout-before.
In all other places, we use layout-afters as primary edges.

llvm-svn: 231627
2015-03-09 04:00:29 +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
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 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
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
Shankar Easwaran d6f73ac366 [test] Add test for section groups and deadstrip
This adds a test that deadstrip should preserve the section group even if there
is only one reference to a function in the group.

llvm-svn: 227711
2015-02-01 05:47:02 +00:00
Rui Ueyama dd88e86b57 Remove kindInGroup reference.
That kind of reference was used only in ELFFile, and the use of
that reference there didn't seem to make sense. All test still
pass (after adjusting symbol names) without that code. LLD is
still be able to link LLD and Clang. Looks like we just don't
need this.

http://reviews.llvm.org/D7189

llvm-svn: 227259
2015-01-27 22:55:29 +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
Simon Atanasyan c77f5fa4f4 [ELF] Add CodeModel attribute to the DefinedAtom class
MIPS ELF symbols might contain some additional MIPS-specific flags
in the st_other field besides visibility ones. These flags indicate
code properties like microMIPS / MIPS16 encoding, position independent
code etc. We need to transfer the flags from input objects to the
output linked file to write them into the symbol table, adjust symbols
addresses etc.

I add new attribute CodeModel to the DefinedAtom class to hold target
specific flag and to get over YAML/Native format conversion barrier.
Other architectures/targets can extend CodeModel enumeration by their
own flags.

MIPS specific part of this patch adds support for STO_MIPS_MICROMIPS
flag. This flag marks microMIPS symbols. Such symbol should:
a) Has STO_MIPS_MICROMIPS in the corresponding .symtab record.
b) Has adjusted (odd) address in the corresponding .symtab
   and .dynsym records.

llvm-svn: 221864
2014-11-13 07:03:41 +00:00
Nick Kledzik 32d0d09bf8 Preserve custom section names when coalescing.
The mergeByContent attribute on DefinedAtoms triggers the symbol table to
coalesce atoms with the exact same content. The problem is that atoms can also
have a required custom section. The coalescing should never change the custom
section of an atom.

The fix is to only consider to atoms to have the same content if their
sectionChoice() and customSectionName() attributes match.

llvm-svn: 218893
2014-10-02 17:22:05 +00:00
Nick Kledzik 0edfdeb0be Move GOTPass and StubsPass from Core to MachO
llvm-svn: 212652
2014-07-09 21:04:24 +00:00
Rui Ueyama 61d7f97000 [PECOFF] Support COMDAT associative sections.
COFF supports a feature similar to ELF's section groups. This
patch implements it.

In ELF, section groups are identified by their names, and they are
treated somewhat differently from regular symbols. In COFF, the
feature is realized in a more straightforward way. A section can
have an annotation saying "if Nth section is linked, link this
section too."

I added a new reference type, kindAssociate. If a target atom is
coalesced away, the referring atom is removed by Resolver, so that
they are treated as a group.

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

llvm-svn: 211106
2014-06-17 16:19:33 +00:00
Rui Ueyama 9aee050a0c Remove group-parent references.
Previously section groups are doubly linked to their children.
That is, an atom representing a group has group-child references
to its group contents, and content atoms also have group-parent
references to the group atom. That relationship was invariant;
if X has a group-child edge to Y, Y must have a group-parent
edge to X.

However we were not using group-parent references at all. The
resolver only needs group-child edges.

This patch simplifies the section group by removing the unused
reverse edge. No functionality change intended.

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

llvm-svn: 210066
2014-06-03 03:07:49 +00:00
Rui Ueyama 23487e878b Make dead-striping to handle reverse edges.
Layout-before edges are no longer used for layout, but they are
still there for dead-stripping. If we would just remove them
from code, LLD would wrongly remove live atoms that were
referenced by layout-befores.

This patch fixes the issue. Before dead-stripping, it scans all
atoms to construct a reverse map for layout-after edges. Dead-
stripping pass uses the map to traverse the graph.

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

llvm-svn: 210057
2014-06-03 01:59:02 +00:00
Rui Ueyama 50c337a47c Remove trailing whitespaces.
llvm-svn: 208815
2014-05-14 21:49:38 +00:00
Shankar Easwaran 9316c40a1b [core] support .gnu.linkonce sections
.gnu.linkonce sections are similar to section groups.

They were supported before section groups existed and provided a way
to resolve COMDAT sections using a different design.

There are few implementations that use .gnu.linkonce sections
to store simple floating point constants which doesnot require complex section
group support but need a way to store only one copy of the floating point
constant in a binary.

.gnu.linkonce based symbol resolution achieves that.

Review : http://llvm-reviews.chandlerc.com/D3242

llvm-svn: 205280
2014-04-01 03:49:55 +00:00
Shankar Easwaran 50136f1f4e Revert "[core] support .gnu.linkonce sections"
This reverts commit 5d5ca72a7876c3dd3dd1db83dc6a0d74be9e2cd1.

Discuss on a better design to raise error when there is a similar group with Gnu
linkonce sections and COMDAT sections.

llvm-svn: 205224
2014-03-31 17:12:06 +00:00
Shankar Easwaran 79cfed55fc [core] support .gnu.linkonce sections
.gnu.linkonce sections are similar to section groups. They were supported before
section groups existed and provided a way to resolve COMDAT sections using a
different design. There are few implementations that use .gnu.linkonce sections
to store simple floating point constants which doesnot require complex section
group support but need a way to store only one copy of the floating point
constant. .gnu.linkonce based symbol resolution achieves that.

llvm-svn: 205163
2014-03-31 03:16:37 +00:00
Rui Ueyama 8be4ce254a Do not use layout-before to layout atoms.
Currently we use both layout-after and layout-before edges to specify atom
orders in the resulting executable. We have a complex piece of code in
LayoutPass.cpp to deal with both types of layout specifiers.

(In the following description, I denote "Atom A having a layout-after edge
to B" as "A -> B", and A's layout-before to B as "A => B".)

However, that complexity is not really needed for this reason: If there
are atoms such that A => B, B -> A is always satisifed, so using only layout-
after relationships will yield the same result as the current code.

Actually we have a piece of complex code that verifies that, for each A -> B,
B => [ X => Y => ... => Z => ] A is satsified, where X, Y, ... Z are all
zero-size atoms. We can get rid of the code from our codebase because layout-
before is basically redundant.

I think we can simplify the code for layout-after even more than this, but
I want to just remove this pass for now for simplicity.

Layout-before edges are still there for dead-stripping, so this change won't
break it. We will remove layout-before in a followup patch once we fix the
dead-stripping pass.

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

llvm-svn: 204966
2014-03-27 22:08:26 +00:00
Shankar Easwaran 7ac2a3df64 [core] add SectionGroup support
Review : http://llvm-reviews.chandlerc.com/D3182

llvm-svn: 204830
2014-03-26 16:37:13 +00:00
Nico Rieck b9d84f4d14 [lld] Include reference kind in cycle detector debug output
This restores the debug output to how it was before r197727 broke it. This
went undetected because the corresponding test was never run due to broken
feature detection.

llvm-svn: 202079
2014-02-24 21:14:37 +00:00
Nico Rieck 78f2b48e7d Fix feature detection in lld's lit.cfg
llvm-svn: 202078
2014-02-24 21:13:53 +00:00
Shankar Easwaran 3d8de47f76 Fix trailing whitespace.
llvm-svn: 200182
2014-01-27 03:09:26 +00:00
Nick Kledzik 6edd722a2c [mach-o] enable mach-o and native yaml to be intermixed
The main goal of this patch is to allow "mach-o encoded as yaml" and "native
encoded as yaml" documents to be intermixed.  They are distinguished via 
yaml tags at the start of the document.  This will enable all mach-o test cases
to be written using yaml instead of checking in object files.

The Registry was extend to allow yaml tag handlers to be registered.  The
mach-o Reader adds a yaml tag handler for the tag "!mach-o". 

Additionally, this patch fixes some buffer ownership issues.  When parsing
mach-o binaries, the mach-o atoms can have pointers back into the memory 
mapped .o file.  But with yaml encoded mach-o, name and content are ephemeral, 
so a copyRefs parameter was added to cause the mach-o atoms to make their
own copy.  

llvm-svn: 198986
2014-01-11 01:07:43 +00:00
Joey Gouly 72c5d3d7c1 REQUIRES: debug doesn't actually do anything!
Makes the tests pass (rather, not run) on release builds.

llvm-svn: 197838
2013-12-20 22:01:26 +00:00
Rui Ueyama 70f11d7589 Fix Weak External symbol handling.
The fallback atom was used only when it's searching for a symbol in a library;
if an undefined symbol was not found in a library, the LLD looked for its
fallback symbol in the library.

Although it worked in most cases, because symbols with fallbacks usually occur
only in OLDNAMES.LIB (a standard library), that behavior was incompatible with
link.exe. This patch fixes the issue so that the semantics is the same as
MSVC's link.exe

The new (and correct, I believe) behavior is this:

 - If there's no definition for an undefined atom, replace the undefined atom
   with its fallback and then proceed (e.g. look in the next file or stop
   linking as usual.)

Weak External symbols are underspecified in the Microsoft PE/COFF spec. However,
as long as I observed the behavior of link.exe, this seems to be what we want
for compatibility.

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

llvm-svn: 195269
2013-11-20 20:51:55 +00:00
Rui Ueyama b4dca7f065 Select new undefined atom rather than old one if other conditions are the same.
We can add multiple undefined atoms having the same name to the symbol table.
If such atoms are added, the symbol table compares their canBeNull attributes,
and select one having a stronger constraint. If their canBeNulls are the same,
the choice is arbitrary. Currently it choose the existing one.

This patch changes the preference, so that the symbol table choose the new one
if the new atom has a greater canBeNull or a fallback atom. This shouldn't
change the behavior except the case described below.

A new undefined atom may have a new fallback atom attribute. By choosing the new
atom, we can update the fallback atom during Core Linking. PE/COFF actually need
that. For example, _lseek is an alias for __lseek on Windows. One of an object
file in OLDNAMES.LIB has an undefined atom for _lseek with the fallback to
__lseek. When the linker tries to resolve _read, it supposed to read the file
from OLDNAMES.LIB and use the new fallback from the file. Currently LLD cannot
handle such case because duplicate undefined atoms with the same attributes are
ignored.

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

llvm-svn: 194777
2013-11-15 03:12:24 +00:00
Rui Ueyama 7eaa44c0bc Test: Move input redirections at the end of the line.
Writing arguments after the redirection of input ("< somefile") seems a bit
strange. Changes the order.

llvm-svn: 194727
2013-11-14 20:52:28 +00:00
Rui Ueyama 73ca00ca72 Test for r194671.
llvm-svn: 194723
2013-11-14 19:18:54 +00:00
Rui Ueyama 12f390856c Fix misleading indentation.
llvm-svn: 194550
2013-11-13 03:00:48 +00:00
Rui Ueyama 99d7013ef2 Run layout-transitivity test only when debugging is enabled.
Because it depends on "-mllvm -debug" flag, the test fails in Release build.

llvm-svn: 193271
2013-10-23 21:15:48 +00:00
Rui Ueyama c05fa0beab Disable layout-transitivity test on FreeBSD for now.
llvm-svn: 193259
2013-10-23 18:22:26 +00:00
Rui Ueyama 53e77efac3 Disable layout-transitivity test on Darwin for now.
llvm-svn: 193121
2013-10-21 22:19:27 +00:00
Rui Ueyama 46bf8286db Fix bug that CompareAtoms::compare is not transitive.
This patch fixes a bug in r190608. The results of a comparison function
passed to std::sort must be transitive, which is, if a < b and b < c, and if
a != b, a < c must be also true. CompareAtoms::compare did not actually
guarantee the transitivity. As a result the sort results were sometimes just
wrong.

Consider there are three atoms, X, Y, and Z, whose file ordinals are 1, 2, 3,
respectively. Z has a property "layout-after X". In this case, all the
following conditionals become true:

  X < Y because X's ordinal is less than Y's
  Y < Z because Y's ordinal is less than Z's
  Z < X because of the layout-after relationship

This is not of course transitive. The reason why this happened is because
we used follow-on relationships for comparison if two atoms falls in the same
follow-on chain, but we used each atom's properties if they did not. This patch
fixes the issue by using follow-on root atoms for comparison to get consistent
results.

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

llvm-svn: 193029
2013-10-19 03:18:18 +00:00
Michael J. Spencer 4355bb9d22 [Core] Add type and size to SharedLibraryAtom.
llvm-svn: 191466
2013-09-26 22:08:43 +00:00
Rui Ueyama e5416ec2d2 Add a fallback mechanism for undefined atom.
In COFF, an undefined symbol can have up to one alternative name. If a symbol
is resolved by its regular name, then it's linked normally. If a symbol is not
found in any input files, all references to the regular name are resolved using
the alternative name. If the alternative name is not found, it's a link error.
This mechanism is called "weak externals".

To support this mechanism, I added a new member function fallback() to undefined
atom. If an undefined atom has the second name, fallback() returns a new undefined
atom that should be used instead of the original one to resolve undefines. If it
does not have the second name, the function returns nullptr.

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

llvm-svn: 190625
2013-09-12 19:14:05 +00:00
Shankar Easwaran df4f12bb65 [lld][test] organize test directory. No change in functionality
* Renames few tests which had extension objtxt to test
* created core directory that contains all the core tests

llvm-svn: 189720
2013-08-31 05:59:52 +00:00