aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/Archive.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-09-20Rename K_MIPS64 to K_GNU64Jake Ehrlich1-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
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth1-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
2017-04-19[Object] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-17/+34
other minor fixes (NFC). llvm-svn: 300779
2016-11-11Make the Error class constructor protectedMehdi Amini1-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
2016-10-24[Object] Replace TimeValue with std::chronoPavel Labath1-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
2016-10-05[Object] Fix a crash in Archive::child_iterator's default constructor.Lang Hames1-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
2016-09-30[Object] Define Archive::isEmpty().Rui Ueyama1-1/+4
llvm-svn: 282884
2016-08-04Clean up the logic of the Archive::Child::Child() with an assert to know Err ↵Kevin Enderby1-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
2016-08-03Clean up of libObject/Archive interfaces and change the last three uses of ↵Kevin Enderby1-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
2016-08-03Reapply "More fixes to get good error messages for bad archives."Vedant Kumar1-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
2016-08-03Revert "More fixes to get good error messages for bad archives."Vedant Kumar1-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
2016-08-02More fixes to get good error messages for bad archives.Kevin Enderby1-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
2016-08-01Simplify some code found when it was moved in r277177David Blaikie1-10/+10
llvm-svn: 277394
2016-07-29Think this will fix issues with the error messages generated for ↵Kevin Enderby1-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
2016-07-29The next step along the way to getting good error messages for bad archives.Kevin Enderby1-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
2016-07-25Next step along the way to getting good error messages for bad archives.Kevin Enderby1-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
2016-07-22[Support] Make ErrorAsOutParameter take an Error* rather than an Error&.Lang Hames1-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
2016-07-19Next step along the way to getting good error messages for bad archives.Kevin Enderby1-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
2016-07-14[Object] Change Archive::findSym to return an Expected<Optional<Child>>.Lang Hames1-9/+6
As suggested by Rafael in review of D22079 - this was accidentally left out of the final commit (r275316). llvm-svn: 275469
2016-07-14[Object] Re-apply r275316 now that I have the corresponding LLD patch ready.Lang Hames1-22/+26
llvm-svn: 275361
2016-07-14[Object] Revert r275316, Archive::child_iterator changes, while I update lld.Lang Hames1-26/+22
Should fix the bots broken by r275316. llvm-svn: 275353
2016-07-13[Object] Change Archive::child_iterator for better interop with Error/Expected.Lang Hames1-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
2016-07-05Object: support empty UID/GID fieldsSaleem Abdulrasool1-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
2016-06-29Change Archive::create() from ErrorOr<...> to Expected<...> and updateKevin Enderby1-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
2016-06-24Make sure Format is always initialized.Rafael Espindola1-0/+5
Should fix the msan bots. llvm-svn: 273679
2016-06-17Add support for Darwin’s static library table of contents with 64-bit ↵Kevin Enderby1-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
2016-05-17Change llvm-objdump, llvm-nm and llvm-size when reporting an object file errorKevin Enderby1-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
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