summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-ar/llvm-ar.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* The next step along the way to getting good error messages for bad archives.Kevin Enderby2016-07-291-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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
* [llvm-ar] Document 'T' thin archive modifier (NFC)Teresa Johnson2016-07-221-0/+1
| | | | llvm-svn: 276457
* Next step along the way to getting good error messages for bad archives.Kevin Enderby2016-07-191-2/+2
| | | | | | | | | 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] Re-apply r275316 now that I have the corresponding LLD patch ready.Lang Hames2016-07-141-32/+36
| | | | llvm-svn: 275361
* [Object] Revert r275316, Archive::child_iterator changes, while I update lld.Lang Hames2016-07-141-36/+32
| | | | | | 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-32/+36
| | | | | | | | | | | | | | | | | | | | | | | 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: Replace NewArchiveIterator with a simpler NewArchiveMember class. NFCI.Peter Collingbourne2016-06-291-67/+54
| | | | | | | | | | | | | | | | 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
* Change Archive::create() from ErrorOr<...> to Expected<...> and updateKevin Enderby2016-06-291-2/+5
| | | | | | | | | its clients. This commit will break the next lld builds. I’ll be committing the matching change for lld next. llvm-svn: 274160
* [llvm-ar] Ignore -plugin option.Davide Italiano2016-06-271-0/+1
| | | | | | | | | | | binutils ar uses -plugin to specify the LTO plugin, but LLVM doesn't need this as it doesn't use a plugin for LTO. Accepting (and ignoring) the option allows interoperability with existing build systems and make downstream consumers life much easier. No objections from Rafael on this change. llvm-svn: 273938
* llvm-ar: reduce some duplication, NFCSaleem Abdulrasool2016-06-221-27/+19
| | | | | | | Improve the previous change by using a local function to reduce the duplication of the object file scanning. NFC. llvm-svn: 273429
* llvm-ar: be more clever about default formatSaleem Abdulrasool2016-06-221-18/+76
| | | | | | | | | | | | Try to be more clever about selecting the default format. When an existing archive is used, use the type of the archive to determine the format. When existing members are present, use the first member's format to determine the format to use. If we are creating an empty archive (MRI mode) or are adding non-object members, default to the current behaviour of using the host type due to the lack of a better alternative. This aids in cross-compilation on Darwin to non-Darwin platforms which rely on GNU format archives. llvm-svn: 273373
* llvm-ar: correct typoSaleem Abdulrasool2016-06-211-1/+1
| | | | | | Default was misspelt. NFC. llvm-svn: 273287
* Search for llvm-symbolizer binary in the same directory as argv[0], beforeRichard Smith2016-06-091-1/+1
| | | | | | | looking for it along $PATH. This allows installs of LLVM tools outside of $PATH to find the symbolizer and produce pretty backtraces if they crash. llvm-svn: 272232
* Fix bug where temporary file would be left behind every time an archive was ↵Rafael Espindola2016-05-091-7/+13
| | | | | | | | | | | | | | | | | | | 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
* Simplify. NFC.Rafael Espindola2016-05-021-4/+1
| | | | llvm-svn: 268326
* Don't try to create thin bsd archives.Rafael Espindola2016-05-021-1/+3
| | | | | | Not such variant has been specified yet. llvm-svn: 268305
* Fix formatting and wording of llvm-ranlib error message. NFC.Sunil Srivastava2016-04-081-1/+1
| | | | | | | | Patch by Douglas Yung! Reviewed by Rafael Espindola llvm-svn: 265753
* [llvm-ar] Use failIfError/fail helpers.Davide Italiano2015-11-141-11/+4
| | | | llvm-svn: 253141
* [llvm-ar] Use fail() helper to reduce duplication.Davide Italiano2015-11-141-4/+2
| | | | llvm-svn: 253139
* [llvm-ar] Simplify the code.Davide Italiano2015-11-141-12/+3
| | | | llvm-svn: 253138
* Reapply r250906 with many suggested updates from Rafael Espindola.Kevin Enderby2015-11-051-4/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 doesn't need a object::Archive::child_iterator.Rafael Espindola2015-11-021-2/+2
| | | | llvm-svn: 251796
* Make a few definitions static. NFC.Rafael Espindola2015-11-011-5/+6
| | | | llvm-svn: 251759
* Use Child instead of child_iterator in the archive writer.Rafael Espindola2015-11-011-4/+3
| | | | | | | We never need to pass end(). This will also remove some complication once we start adding error checking. llvm-svn: 251758
* Prefer ranlib mode over ar mode.Ed Schouten2015-10-271-2/+2
| | | | | | | | | | | | | | | | | For CloudABI's toolchain I have a symlink that goes from <target>-ar and <target>-ranlib to LLVM's ar binary, to mimick GNU Binutils' naming scheme. The problem is that if we're targetting ARM64, the name of the ranlib executable is aarch64-unknown-cloudabi-ranlib. This already contains the string "ar". Let's move the "ranlib" test above the "ar" test. It's not that likely that we're going to see operating systems or harwdare architectures that are called "ranlib". Reviewed by: rafael Differential Revision: http://reviews.llvm.org/D14123 llvm-svn: 251413
* Backing out commit r250906 as it broke lld.Kevin Enderby2015-10-211-26/+6
| | | | llvm-svn: 250908
* This removes the eating of the error in Archive::Child::getSize() when the ↵Kevin Enderby2015-10-211-6/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* For new archive member we only need to store the full path.Rafael Espindola2015-07-151-9/+7
| | | | | | | We were storing both the path and the file name, which was redundant and easy to get confused up with. llvm-svn: 242347
* Handle the error of trying to convert a regular archive to a thin one.Rafael Espindola2015-07-151-2/+13
| | | | | | While at it, test that we can add to a thin archive. llvm-svn: 242330
* Initial support for writing thin archives.Rafael Espindola2015-07-151-3/+7
| | | | llvm-svn: 242269
* Add support for reading members out of thin archives.Rafael Espindola2015-07-141-2/+4
| | | | | | | | | | 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
* llvm-ar: Don't try to extract from thin archives.Rafael Espindola2015-07-141-0/+5
| | | | | | This matches the gnu ar behavior. llvm-svn: 242162
* llvm-ar: print an error when the requested member is not found.Rafael Espindola2015-07-141-3/+12
| | | | llvm-svn: 242156
* Use a range loop. NFC.Rafael Espindola2015-07-141-19/+17
| | | | llvm-svn: 242153
* Add support deterministic output in llvm-ar and make it the default.Rafael Espindola2015-07-131-2/+10
| | | | llvm-svn: 242061
* Create BSD archives by default on OS X.Rafael Espindola2015-07-091-3/+9
| | | | | | | | | They should probably be created on anything that is not windows or linux, but I will test on freebsd before changing that. With this it is possible to bootstrap with llvm-ar instead of ar+ranlib on OS X. llvm-svn: 241849
* 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
* Start adding support for writing archives in BSD format.Rafael Espindola2015-07-081-2/+24
| | | | | | | | 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
* ArrayRef-ify libDriverMainDavid Blaikie2015-06-211-1/+1
| | | | llvm-svn: 240234
* LibDriver, llvm-lib: introduce.Peter Collingbourne2015-06-091-6/+11
| | | | | | | | | | llvm-lib is intended to be a lib.exe compatible utility that also understands bitcode. The implementation lives in a library so that lld can use it to implement /lib. Differential Revision: http://reviews.llvm.org/D10297 llvm-svn: 239434
* llvm-ar: Move archive writer to Object.Peter Collingbourne2015-06-081-326/+6
| | | | | | | | | No functional change intended, other than some minor changes to certain diagnostics. Differential Revision: http://reviews.llvm.org/D10296 llvm-svn: 239278
* Purge unused includes throughout libSupport.Benjamin Kramer2015-03-231-0/+1
| | | | | | NFC. llvm-svn: 232976
* llvm-ar: Remove unimplemented -N option from -helpDavid Majnemer2015-01-281-1/+0
| | | | | | This fixes PR22358. llvm-svn: 227296
* Only seek once before writing the member offsets.Rafael Espindola2014-12-111-18/+20
| | | | | | | This cuts down the number on system calls done by a static llvm-ar producing lib/libclangSema.a from 9164 to 442. llvm-svn: 224025
* llvm-ar: close input files early.Rafael Espindola2014-12-111-16/+13
| | | | | | We already have them mapped into memory, so we can just close the file. llvm-svn: 224020
* Remove unused variable.Rafael Espindola2014-11-071-2/+2
| | | | llvm-svn: 221549
* Make two helper functions static.Rafael Espindola2014-10-221-2/+2
| | | | llvm-svn: 220389
* Handle spaces and quotes in file names in MRI scripts.Rafael Espindola2014-10-221-0/+3
| | | | llvm-svn: 220364
* MRI scripts: Add addlib support.Rafael Espindola2014-10-211-1/+20
| | | | llvm-svn: 220346
* Use a range loop. NFC.Rafael Espindola2014-10-211-7/+6
| | | | llvm-svn: 220344
OpenPOWER on IntegriCloud