163 Commits

Author SHA1 Message Date
Mehdi Amini 6a4b837938 Prevent at compile time converting from Error::success() to Expected<T>
This would trigger an assertion at runtime otherwise.

Differential Revision: https://reviews.llvm.org/D26482

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@286562 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 04:29:25 +00:00
Rui Ueyama b6f84d2c36 Fix -Wpessimizing-move warnings.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@264951 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-30 22:40:16 +00:00
Pete Cooper ff00306e9e Convert file handle* methods to llvm::Error instead of std::error_code. NFC.
This updates most of the file handling methods in the linking context and
resolver to use the new API.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@264924 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-30 20:56:54 +00:00
Rui Ueyama 7964984860 Remove dead flags.
searchArchivesToOverrideTentativeDefinitions and
searchSharedLibrariesToOverrideTentativeDefinitions are always false.
For the dead flags, we have a fairly large amount of code which is
never be executed.

http://reviews.llvm.org/D17791

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@264653 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-28 20:59:47 +00:00
Pete Cooper 1eca6f241d Use owning pointers instead of raw pointers for Atom's to fix leaks.
This is a re-commit of r264022 with a fix for MSVC.  The issue there was
that the code was running DefinedAtom::~Atom() for some value and instead
needed to cast to Atom before running ~Atom.  Original commit message follows.

Currently each File contains an BumpPtrAllocator in which Atom's are
allocated.  Some Atom's contain data structures like std::vector which
leak as we don't run ~Atom when they are BumpPtrAllocate'd.

Now each File actually owns its Atom's using an OwningAtomPtr.  This
is analygous to std::unique_ptr and may be replaced by it if possible.

An Atom can therefore only be owned by a single File, so the Resolver now
moves them from one File to another.  The MachOLinkingContext owns the File's
and so clears all the Atom's in ~MachOLinkingContext, then delete's all the
File's.  This makes sure all Atom's have been destructed before any of the
BumpPtrAllocator's in which they run have gone away.

Should hopefully fix the remaining leaks.  Will keep an eye on the bots to
make sure.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@264067 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 17:15:50 +00:00
Pete Cooper 81a9e77e30 Revert "Use owning pointers instead of raw pointers for Atom's to fix leaks."
This reverts commit r264022.

This breaks the Window's bots which don't like that i'm calling ~Atom when
the this pointer is a sublcass of Atom.

Reverting for now until I try find a better fix.  I tried using std::unique_ptr with
a custom deleter as a quick fix, but it didn't work well in the YAML parser.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@264023 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 04:00:41 +00:00
Pete Cooper 0e55f8eae6 Use owning pointers instead of raw pointers for Atom's to fix leaks.
Currently each File contains an BumpPtrAllocator in which Atom's are
allocated.  Some Atom's contain data structures like std::vector which
leak as we don't run ~Atom when they are BumpPtrAllocate'd.

Now each File actually owns its Atom's using an OwningAtomPtr.  This
is analygous to std::unique_ptr and may be replaced by it if possible.

An Atom can therefore only be owned by a single File, so the Resolver now
moves them from one File to another.  The MachOLinkingContext owns the File's
and so clears all the Atom's in ~MachOLinkingContext, then delete's all the
File's.  This makes sure all Atom's have been destructed before any of the
BumpPtrAllocator's in which they run have gone away.

Should hopefully fix the remaining leaks.  Will keep an eye on the bots to
make sure.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@264022 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 03:44:32 +00:00
Rui Ueyama 6108987f1a Remove more dead code.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@262443 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-02 01:23:29 +00:00
Rui Ueyama 826cefae1a Remove dead code for ELF.
The preload feature was buggy that we had disabled it even for ELF.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@262194 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-28 21:22:44 +00:00
Rafael Espindola 50f9db6ab6 Delete more COFF and ELF bits from the old linker.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@262184 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-28 16:27:08 +00:00
Rafael Espindola da338b7d42 Delete more ELF bits from the old linker.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@262181 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-28 16:03:37 +00:00
Rafael Espindola a1abc14e43 Remove a few bits of elf from the old linker.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@262164 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-28 02:22:24 +00:00
Pete Cooper f2f087accf Fix handling of mach header and DSO handle symbols.
The magic file which contained these symbols inherited from archive
which meant that the resolver didn't add the required atoms as archive
members only get added when referenced.  Instead we now inherit from
SimpleFile which always links in the atoms needed.

The second issue was in the handling of these symbols when we emit
the MachO.  The mach header symbol needs to be in the atom list as
it gets an offset (0), and being in the atom list makes sure it is
emitted to the symbol table.  DSO handles are not emitted to the
symbol table.

rdar://problem/24450654

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@259574 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-02 21:37:15 +00:00
Pete Cooper bd281ef5dc Add File::kind's for all subclasses of File.
This is to enable isa<> support for any files which need it.

It will be used in an upcoming patch to differentiate MachOFile from other implicitly generated files.

Reviewed by Lang Hames.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@257830 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-14 22:55:38 +00:00
Pete Cooper fe749deaae Add handleLoadedFile hook to the context.
This is called from the resolver on each file we decide we actually want to use.

Future commits will make use of this to extract useful information from the files and do
error checking against the context.  For example, ensure that files are the same arch as
each other.

Reviewed by Lang Hames.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@257814 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-14 21:53:13 +00:00
Pete Cooper ee3aa884cc Add more debugging output to MachO lld. NFC.
In debug builds there's now a dump method on Section and improved
printing of atoms.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@255826 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-16 22:03:21 +00:00
Pete Cooper 07e6fb6b1b Added some DEBUG() prints to make it clearer what the mach-o passes are doing. NFC.
We had some DEBUG prints these passes, but add more so that its clear where we are dumping
things, and what state we are in when we do so.

I'll be adding more and more DEBUG printing to try make it easier to observe whats going on
without having to attach a debugger.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@255805 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-16 19:12:49 +00:00
Rui Ueyama 37874d515c Remove return after report_fatal_error which has noreturn attribute.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@234204 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-06 20:25:18 +00:00
Rui Ueyama 6b3b63e01d 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231615 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-09 00:06:07 +00:00
Rui Ueyama c58cd960eb Revert r231552: Resolver: optimize fallback atoms.
This patch broke a buildbot.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231611 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-08 21:31:38 +00:00
Rui Ueyama 0fd97454ca Remove sectionPosition attribute.
This code is simply dead. No one is using it.

http://reviews.llvm.org/D8125

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231583 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-08 01:01:40 +00:00
Rui Ueyama 3580a67e66 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231552 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-07 04:23:46 +00:00
Rui Ueyama b210d93ea4 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231551 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-07 03:55:32 +00:00
Rui Ueyama eeed1f0c85 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231549 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-07 03:22:37 +00:00
Rui Ueyama ba86701dee Resolver: move code inside an assert.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@231518 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-06 21:15:06 +00:00