Commit Graph

2924 Commits

Author SHA1 Message Date
Benjamin Kramer bd521201b7 Apply clang-tidy's misc-move-constructor-init to lld.
No functionality change intended.

llvm-svn: 271686
2016-06-03 16:57:13 +00:00
Eugene Zelenko 20a38451f5 Fix some Include What You Use warnings; other minor fixes.
Differential revision: http://reviews.llvm.org/D19735

llvm-svn: 268093
2016-04-29 19:47:09 +00:00
Eugene Zelenko a7a55c4d27 Fix builds broken in r267008.
llvm-svn: 267010
2016-04-21 17:27:04 +00:00
Eugene Zelenko 1a299eab32 Fix Clang-tidy misc-unused-using-decls and Include What You Use warnings.
Differential revision: http://reviews.llvm.org/D19348

llvm-svn: 267008
2016-04-21 17:14:10 +00:00
Mehdi Amini de3f7678d1 Add missing header (NFC)
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266597
2016-04-18 09:33:41 +00:00
Mehdi Amini 0bc6b2b5a0 Add missing header (NFC)
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266596
2016-04-18 09:26:29 +00:00
Lang Hames 33fd854584 [lld][MachO] Clean up some unnecessarily verbose code. NFC.
Suggested by Dave Blaikie in review of r265447. Thanks Dave!

llvm-svn: 265566
2016-04-06 17:18:55 +00:00
Lang Hames 24f5a3eb03 [lld][MachO] Check Expected<T> for error prior to destruction.
This should fix the failures on the LLD bots caused by r265446.

llvm-svn: 265477
2016-04-05 22:06:48 +00:00
Pete Cooper f4d7688e4b Revert "Remove useless unreachable. Switch coverage already gives us this. NFC"
This reverts commit r264945.

The commit only removed an unreachable in a method with a covered switch, but
GCC is likely to warn on this, and the coding standards recommend just leaving
in the unreachable.

llvm-svn: 264983
2016-03-31 01:23:23 +00:00
Pete Cooper eadf9e4ec9 Remove unused variants of make_dynamic_error_code. NFC.
make_dynamic_error_code was used to create a std::error_code with
a std::string message.  Now that we are migrating to llvm::Error,
there are no calls to these make_dynamic_error_code methods.

There is one single call to make_dynamic_error_code remaining, the one
inside GenericError::convertToErrorCode().  That method is only called
from File::doParse() which should be a temporary situation.  We need
to work out how to deal with File::parse() caching the error result from
doParse().  Caching errors isn't supported in the new scheme, and probably
isn't needed here, but we need to work that out.

Once thats done, dynamic error and all utilities around it can be deleted.

llvm-svn: 264982
2016-03-31 01:21:50 +00:00
Pete Cooper 2f6216c181 Use Expected<T> instead of ErrorOr<T>in yaml reader. NFC
llvm-svn: 264981
2016-03-31 01:13:04 +00:00
Pete Cooper d0a643e7dc Change library search methods to return Optional instead of ErrorOr.
These methods weren't really throwing errors.  The only error used
was that a file could not be found, which isn't really an error at all
as we are searching paths and libraries for a file.  All of the callers
also ignored errors and just used the returned path if one was available.

Changing to return Optional<StringRef> as that actually reflects what
we are trying to do here: optionally find a given path.

llvm-svn: 264979
2016-03-31 01:09:35 +00:00
Pete Cooper dc59c794d0 Fix a bunch more of -Wpessimizing-move issues.
Thanks to Rui for pointing out this warning was firing.

llvm-svn: 264978
2016-03-31 00:38:02 +00:00
Pete Cooper e487da165c Fix a bunch of -Wpessimizing-move issues.
Thanks to Rui for pointing out this warning was firing.

llvm-svn: 264977
2016-03-31 00:35:50 +00:00
Pete Cooper 514594bdd3 Convert a few macho reader/writer helpers to new error handling. NFC.
These methods were responsible for some of the few remaining calls
to llvm::errorCodeToError.  Converting them makes us have more Error's
in the api and fewer error_code's.

llvm-svn: 264974
2016-03-31 00:08:16 +00:00
Pete Cooper c6e7b8146a Convert readBinary to llvm::Error. NFC
llvm-svn: 264973
2016-03-30 23:58:24 +00:00
Pete Cooper ec4e166a5a Convert normalized file to atoms methods to new error handling. NFC.
This converts almost all of the error handling in atom creation
to llvm::Error instead of std::error_code.

llvm-svn: 264968
2016-03-30 23:43:27 +00:00
Pete Cooper fefbd22814 Convert lld file writing to llvm::Error. NFC.
This converts the writeFile method, as well as some of the ones it calls
in the normalized binary file writer and yaml writer.

