Commit Graph

2140 Commits

Author SHA1 Message Date
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
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
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
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 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