aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/Archive.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-05-02Expose a getFullName for thin archive members.Rafael Espindola1-10/+18
It will be used in lld. llvm-svn: 268226
2016-04-18[NFC] Header cleanupMehdi Amini1-1/+0
Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
2016-04-06Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby1-1/+4
to produce a real error message Produce the first specific error message for a malformed Mach-O file describing the problem instead of the generic message for object_error::parse_failed of "Invalid data was encountered while parsing the file”.  Many more good error messages will follow after this first one. This is built on Lang Hames’ great work of adding the ’Error' class for structured error handling and threading Error through MachOObjectFile construction. And making createMachOObjectFile return Expected<...> . So to to get the error to the llvm-obdump tool, I changed the stack of these methods to also return Expected<...> : object::ObjectFile::createObjectFile() object::SymbolicFile::createSymbolicFile() object::createBinary() Then finally in ParseInputMachO() in MachODump.cpp the error can be reported and the specific error message can be printed in llvm-objdump and can be seen in the existing test case for the existing malformed binary but with the updated error message. Converting these interfaces to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now use of errorToErrorCode() and errorOrToExpected() are used where the callers are yet to be converted. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values. So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(ObjOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there is one fix also needed to lld/COFF/InputFiles.cpp that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 265606
2016-03-31Object: Correctly read thin archives containing absolute paths.Peter Collingbourne1-3/+8
Differential Revision: http://reviews.llvm.org/D18666 llvm-svn: 265065
2016-02-16Simplify users of StringRef::{l,r}trim (NFC)Vedant Kumar1-9/+8
r260925 introduced a version of the *trim methods which is preferable when trimming a single kind of character. Update all users in llvm. llvm-svn: 260926
2015-11-05Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby1-46/+88
The needed lld matching changes to be submitted immediately next, but this revision will cause lld failures with this alone which is expected. This removes the eating of the error in Archive::Child::getSize() when the characters in the size field in the archive header for the member is not a number. To do this we have all of the needed methods return ErrorOr to push them up until we get out of lib. Then the tools and can handle the error in whatever way is appropriate for that tool. So the solution is to plumb all the ErrorOr stuff through everything that touches archives. This include its iterators as one can create an Archive object but the first or any other Child object may fail to be created due to a bad size field in its header. Thanks to Lang Hames on the changes making child_iterator contain an ErrorOr<Child> instead of a Child and the needed changes to ErrorOr.h to add operator overloading for * and -> . We don’t want to use llvm_unreachable() as it calls abort() and is produces a “crash” and using report_fatal_error() to move the error checking will cause the program to stop, neither of which are really correct in library code. There are still some uses of these that should be cleaned up in this library code for other than the size field. The test cases use archives with text files so one can see the non-digit character, in this case a ‘%’, in the size field. These changes will require corresponding changes to the lld project. That will be committed immediately after this change. But this revision will cause lld failures with this alone which is expected. llvm-svn: 252192
2015-11-03This never returns end(), simplify to use Child instead of iterator. NFC.Rafael Espindola1-3/+2
llvm-svn: 251876
2015-10-31Don't store a Child to the first regular member.Rafael Espindola1-8/+17
This is a bit ugly, but has a few advantages: * Archive is now easy to copy since there is no Archive -> Child -> Archive loop. * It makes it clear that we already checked for errors when finding the Child data. llvm-svn: 251750
2015-10-31Simplify handling of archive Symbol tables.Rafael Espindola1-9/+14
We only need to store a StringRef. llvm-svn: 251748
2015-10-31Simplify the handling of the archive string table.Rafael Espindola1-12/+10
We only need to store a StringRef llvm-svn: 251746
2015-10-21Backing out commit r250906 as it broke lld.Kevin Enderby1-107/+37
llvm-svn: 250908
2015-10-21This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby1-37/+107
characters in the size field in the archive header for the member is not a number. To do this we have all of the needed methods return ErrorOr to push them up until we get out of lib. Then the tools and can handle the error in whatever way is appropriate for that tool. So the solution is to plumb all the ErrorOr stuff through everything that touches archives. This include its iterators as one can create an Archive object but the first or any other Child object may fail to be created due to a bad size field in its header. Thanks to Lang Hames on the changes making child_iterator contain an ErrorOr<Child> instead of a Child and the needed changes to ErrorOr.h to add operator overloading for * and -> . We don’t want to use llvm_unreachable() as it calls abort() and is produces a “crash” and using report_fatal_error() to move the error checking will cause the program to stop, neither of which are really correct in library code. There are still some uses of these that should be cleaned up in this library code for other than the size field. Also corrected the code where the size gets us to the “at the end of the archive” which is OK but past the end of the archive will return object_error::parse_failed now. The test cases use archives with text files so one can see the non-digit character, in this case a ‘%’, in the size field. llvm-svn: 250906
2015-10-13Tweak to r250117 and change to use ErrorOr and drop isSizeValid forKevin Enderby1-17/+12
ArchiveMemberHeader, suggestion by Rafael Espíndola. Also The clang-x86-win2008-selfhost bot still does not like the malformed-machos 00000031.a test, so removing it for now. All the other bots are fine with it however. llvm-svn: 250222
2015-10-12Fixed bugs in llvm-obdump while parsing Mach-O files from malformed archivesKevin Enderby1-0/+12
that caused aborts. This was because of the characters of the ‘Size’ field in the archive header did not contain decimal characters. rdar://22983603 llvm-svn: 250117
2015-10-08Handle Archive::getNumberOfSymbols being called in an archive with no symbols.Rafael Espindola1-2/+2
No change in llvm, but will be tested from lld. llvm-svn: 249709
2015-07-22Fix fetching the symbol table of a thin archive.Rafael Espindola1-6/+11
We were trying to read it as an external file. llvm-svn: 242926
2015-07-15Simplify a few uses of remove_filename by using parent_path instead.Rafael Espindola1-3/+2
llvm-svn: 242334
2015-07-14Add support for reading members out of thin archives.Rafael Espindola1-1/+22
For now the Archive owns the buffers of the thin archive members. This makes for a simple API, but all the buffers are destructed only when the archive is destructed. This should be fine since we close the files after mmap so we should not hit an open file limit. llvm-svn: 242215
2015-07-14Add a herper function. NFC.Rafael Espindola1-8/+7
llvm-svn: 242100
2015-07-13Fix reading archive members with / in the name.Rafael Espindola1-3/+3
This is important for thin archives. llvm-svn: 242082
2015-07-08Don't reject an archive with just a symbol table.Rafael Espindola1-1/+1
It is pretty unambiguous how to interpret it and gnu ar accepts it too. llvm-svn: 241750
2015-07-08Disallow Archive::child_iterator that don't point to an archive.Rafael Espindola1-1/+2
NFC, just less error prone. llvm-svn: 241747
2015-06-09Remove object_error::success and use std::error_code() insteadRui Ueyama1-6/+6
make_error_code(object_error) is slow because object::object_category() uses a ManagedStatic variable. But the real problem is that the function is called too frequently. This patch uses std::error_code() instead of object_error::success. In most cases, we return "success", so this patch reduces number of function calls to that function. http://reviews.llvm.org/D10333 llvm-svn: 239409
2015-05-26Object: Add Archive::getNumberOfSymbols().Rui Ueyama1-14/+13
Add a function that returns number of symbols in archive headers. llvm-svn: 238213
2015-03-02Use read{16,32,64}{le,be}() instead of ↵Rui Ueyama1-37/+24
*reinterpret_cast<u{little,big}{16,32,64}_t>(). llvm-svn: 231016
2015-02-17[Object] Support reading 64-bit MIPS ELF archivesSimon Atanasyan1-5/+25
The 64-bit MIPS ELF archive file format is used by MIPS64 targets. The main difference from a regular archive file is the symbol table format: 1. ar_name is equal to "/SYM64/" 2. number of symbols and offsets are 64-bit integers http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf Page 96 The patch allows reading of such archive files by llvm-nm, llvm-objdump and other tools. But it does not support archive files with number of symbols and/or offsets exceed 2^32. I think it is a rather rare case requires more significant modification of `Archive` class code. http://reviews.llvm.org/D7546 llvm-svn: 229520
2015-02-10[Object] Reformat the code with clang-formatSimon Atanasyan1-6/+5
No functional changes. llvm-svn: 228751
2015-01-16Fix the Archive::Child::getRawSize() method used by llvm-objdump’s ↵Kevin Enderby1-1/+1
-archive-headers option and tweak its use in llvm-objdump. Add back the test case for the -archive-headers option. llvm-svn: 226332
2015-01-16This should fix the build bot clang-cmake-armv7-a15-full failing onKevin Enderby1-2/+0
the macho-archive-headers.test added with r226228. llvm-svn: 226232
2015-01-15Add the option, -archive-headers, used with -macho to print the Mach-O ↵Kevin Enderby1-0/+13
archive headers to llvm-objdump. llvm-svn: 226228
2014-12-16Start adding thin archive support.Rafael Espindola1-3/+17
This is just sufficient for 'ar t' to work. llvm-svn: 224307
2014-11-12Object, support both mach-o archive t.o.c file namesNick Kledzik1-1/+1
For historical reasons archives on mach-o have two possible names for the file containing the table of contents for the archive: "__.SYMDEF SORTED" and "__.SYMDEF". But the libObject archive reader only supported the former. This patch fixes llvm::object::Archive to support both names. llvm-svn: 221747
2014-08-19Don't own the buffer in object::Binary.Rafael Espindola1-22/+13
Owning the buffer is somewhat inflexible. Some Binaries have sub Binaries (like Archive) and we had to create dummy buffers just to handle that. It is also a bad fit for IRObjectFile where the Module wants to own the buffer too. Keeping this ownership would make supporting IR inside native objects particularly painful. This patch focuses in lib/Object. If something elsewhere used to own an Binary, now it also owns a MemoryBuffer. This patch introduces a few new types. * MemoryBufferRef. This is just a pair of StringRefs for the data and name. This is to MemoryBuffer as StringRef is to std::string. * OwningBinary. A combination of Binary and a MemoryBuffer. This is needed for convenience functions that take a filename and return both the buffer and the Binary using that buffer. The C api now uses OwningBinary to avoid any change in semantics. I will start a new thread to see if we want to change it and how. llvm-svn: 216002
2014-07-31A std::unique_ptr case I missed in the previous patch.Rafael Espindola1-2/+3
llvm-svn: 214379
2014-07-21Correct the ownership passing semantics of object::createBinary and make ↵David Blaikie1-1/+1
them explicit in the type system. createBinary documented that it destroyed the parameter in error cases, though by observation it does not. By passing the unique_ptr by value rather than lvalue reference, callers are now explicit about passing ownership and the function implements the documented contract. Remove the explicit documentation, since now the behavior cannot be anything other than what was documented, so it's redundant. Also drops a unique_ptr::release in llvm-nm that was always run on a null unique_ptr anyway. llvm-svn: 213557
2014-07-21Remove unnecessary use of unique_ptr::release() used to construct another ↵David Blaikie1-2/+1
unique_ptr. llvm-svn: 213556
2014-07-21Remove unused variable.David Blaikie1-1/+0
llvm-svn: 213554
2014-07-08Add support for BSD format Archive map symbols (aka the table of contentsKevin Enderby1-6/+63
from a __.SYMDEF or "__.SYMDEF SORTED" archive member). llvm-svn: 212568
2014-06-24Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola1-7/+6
Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. llvm-svn: 211595
2014-06-23Pass a std::unique_ptr& to the create??? methods is lib/Object.Rafael Espindola1-4/+1
This makes the buffer ownership on error conditions very natural. The buffer is only moved out of the argument if an object is constructed that now owns the buffer. llvm-svn: 211546
2014-06-23Make ObjectFile and BitcodeReader always own the MemoryBuffer.Rafael Espindola1-1/+6
This allows us to just use a std::unique_ptr to store the pointer to the buffer. The flip side is that they have to support releasing the buffer back to the caller. Overall this looks like a more efficient and less brittle api. llvm-svn: 211542
2014-06-16Convert the Archive API to use ErrorOr.Rafael Espindola1-55/+42
Now that we have c++11, even things like ErrorOr<std::unique_ptr<...>> are easy to use. No intended functionality change. llvm-svn: 211033
2014-06-13Remove 'using std::errro_code' from lib.Rafael Espindola1-15/+15
llvm-svn: 210871
2014-06-12Don't use 'using std::error_code' in include/llvm.Rafael Espindola1-0/+1
This should make sure that most new uses use the std prefix. llvm-svn: 210835
2014-05-31Use error_code() instead of error_code::succes()Rafael Espindola1-1/+1
There is no std::error_code::success, so this removes much of the noise in transitioning to std::error_code. llvm-svn: 209952
2014-05-18Remove last uses of OwningPtr from llvm. As far as I can tell these method ↵Craig Topper1-17/+0
versions are not used by lldb, lld, or clang. llvm-svn: 209103
2014-04-15[C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper1-2/+2
instead of comparing to nullptr. llvm-svn: 206252
2014-03-05[C++11] Add overloads for externally used OwningPtr functions.Ahmed Charles1-7/+24
This will allow external callers of these functions to switch over time rather than forcing a breaking change all a once. These particular functions were determined by building clang/lld/lldb. llvm-svn: 202959
2014-02-21Add a SymbolicFile interface between Binary and ObjectFile.Rafael Espindola1-2/+3
This interface allows IRObjectFile to be implemented without having dummy methods for all section and segment related methods. Both llvm-ar and llvm-nm are changed to use it. Unfortunately the mangler is still not plugged in since it requires some refactoring to make a Module hold a DataLayout. llvm-svn: 201881
2014-01-21Be a bit more consistent about using ErrorOr when constructing Binary objects.Rafael Espindola1-0/+8
The constructors of classes deriving from Binary normally take an error_code as an argument to the constructor. My original intent was to change them to have a trivial constructor and move the initial parsing logic to a static method returning an ErrorOr. I changed my mind because: * A constructor with an error_code out parameter is extremely convenient from the implementation side. We can incrementally construct the object and give up when we find an error. * It is very efficient when constructing on the stack or when there is no error. The only inefficient case is where heap allocating and an error is found (we have to free the memory). The result is that this is a much smaller patch. It just standardizes the create* helpers to return an ErrorOr. Almost no functionality change: The only difference is that this found that we were trying to read past the end of COFF import library but ignoring the error. llvm-svn: 199770