llvm-svn: 264961
2016-03-30 23:10:39 +00:00
Rui Ueyama 1e0f022f05 Fix -Wpessimizing-move warnings.
llvm-svn: 264951
2016-03-30 22:40:16 +00:00
Pete Cooper 63d1aba2ce Remove useless unreachable. Switch coverage already gives us this. NFC
llvm-svn: 264945
2016-03-30 22:34:37 +00:00
Pete Cooper 3c40b5b750 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.

llvm-svn: 264924
2016-03-30 20:56:54 +00:00
Pete Cooper 96be123198 Change loadFileList to llvm::Error. NFC
llvm-svn: 264921
2016-03-30 20:44:14 +00:00
Pete Cooper c73c9d273d Convert lld Pass::runOnFile to llvm::Error from std::error_code. NFC.
Pretty mechanical change here.  Just replacing all the std::error_code() with
llvm::Error() and make_dynamic_error_code with make_error<GenericError>

llvm-svn: 264917
2016-03-30 20:36:31 +00:00
Pete Cooper 1e00911ee0 Change getReferenceInfo/getPairReferenceInfo to use new Error handling. NFC.
Adds a GenericError class to lld/Core which can carry a string.  This is
analygous to the dynamic_error we currently use in lld/Core.

Use this GenericError instead of make_dynamic_error_code.  Also, provide
an implemention of GenericError::convertToErrorCode which for now converts
it in to the dynamic_error_code we used to have.  This will go away once
all the APIs are converted.

llvm-svn: 264910
2016-03-30 20:15:06 +00:00
Rui Ueyama 46a8e29587 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

llvm-svn: 264653
2016-03-28 20:59:47 +00:00
Pete Cooper 107ac9e1aa Use None to construct an empty ArrayRef. NFC.
Suggested by David Blaikie in response to r264234.

llvm-svn: 264311
2016-03-24 17:39:34 +00:00
Pete Cooper b29ecbd4e9 Avoid UB when creating empty atoms. NFC.
The stack-size.yaml test had an empty atom content array.  This is
legal, but asking a BumpPtrAllocator for 0 sized data may not be
legal.  Instead just avoid requesting any data when we can just return
an empty ArrayRef instead.

llvm-svn: 264234
2016-03-24 01:16:06 +00:00
Pete Cooper 07134ae364 Avoid UB deref of nullptr to reference. NFC.
Its possible for file to have no entry atom which means that there
is no atom to check for being a thumb function.  Instead just skip
the thumb check and set the entry address to 0, which matches the
current behaviour of getting a default initialised int from a map.

llvm-svn: 264233
2016-03-24 01:14:10 +00:00
Pete Cooper 07601d33f8 Use a memcpy to avoid unaligned store UB.
On a 32-bit output, we may write LC_MAIN (which contains a uint64_t) to
an unaligned address.  This changes it to use a memcpy instead which is UB safe.

llvm-svn: 264232
2016-03-24 01:05:17 +00:00
Pete Cooper a13f62f5f8 Use unaligned read to fix UB. NFC.
We were casting a potentially unaligned pointer to uint32_t and
dereferencing.  As the pointer ultimately comes from the object file,
there's no way to guarantee alignment, so use the little32_t read instead.

Also, little32_t knows about endianness, so in theory this may have broken on
big endian machines.

llvm-svn: 264231
2016-03-24 01:03:44 +00:00
Pete Cooper 3f564a52d0 Parsed alignment should be a power of 2.
The .o path always makes sure to store a power of 2 value in the
Section alignment.  However, the YAML code didn't verify this.

Added verification and updated all the tests which had a 3 but meant
to have 2^3.

llvm-svn: 264228
2016-03-24 00:36:37 +00:00
Pete Cooper 47e5399cd3 Fix more cases of UB from allocating 0 sized data. NFC.
The size of a section can be zero, even when it contains atoms, so
long as all of the atoms are also size 0.  In this case we were
allocating space for a 0 sized buffer.

Changed this to only allocate when we need the space, but also cleaned
up all the code to use MutableArrayRef instead of uint8_t* so its much much
safer as we get bounds checking on all of our section creation logic.

llvm-svn: 264204
2016-03-23 22:19:16 +00:00
Pete Cooper b565bdfb6e Use a memcpy to avoid unaligned store UB.
On a 32-bit output, we may write LC_SOURCE_VERSION (which contains a uint64_t) to
an unaligned address.  This changes it to use a memcpy instead which is UB safe.

llvm-svn: 264202
2016-03-23 22:00:09 +00:00
Kevin Enderby 2112b2c07d Add the needed lld change for r264187 in llvm.
Sorry had this fixed in my check out but failed mention it in my
commit message for r264187.

