aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/ArchiveWriter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-08-03Reapply "More fixes to get good error messages for bad archives."Vedant Kumar1-4/+16
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-16/+4
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-4/+16
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-07-29The next step along the way to getting good error messages for bad archives.Kevin Enderby1-2/+2
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-06-29Object: Replace NewArchiveIterator with a simpler NewArchiveMember class. NFCI.Peter Collingbourne1-117/+63
The NewArchiveIterator class has a problem: it requires too much context. Any memory buffers added to the archive must be stored within an Archive::Member, which must have an associated Archive. This makes it harder than necessary to create new archive members (or new archives entirely) from scratch using memory buffers. This patch replaces NewArchiveIterator with a NewArchiveMember class that stores just the memory buffer and the information that goes into the archive member header. Differential Revision: http://reviews.llvm.org/D21721 llvm-svn: 274183
2016-05-09Fix bug where temporary file would be left behind every time an archive was ↵Rafael Espindola1-1/+15
updated. When updating an existing archive, llvm-ar opens the old archive into a `MemoryBuffer`, does its thing, and writes the results to a temporary file. That file is then renamed to the original archive filename, thus replacing it with the updated contents. However, on Windows at least, what would happen is that the `MemoryBuffer` for the old archive would actually be an mmap'ed view of the file, so when it came time to do the rename via Win32's `ReplaceFile`, it would succeed but would be unable to fully replace the file since there would still be a handle open on it; instead, the old version got renamed to a random temporary name and left behind. Patch by Cameron! llvm-svn: 268916
2016-05-03[lib/Object] Make this assertion more useful.Davide Italiano1-3/+2
llvm-svn: 268367
2016-05-02Don't try to create thin bsd archives.Rafael Espindola1-0/+3
Not such variant has been specified yet. llvm-svn: 268305
2016-04-20Replace a loop with a for-each loop. No behavior change.Nico Weber1-2/+1
llvm-svn: 266903
2016-04-06Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby1-3/+6
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
2015-12-18Handle archives with paths in the names.Rafael Espindola1-2/+4
We always create archives with just he filename as the member name, but other archives can put a more complicated path in there. This patches handles it by computing just the filename as we do when adding a new member. If storing the path is important for some reason, we should probably have an orthogonal option for doing that and do it for both old and new members. Fixes pr25877. llvm-svn: 256001
2015-11-05Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby1-2/+5
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-02Avoid implicitly constructing a Archive::child_iterator.Rafael Espindola1-10/+10
llvm-svn: 251794
2015-11-01Use Child instead of child_iterator in the archive writer.Rafael Espindola1-5/+5
We never need to pass end(). This will also remove some complication once we start adding error checking. llvm-svn: 251758
2015-10-21Backing out commit r250906 as it broke lld.Kevin Enderby1-10/+7
llvm-svn: 250908
2015-10-21This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby1-7/+10
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-09-22Untabify.NAKAMURA Takumi1-1/+1
llvm-svn: 248264
2015-07-16Fix handling of relative paths in thin archives.Rafael Espindola1-3/+32
The member has to end up with a path relative to the archive. llvm-svn: 242362
2015-07-15llvm-ar: Don't write the directory in the string table.Rafael Espindola1-1/+1
We were already doing the right thing for short file names, but not long ones. llvm-svn: 242354
2015-07-15Silence GCC -Wparenthesis warningDavid Majnemer1-3/+2
llvm-svn: 242348
2015-07-15For new archive member we only need to store the full path.Rafael Espindola1-4/+4
We were storing both the path and the file name, which was redundant and easy to get confused up with. llvm-svn: 242347
2015-07-15Handle the error of trying to convert a regular archive to a thin one.Rafael Espindola1-0/+3
While at it, test that we can add to a thin archive. llvm-svn: 242330
2015-07-15Initial support for writing thin archives.Rafael Espindola1-13/+24
llvm-svn: 242269
2015-07-14Use a range loop.Rafael Espindola1-4/+2
llvm-svn: 242250
2015-07-13Add support deterministic output in llvm-ar and make it the default.Rafael Espindola1-17/+43
llvm-svn: 242061
2015-07-09llvm-ar: Pad the symbol table to 4 bytes.Rafael Espindola1-2/+5
It looks like ld64 requires it. With this we seem to be able to bootstrap using llvm-ar+/usr/bin/true instead of ar+ranlib (currently on stage2). llvm-svn: 241842
2015-07-09Basic support for BSD symbol tables in archives.Rafael Espindola1-17/+39
This could be optimized and for now we only produce __.SYMDEF and not "__.SYMDEF SORTED". llvm-svn: 241814
2015-07-09Remove redundant variable. NFC.Rafael Espindola1-2/+1
llvm-svn: 241810
2015-07-09Add a helper to printing BE of LE depending on the format.Rafael Espindola1-6/+10
The gnu ar format uses BE numbers. The BSD one uses LE. Add a helper for one or the other. NFC for now, just removes some noise from the following patch. llvm-svn: 241808
2015-07-09Extract printBSDMemberHeader.Rafael Espindola1-22/+25
It will get another use in the following patch. Also rename the other helper to printGNUSmallMemberHeader for consistency. llvm-svn: 241805
2015-07-08Disallow Archive::child_iterator that don't point to an archive.Rafael Espindola1-2/+0
NFC, just less error prone. llvm-svn: 241747
2015-07-08Use a raw_svector_ostream and simplify a loop. NFC.Rafael Espindola1-6/+3
llvm-svn: 241727
2015-07-08Start adding support for writing archives in BSD format.Rafael Espindola1-10/+30
No support for the symbol table yet (but will hopefully add it today). We always use the long filename format so that we can align the member, which is an advantage of the BSD format. llvm-svn: 241721
2015-07-08Inline function into only use.Rafael Espindola1-12/+6
llvm-svn: 241692
2015-07-08Add a helper function to reduce a bit of code duplication.Rafael Espindola1-25/+22
llvm-svn: 241691
2015-07-08Use a range loop. NFC.Rafael Espindola1-8/+6
llvm-svn: 241685
2015-06-17[ArchiveWriter] Use EndianStream. No functional change intended.Benjamin Kramer1-9/+4
llvm-svn: 239913
2015-06-13Don't use std::errc.Rafael Espindola1-1/+2
As noted on Errc.h: // * std::errc is just marked with is_error_condition_enum. This means that // common patters like AnErrorCode == errc::no_such_file_or_directory take // 4 virtual calls instead of two comparisons. And on some libstdc++ those virtual functions conclude that ------------------------ int main() { std::error_code foo = std::make_error_code(std::errc::no_such_file_or_directory); return foo == std::errc::no_such_file_or_directory; } ------------------------- should exit with 0. llvm-svn: 239683
2015-06-08Fix Windows build.Peter Collingbourne1-0/+4
llvm-svn: 239279
2015-06-08llvm-ar: Move archive writer to Object.Peter Collingbourne1-0/+338
No functional change intended, other than some minor changes to certain diagnostics. Differential Revision: http://reviews.llvm.org/D10296 llvm-svn: 239278