summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/Archive.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Object] Uncapitalize an error messageFangrui Song2019-09-201-1/+1
| | | | | | Test case will be added by my next commit. llvm-svn: 372369
* [llvm-ar] Fix support for archives with members larger than 4GBOwen Reynolds2019-07-231-2/+2
| | | | | | | | | | | | | | | | llvm-ar outputs a strange error message when handling archives with members larger than 4GB due to not checking file size when passing the value as an unsigned 32 bit integer. This overflow issue caused malformed archives to be created.: https://bugs.llvm.org/show_bug.cgi?id=38058 This change allows for members above 4GB and will error in a case that is over the formats size limit, a 10 digit decimal integer. Differential Revision: https://reviews.llvm.org/D65093 llvm-svn: 366813
* [libObject][NFC] Include filename in error messageJordan Rupprecht2019-02-061-1/+1
| | | | llvm-svn: 353341
* [ADT] Add a fallible_iterator wrapper.Lang Hames2019-02-051-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A fallible iterator is one whose increment or decrement operations may fail. This would usually be supported by replacing the ++ and -- operators with methods that return error: class MyFallibleIterator { public: // ... Error inc(); Errro dec(); // ... }; The downside of this style is that it no longer conforms to the C++ iterator concept, and can not make use of standard algorithms and features such as range-based for loops. The fallible_iterator wrapper takes an iterator written in the style above and adapts it to (mostly) conform with the C++ iterator concept. It does this by providing standard ++ and -- operator implementations, returning any errors generated via a side channel (an Error reference passed into the wrapper at construction time), and immediately jumping the iterator to a known 'end' value upon error. It also marks the Error as checked any time an iterator is compared with a known end value and found to be inequal, allowing early exit from loops without redundant error checking*. Usage looks like: MyFallibleIterator I = ..., E = ...; Error Err = Error::success(); for (auto &Elem : make_fallible_range(I, E, Err)) { // Loop body is only entered when safe. // Early exits from loop body permitted without checking Err. if (SomeCondition) return; } if (Err) // Handle error. * Since failure causes a fallible iterator to jump to end, testing that a fallible iterator is not an end value implicitly verifies that the error is a success value, and so is equivalent to an error check. Reviewers: dblaikie, rupprecht Subscribers: mgorny, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57618 llvm-svn: 353237
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Object: Find terminator correctly when reading long filenames in GNU ↵Hans Wennborg2018-05-081-4/+8
| | | | | | | | | | | | archives (PR37244) The code was previously relying on there being a null terminator somewhere in (or after) the string table, something made less likely by r330786. Differential Revision: https://reviews.llvm.org/D46527 llvm-svn: 331746
* Make 32-bit member offset in Archive::Symbol::getMember 64-bitJake Ehrlich2017-10-271-1/+1
| | | | | | | | | | | | When accessing a member for a symbol with an offset greater than 2^32 - 1 the current Archive::Symbol::getMember implementation will overflow and cause unexpected behavior. This change simply fixes that. In particular if you call "llvm-nm --print-armap" on an archive that has this behavior you'll get an error. Differential Revision: https://reviews.llvm.org/D39379 llvm-svn: 316801
* Rename K_MIPS64 to K_GNU64Jake Ehrlich2017-09-201-8/+8
| | | | | | | This patch renames K_MIPS64 to K_GNU64 as part of a change to add support for writing archives with 64-bit indexes in the symbol table. llvm-svn: 313787
* Sort the remaining #include lines in include/... and lib/....Chandler Carruth2017-06-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
* [Object] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko2017-04-191-17/+34
| | | | | | other minor fixes (NFC). llvm-svn: 300779
* Make the Error class constructor protectedMehdi Amini2016-11-111-3/+3
| | | | | | | | | This is forcing to use Error::success(), which is in a wide majority of cases a lot more readable. Differential Revision: https://reviews.llvm.org/D26481 llvm-svn: 286561
* [Object] Replace TimeValue with std::chronoPavel Labath2016-10-241-4/+3
| | | | | | | | | | | | | | | Summary: Most of the changes are very straight-forward. The only choice I had to make was to use second-precision time points in the Archive classes. I did this because the archive files use that precision in the on-disk representation anyway. Reviewers: rafael, zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25773 llvm-svn: 284974
* [Object] Fix a crash in Archive::child_iterator's default constructor.Lang Hames2016-10-051-4/+7
| | | | | | | | | | To be default constructible, Archive::child_iterator needs to be able to construct an Archive::Child with a null parent, however Archive::Child's constructor always dereferenced its Parent argument to compute the remaining archive size. This commit fixes Archive::Child's constructor to only do the size calculation when the parent is non-null. llvm-svn: 283387
* [Object] Define Archive::isEmpty().Rui Ueyama2016-09-301-1/+4
| | | | llvm-svn: 282884
* Clean up the logic of the Archive::Child::Child() with an assert to know Err ↵Kevin Enderby2016-08-041-21/+23
| | | | | | | | | | | | | | | | | is not a nullptr when we are pointed at real data. David Blaikie pointed out some odd logic in the case the Err value was a nullptr and Lang Hames suggested it could be cleaned it up with an assert to know that Err is not a nullptr when we are pointed at real data. As only in the case of constructing the sentinel value by pointing it at null data is Err is permitted to be a nullptr, since no error could occur in that case. With this change the testing for “if (Err)” is removed from the constructor’s logic and *Err is used directly without any check after the assert(). llvm-svn: 277776
* Clean up of libObject/Archive interfaces and change the last three uses of ↵Kevin Enderby2016-08-031-40/+75
| | | | | | | | | | | | ErrorOr<> changing them to Expected<> to allow them to pass through llvm Errors. No functional change. This commit by itself will break the next lld builds.  I’ll be committing the matching change for lld immediately next. llvm-svn: 277656
* Reapply "More fixes to get good error messages for bad archives."Vedant Kumar2016-08-031-12/+50
| | | | | | | | This reverts commit the revert commit r277627. The build errors mentioned in r277627 were likely caused by an unclean build directory. Sorry for the noise. llvm-svn: 277630
* Revert "More fixes to get good error messages for bad archives."Vedant Kumar2016-08-031-50/+12
| | | | | | | | | | | | | This reverts commit r277540. It breaks the build with: ../lib/Object/Archive.cpp:264:41: error: return type of out-of-line definition of 'llvm::object::ArchiveMemberHeader::getUID' differs from that in the declaration Expected<unsigned> ArchiveMemberHeader::getUID() const { ~~~~~~~~~~~~~~~~~~ ^ include/llvm/Object/Archive.h:53:12: note: previous declaration is here unsigned getUID() const; ~~~~~~~~ ^ llvm-svn: 277627
* More fixes to get good error messages for bad archives.Kevin Enderby2016-08-021-12/+50
| | | | | | | Fixed the last incorrect uses of llvm_unreachable() in the code which were actually just cases of errors in the input Archives. llvm-svn: 277540
* Simplify some code found when it was moved in r277177David Blaikie2016-08-011-10/+10
| | | | llvm-svn: 277394
* Think this will fix issues with the error messages generated for ↵Kevin Enderby2016-07-291-15/+13
| | | | | | | | | | | | | | | malformed-archives.test in r277177 and added back this test which was deleted in r277196 while I tracked down these problems. Changed from constructing Twine's to std::string's as Twine's don't work across statements. Also removed a few unneeded Twine() constructions. Fix the write_escaped() calls to not pass the unintended second argument fixing the warning on the ld-x86_64-win7 bot. llvm-svn: 277223
* The next step along the way to getting good error messages for bad archives.Kevin Enderby2016-07-291-87/+228
| | | | | | | | | | | | | | | | | | | | | | | | As mentioned in commit log for r276686 this next step is adding a new method in the ArchiveMemberHeader class to get the full name that does proper error checking, and can be use for error messages. To do this the name of ArchiveMemberHeader::getName() is changed to ArchiveMemberHeader::getRawName() to be consistent with Archive::Child::getRawName(). Then the “new” method is the addition of a new implementation of ArchiveMemberHeader::getName() which gets the full name and provides proper error checking. Which is mostly a rewrite of what was Archive::Child::getName() and cleaning up incorrect uses of llvm_unreachable() in the code which were actually just cases of errors in the input Archives. Then Archive::Child::getName() is changed to return Expected<> and use the new implementation of ArchiveMemberHeader::getName() . Also needed to change Archive::getMemoryBufferRef() with these changes to return Expected<> as well to propagate Errors up. As well as changing Archive::isThinMember() to return Expected<> . llvm-svn: 277177
* Next step along the way to getting good error messages for bad archives.Kevin Enderby2016-07-251-23/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | I consulted with Lang Hames on this work, and the goal was to add a bit of "where" in the archive the error occurred along with what the error was. So this step changes ArchiveMemberHeader into a class with a pointer to the archive header and the parent archive. Which allows the methods in the ArchiveMemberHeader to determine which member the header is for to include that information in the error message. For this first step the "where" is just the offset to the member in the archive. The next step will be a new method on ArchiveMemberHeader to get the full name, if possible, to be use in the error message. Which will now be possible as ArchiveMemberHeader contains a pointer to the Archive with its string table and its size, etc. so the full name can be determined from the header if it is valid. Also this change adds the missing checks the archive header is actually contained in the buffer and is not truncated, as well as if the terminating characters are correct in the header. And changes one error message in Archive::Child::getNext() where the name or offset to member is now added. llvm-svn: 276686
* [Support] Make ErrorAsOutParameter take an Error* rather than an Error&.Lang Hames2016-07-221-4/+3
| | | | | | | | | | | | | | | | | | | | | | This allows ErrorAsOutParameter to work better with "optional" errors. For example, consider a function where for certain input values it is known that the function can't fail. This can now be written as: Result foo(Arg X, Error *Err) { ErrorAsOutParameter EAO(Err); if (<Error Condition>) { if (Err) *Err = <report error>; else llvm_unreachable("Unexpected failure!"); } } Rather than having to construct an ErrorAsOutParameter under every conditional where Err is known to be non-null. llvm-svn: 276430
* Next step along the way to getting good error messages for bad archives.Kevin Enderby2016-07-191-35/+46
| | | | | | | | | This step builds on Lang Hames work to change Archive::child_iterator for better interoperation with Error/Expected. Building on that it is now possible to return an error message when the size field of an archive contains non-decimal characters. llvm-svn: 276025
* [Object] Change Archive::findSym to return an Expected<Optional<Child>>.Lang Hames2016-07-141-9/+6
| | | | | | | As suggested by Rafael in review of D22079 - this was accidentally left out of the final commit (r275316). llvm-svn: 275469
* [Object] Re-apply r275316 now that I have the corresponding LLD patch ready.Lang Hames2016-07-141-22/+26
| | | | llvm-svn: 275361
* [Object] Revert r275316, Archive::child_iterator changes, while I update lld.Lang Hames2016-07-141-26/+22
| | | | | | Should fix the bots broken by r275316. llvm-svn: 275353
* [Object] Change Archive::child_iterator for better interop with Error/Expected.Lang Hames2016-07-131-22/+26
| | | | | | | | | | | | | | | | | | | | | | | See http://reviews.llvm.org/D22079 Changes the Archive::child_begin and Archive::children to require a reference to an Error. If iterator increment fails (because the archive header is damaged) the iterator will be set to 'end()', and the error stored in the given Error&. The Error value should be checked by the user immediately after the loop. E.g.: Error Err; for (auto &C : A->children(Err)) { // Do something with archive child C. } // Check the error immediately after the loop. if (Err) return Err; Failure to check the Error will result in an abort() when the Error goes out of scope (as guaranteed by the Error class). llvm-svn: 275316
* Object: support empty UID/GID fieldsSaleem Abdulrasool2016-07-051-2/+8
| | | | | | | | | Normal archives do not have empty UID/GID fields. However, the Microsoft Import library format is a customized archive (it just uses an alternate symbol index format). When the import library is constructed by lib.exe, the UID and GID fields are left empty. Do not abort on such an input. llvm-svn: 274528
* Change Archive::create() from ErrorOr<...> to Expected<...> and updateKevin Enderby2016-06-291-18/+25
| | | | | | | | | its clients. This commit will break the next lld builds. I’ll be committing the matching change for lld next. llvm-svn: 274160
* Make sure Format is always initialized.Rafael Espindola2016-06-241-0/+5
| | | | | | Should fix the msan bots. llvm-svn: 273679
* Add support for Darwin’s static library table of contents with 64-bit ↵Kevin Enderby2016-06-171-3/+40
| | | | | | | | | | | | | | offsets to the archive members. Darwin added support in its Xcode 8.0 tools (released in the beta) for static library table of contents with 64-bit offsets to the archive members. The change is very straight forward. The table of contents member is named ___.SYMDEF_64 or "___.SYMDEF_64 SORTED" and same layout is used but with fields using 64 bit values instead of 32 bit values. rdar://26869808 llvm-svn: 273058
* Change llvm-objdump, llvm-nm and llvm-size when reporting an object file errorKevin Enderby2016-05-171-3/+8
| | | | | | | | | | | | | | | | | | | | | when the object is in an archive to use something like libx.a(foo.o) as part of the error message. Also changed llvm-objdump and llvm-size to be like llvm-nm and ignore non-object files in archives and not produce any error message. To do this Archive::Child::getAsBinary() was changed from ErrorOr<...> to Expected<...> then that was threaded up to its users. Converting this interface to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now the use of errorToErrorCode() is still used in one place yet to be fully converted. Again 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 comments for those. llvm-svn: 269784
* Expose a getFullName for thin archive members.Rafael Espindola2016-05-021-10/+18
| | | | | | It will be used in lld. llvm-svn: 268226
* [NFC] Header cleanupMehdi Amini2016-04-181-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
* 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
OpenPOWER on IntegriCloud