llvm-svn: 264188
2016-03-23 20:37:23 +00:00
Pete Cooper e82f3a099f Copy MachO struct to temporary to avoid unaligned load UB.
We were already copying this data to a temporary for endian swaps.  Now
we just always copy it, but still only do the endian swaps when needed.

llvm-svn: 264172
2016-03-23 18:00:10 +00:00
Pete Cooper 10bf15ee8e Move empty atom check to target independent code. NFC.
Turns out that checking only x86 for empty atoms to fix UBSan then
requires the same code in the other targets too.  Better to just
check this in the main run loop instead of in each target.

Should be NFC, other than fixing UBSan failures.

llvm-svn: 264116
2016-03-22 23:07:34 +00:00
Pete Cooper b9a9d7163f Avoid memcpy from nullptr. NFC.
This was caught by the UBSan bot.  When the atom has no size, we would
issue a memcpy with size0 and a nullptr for the source.

Also, this code should never have references inside an empty atom so
add an assert for that while we're here.

llvm-svn: 264115
2016-03-22 22:59:35 +00:00
Pete Cooper 8e1b9a17a6 Don't memcpy from a null source. Found by UBSan
llvm-svn: 264114
2016-03-22 22:51:03 +00:00
Pete Cooper 1edff82f82 More MSVC bot appeasement. Explicitly define rvalue methods on SortKey.
OwningAtomPtr does not have OwningAtomPtr(OwningAtomPtr&) or the equivalent
operator= as we only want to use rvalue references in it.

SortKey didn't like this on MSVC as it was synthesizing SortKey(SortKey&) and
trying to use the OwningAtomPtr(OwningAtomPtr&) method which was private an
unimplemented.

Now we explicitly have the methods on SortKey so hopefully the bot will be
happier.

llvm-svn: 264077
2016-03-22 18:09:55 +00:00
Pete Cooper 8ad55fb2d0 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.

llvm-svn: 264067
2016-03-22 17:15:50 +00:00
Mehdi Amini d595b08998 DenseMap resize() is now named reserved(), adapt the call sites
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264028
2016-03-22 07:31:35 +00:00
Pete Cooper 3e4d732dd0 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.

llvm-svn: 264023
2016-03-22 04:00:41 +00:00
Pete Cooper 572a87e2aa 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.

llvm-svn: 264022
2016-03-22 03:44:32 +00:00
Pete Cooper c0c464cac1 Move ownership of Pass File's to the MachoLinkingContext.
In trying to fix the leaks in the MachO lld codebase, we need to have
a better model for file and atom ownership.  Having the context own
everything seems like the simplest model, so change all the passes to
allocate File's on the context instead of owning files as a member.

llvm-svn: 264004
2016-03-21 23:17:47 +00:00
Pete Cooper 590872b0c2 Always pass an allocator to YAMLTraits.
The YAML traits new's when not passed an allocator to parse data.
For atom types, this is a leak as we don't destruct atoms.  For
the File here, we do actually destruct File's so that single case of
not using an allocator will be fine.

Should fix a bunch more leaks.

llvm-svn: 263680
2016-03-17 00:33:58 +00:00
Pete Cooper 31275a1413 Use allocator in YAML code to avoid leaking atom content.
In lld we allocate atoms on an allocator and so don't run their
destructors.  This means we also shouldn't allocate memory inside
them without that also being on an allocator.

Reviewed by Lang Hames and Rafael Espindola.

llvm-svn: 263677
2016-03-16 23:30:27 +00:00
Pete Cooper ebecd6c543 Fix EHFrame processing to add implicit references when needed.
The current code for processCIE and processFDE returns out if it sees
any references.  The problem with this is that some references could be
explicit in the binary, while others are implicit as they can be
inferred from the content of the EHFrame itself.

This change walks the references we have against the references we
need, and verifies that all explicit references are in the correct place,
and generates any missing implicit ones.

Reviewed by Lang Hames and Nick Kledzik.

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

llvm-svn: 263590
2016-03-15 21:33:10 +00:00
Rui Ueyama 6b500dc5f9 Simplify string operations. NFC.
llvm-svn: 262569
2016-03-03 00:51:23 +00:00
Rui Ueyama a453c0a5ad Merge DarwinLdDriver and Driver.
Now that DarwinLdDriver is the only derived class of Driver.
This patch merges them and actually removed the class because
they can now just be non-member functions. This change simplifies
a common header, Driver.h.

http://reviews.llvm.org/D17788

llvm-svn: 262502
2016-03-02 19:08:05 +00:00
Rui Ueyama 515025522b Use C++11 initializers for data members.
http://reviews.llvm.org/D17793

llvm-svn: 262501
2016-03-02 19:06:20 +00:00