summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/Archive.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby2016-04-061-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
* Object: Correctly read thin archives containing absolute paths.Peter Collingbourne2016-03-311-3/+8
| | | | | | Differential Revision: http://reviews.llvm.org/D18666 llvm-svn: 265065
* Simplify users of StringRef::{l,r}trim (NFC)Vedant Kumar2016-02-161-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
* Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby2015-11-051-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
* This never returns end(), simplify to use Child instead of iterator. NFC.Rafael Espindola2015-11-031-3/+2
| | | | llvm-svn: 251876
* Don't store a Child to the first regular member.Rafael Espindola2015-10-311-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
* Simplify handling of archive Symbol tables.Rafael Espindola2015-10-311-9/+14
| | | | | | We only need to store a StringRef. llvm-svn: 251748
* Simplify the handling of the archive string table.Rafael Espindola2015-10-311-12/+10
| | | | | | We only need to store a StringRef llvm-svn: 251746
* Backing out commit r250906 as it broke lld.Kevin Enderby2015-10-211-107/+37
| | | | llvm-svn: 250908
* This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby2015-10-211-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
* Tweak to r250117 and change to use ErrorOr and drop isSizeValid forKevin Enderby2015-10-131-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
* Fixed bugs in llvm-obdump while parsing Mach-O files from malformed archivesKevin Enderby2015-10-121-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
* Handle Archive::getNumberOfSymbols being called in an archive with no symbols.Rafael Espindola2015-10-081-2/+2
| | | | | | No change in llvm, but will be tested from lld. llvm-svn: 249709
* Fix fetching the symbol table of a thin archive.Rafael Espindola2015-07-221-6/+11
| | | | | | We were trying to read it as an external file. llvm-svn: 242926
* Simplify a few uses of remove_filename by using parent_path instead.Rafael Espindola2015-07-151-3/+2
| | | | llvm-svn: 242334
* Add support for reading members out of thin archives.Rafael Espindola2015-07-141-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
* Add a herper function. NFC.Rafael Espindola2015-07-141-8/+7
| | | | llvm-svn: 242100
* Fix reading archive members with / in the name.Rafael Espindola2015-07-131-3/+3
| | | | | | This is important for thin archives. llvm-svn: 242082
* Don't reject an archive with just a symbol table.Rafael Espindola2015-07-081-1/+1
| | | | | | It is pretty unambiguous how to interpret it and gnu ar accepts it too. llvm-svn: 241750
* Disallow Archive::child_iterator that don't point to an archive.Rafael Espindola2015-07-081-1/+2
| | | | | | NFC, just less error prone. llvm-svn: 241747
* Remove object_error::success and use std::error_code() insteadRui Ueyama2015-06-091-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
* Object: Add Archive::getNumberOfSymbols().Rui Ueyama2015-05-261-14/+13
| | | | | | Add a function that returns number of symbols in archive headers. llvm-svn: 238213
* Use read{16,32,64}{le,be}() instead of ↵Rui Ueyama2015-03-021-37/+24
| | | | | | *reinterpret_cast<u{little,big}{16,32,64}_t>(). llvm-svn: 231016
* [Object] Support reading 64-bit MIPS ELF archivesSimon Atanasyan2015-02-171-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
* [Object] Reformat the code with clang-formatSimon Atanasyan2015-02-101-6/+5
| | | | | | No functional changes. llvm-svn: 228751
* Fix the Archive::Child::getRawSize() method used by llvm-objdump’s ↵Kevin Enderby2015-01-161-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
* This should fix the build bot clang-cmake-armv7-a15-full failing onKevin Enderby2015-01-161-2/+0
| | | | | | the macho-archive-headers.test added with r226228. llvm-svn: 226232
* Add the option, -archive-headers, used with -macho to print the Mach-O ↵Kevin Enderby2015-01-151-0/+13
| | | | | | archive headers to llvm-objdump. llvm-svn: 226228
* Start adding thin archive support.Rafael Espindola2014-12-161-3/+17
| | | | | | This is just sufficient for 'ar t' to work. llvm-svn: 224307
* Object, support both mach-o archive t.o.c file namesNick Kledzik2014-11-121-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
* Don't own the buffer in object::Binary.Rafael Espindola2014-08-191-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
* A std::unique_ptr case I missed in the previous patch.Rafael Espindola2014-07-311-2/+3
| | | | llvm-svn: 214379
* Correct the ownership passing semantics of object::createBinary and make ↵David Blaikie2014-07-211-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
* Remove unnecessary use of unique_ptr::release() used to construct another ↵David Blaikie2014-07-211-2/+1
| | | | | | unique_ptr. llvm-svn: 213556
* Remove unused variable.David Blaikie2014-07-211-1/+0
| | | | llvm-svn: 213554
* Add support for BSD format Archive map symbols (aka the table of contentsKevin Enderby2014-07-081-6/+63
| | | | | | from a __.SYMDEF or "__.SYMDEF SORTED" archive member). llvm-svn: 212568
* Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola2014-06-241-7/+6
| | | | | | | Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. llvm-svn: 211595
* Pass a std::unique_ptr& to the create??? methods is lib/Object.Rafael Espindola2014-06-231-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
* Make ObjectFile and BitcodeReader always own the MemoryBuffer.Rafael Espindola2014-06-231-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
* Convert the Archive API to use ErrorOr.Rafael Espindola2014-06-161-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
* Remove 'using std::errro_code' from lib.Rafael Espindola2014-06-131-15/+15
| | | | llvm-svn: 210871
* Don't use 'using std::error_code' in include/llvm.Rafael Espindola2014-06-121-0/+1
| | | | | | This should make sure that most new uses use the std prefix. llvm-svn: 210835
* Use error_code() instead of error_code::succes()Rafael Espindola2014-05-311-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
* Remove last uses of OwningPtr from llvm. As far as I can tell these method ↵Craig Topper2014-05-181-17/+0
| | | | | | versions are not used by lldb, lld, or clang. llvm-svn: 209103
* [C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper2014-04-151-2/+2
| | | | | | instead of comparing to nullptr. llvm-svn: 206252
* [C++11] Add overloads for externally used OwningPtr functions.Ahmed Charles2014-03-051-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
* Add a SymbolicFile interface between Binary and ObjectFile.Rafael Espindola2014-02-211-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
* Be a bit more consistent about using ErrorOr when constructing Binary objects.Rafael Espindola2014-01-211-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
* Rename these methods to match the style guide.Rafael Espindola2014-01-211-15/+15
| | | | llvm-svn: 199751
* Return an ErrorOr<Binary *> from createBinary.Rafael Espindola2014-01-151-3/+4
| | | | | | | | I did write a version returning ErrorOr<OwningPtr<Binary> >, but it is too cumbersome to use without std::move. I will keep the patch locally and submit when we switch to c++11. llvm-svn: 199326
OpenPOWER on IntegriCloud