summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/Archive.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Add support for the 's' operation to llvm-ar.Rafael Espindola2013-07-291-2/+6
| | | | | | | | | | | | If no other operation is specified, 's' becomes an operation instead of an modifier. The s operation just creates a symbol table. It is the same as running ranlib. We assume the archive was created by a sane ar (like llvm-ar or gnu ar) and if the symbol table is present, then it is current. We use that to optimize the most common case: a broken build system that thinks it has to run ranlib. llvm-svn: 187353
* Add 'const' qualifiers to static const char* variables.Craig Topper2013-07-161-1/+1
| | | | llvm-svn: 186371
* Change llvm-ar to use lib/Object.Rafael Espindola2013-07-121-26/+23
| | | | | | | | | | | | | | | | | | | | | | This fixes two bugs is lib/Object that the use in llvm-ar found: * In OS X created archives, the name can be padded with nulls. Strip them. * In the constructor, remember the first non special member and use that in begin_children. This makes sure we skip all special members, not just the first one. The change to llvm-ar itself consist of * Using lib/Object for reading archives instead of ArchiveReader.cpp. * Writing the modified archive directly, instead of creating an in memory representation. The old Archive library was way more general than what is needed, as can be seen by the diffstat of this patch. Having llvm-ar using lib/Object now opens the way for creating regular symbol tables for both native objects and bitcode files so that we can use those archives for LTO. llvm-svn: 186197
* Don't reject an empty archive.Rafael Espindola2013-07-121-4/+6
| | | | llvm-svn: 186159
* Find the symbol table on archives created on OS X.Rafael Espindola2013-07-101-3/+14
| | | | llvm-svn: 186041
* Don't crash in 'llvm -s' when an archive has no symtab.Rafael Espindola2013-07-101-1/+7
| | | | llvm-svn: 186029
* Add missing getters. They will be used in llvm-ar.Rafael Espindola2013-07-091-0/+32
| | | | llvm-svn: 185937
* Archive members cannot be larger than 4GB. Return a uint32_t.Rafael Espindola2013-07-091-5/+5
| | | | llvm-svn: 185936
* Add getHeader helper and move ToHeader to the cpp file.Rafael Espindola2013-07-091-2/+6
| | | | llvm-svn: 185933
* Compute the size of an archive member in the constructor.Rafael Espindola2013-07-091-14/+13
| | | | | | | It is always computed the same way (by parsing the header). Doing it in the constructor simplifies the callers a bit. llvm-svn: 185905
* Move some code out of line. No functionality change.Rafael Espindola2013-07-091-0/+70
| | | | llvm-svn: 185901
* Remove a useless declarations (found by scan-build)Sylvestre Ledru2013-07-051-1/+0
| | | | llvm-svn: 185709
* Use the raw member names in Archive::Archive.Rafael Espindola2013-07-051-15/+10
| | | | | | | This a bit more efficient and avoids having a function that uses the string table being called by a function that searches for it. llvm-svn: 185680
* Add support for archives with no symbol table or string table.Rafael Espindola2013-07-041-1/+1
| | | | llvm-svn: 185664
* Add support for gnu archives with a string table and no symtab.Rafael Espindola2013-07-031-27/+52
| | | | | | While there, use early returns to reduce nesting. llvm-svn: 185547
* Remove the LLVM specific archive index.Rafael Espindola2013-06-141-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Archive files (.a) can have a symbol table indicating which object files in them define which symbols. The purpose of this symbol table is to speed up linking by allowing the linker the read only the .o files it is actually going to use instead of having to parse every object's symbol table. LLVM's archive library currently supports a LLVM specific format for such table. It is hard to see any value in that now that llvm-ld is gone: * System linkers don't use it: GNU ar uses the same plugin as the linker to create archive files with a regular index. The OS X ar creates no symbol table for IL files, I assume the linker just parses all IL files. * It doesn't interact well with archives having both IL and native objects. * We probably don't want to be responsible for yet another archive format variant. This patch then: * Removes support for creating and reading such index from lib/Archive. * Remove llvm-ranlib, since there is nothing left for it to do. We should in the future add support for regular indexes to llvm-ar for both native and IL objects. When we do that, llvm-ranlib should be reimplemented as a symlink to llvm-ar, as it is equivalent to "ar s". llvm-svn: 184019
* [Object/COFF] Fix Windows .lib name handling.Rui Ueyama2013-06-031-4/+10
| | | | llvm-svn: 183091
* [Object][Archive] Improve performance.Michael J. Spencer2013-02-031-98/+10
| | | | | | | | | | | | Improve performance of iterating over children and accessing the member file buffer by caching the file size and moving code out to the header. This also makes getBuffer return a StringRef instead of a MemoryBuffer. Both fixing a memory leak and removing a malloc. This takes getBuffer from ~10% of the time in lld to unmeasurable. llvm-svn: 174272
* [Object][Archive] Fix name handling with bsd style long names.Michael J. Spencer2013-01-101-8/+14
| | | | llvm-svn: 172026
* [Object][Archive] Apparently StringRef::getAsInteger for APInt accepts spaces.Michael J. Spencer2013-01-101-2/+6
| | | | llvm-svn: 172022
OpenPOWER on IntegriCloud