summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/IRObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Don't pass a Reloc::Model to MC.Rafael Espindola2016-05-181-1/+1
| | | | | | | | | | | | MC only needs to know if the output is PIC or not. It never has to decide about creating GOTs and PLTs for example. The only thing that MC itself uses this information for is expanding "macros" in sparc and mips. The rest I am pretty sure could be moved to CodeGen. This is a cleanup and isolates the code from future changes to Reloc::Model. llvm-svn: 269909
* Return a StringRef from getSection.Rafael Espindola2016-05-111-1/+1
| | | | | | This is similar to how getName is handled. llvm-svn: 269218
* Clean the API for CollectAsmUndefinedRefs, taking a Triple and a String ↵Mehdi Amini2016-04-221-5/+3
| | | | | | | InlineAsm instead of a Module (NFC) From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 267106
* IRObjectFile, clang-format fixup for r267104Mehdi Amini2016-04-221-4/+5
| | | | | From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 267105
* Use std::move on the enum to insert it into the pair to please MSVCMehdi Amini2016-04-221-1/+1
| | | | | | | | (I have no idea why is it needed) Fixup for r267103 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 267104
* Refactor IRObjectFile, extract a static CollectAsmUndefinedRefs() method to ↵Mehdi Amini2016-04-221-4/+15
| | | | | | | | | parse inline assembly (NFC) I plan to call this from ThinLTOCodeGenerator. From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 267103
* Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby2016-04-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Rename embedded bitcode section in MachOSteven Wu2016-02-291-4/+1
| | | | | | | | | | | | | | Summary: Rename the section embeds bitcode from ".llvmbc,.llvmbc" to "__LLVM,__bitcode". The new name matches MachO section naming convention. Reviewers: rafael, pcc Subscribers: davide, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D17388 llvm-svn: 262245
* IRObject: Mark extern_weak as weak.Rafael Espindola2016-02-291-1/+2
| | | | llvm-svn: 262222
* Use copy initialization.Rafael Espindola2016-02-111-2/+2
| | | | | | We can do it since getMemBuffer returns a unique_ptr. llvm-svn: 260576
* Move MCTargetAsmParser.h to llvm/MC/MCParser where it belongs.Benjamin Kramer2016-01-271-1/+1
| | | | llvm-svn: 258917
* Use diagnostic handler in the LLVMContextRafael Espindola2015-12-141-1/+1
| | | | | | | | | | | | | | | | This patch converts code that has access to a LLVMContext to not take a diagnostic handler. This has a few advantages * It is easier to use a consistent diagnostic handler in a single program. * Less clutter since we are not passing a handler around. It does make it a bit awkward to implement some C APIs that return a diagnostic string. I will propose new versions of these APIs and deprecate the current ones. llvm-svn: 255571
* Fix llvm-nm(1) printing of llvm-bitcode files for -format darwin to match ↵Kevin Enderby2015-11-101-0/+6
| | | | | | | | darwin’s nm(1). Also a small fix to match printing of Mach-O objects with -format posix. llvm-svn: 252567
* Simplify the Mangler interface now that DataLayout is mandatory.Rafael Espindola2015-06-231-3/+1
| | | | | | | We only need to pass in a DataLayout when mangling a raw string, not when constructing the mangler. llvm-svn: 240405
* Return a unique_ptr from getLazyBitcodeModule and parseBitcodeFile. NFC.Rafael Espindola2015-06-161-2/+2
| | | | llvm-svn: 239858
* Recommit r239721: Replace string GNU Triples with llvm::Triple in ↵Daniel Sanders2015-06-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | InitMCObjectFileInfo. NFC. Summary: This affects other tools so the previous C++ API has been retained as a deprecated function for the moment. Clang has been updated with a trivial patch (not covered by the pre-commit review) to avoid breaking -Werror builds. Other in-tree tools will be fixed with similar patches. This continues the patch series to eliminate StringRef forms of GNU triples from the internals of LLVM that began in r239036. The first time this was committed it accidentally fixed an inconsistency in triples in llvm-mc and this caused a failure. This inconsistency was fixed in r239808. Reviewers: rengolin Reviewed By: rengolin Subscribers: llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10366 llvm-svn: 239812
* Revert r239721 - Replace string GNU Triples with llvm::Triple in ↵Daniel Sanders2015-06-151-6/+6
| | | | | | | | InitMCObjectFileInfo. NFC. It appears to cause sparc-little-endian.s to assert on Windows and Darwin. llvm-svn: 239724
* Replace string GNU Triples with llvm::Triple in InitMCObjectFileInfo. NFC.Daniel Sanders2015-06-151-6/+6
| | | | | | | | | | | | | | | | | | | | | Summary: This affects other tools so the previous C++ API has been retained as a deprecated function for the moment. Clang has been updated with a trivial patch (not covered by the pre-commit review) to avoid breaking -Werror builds. Other in-tree tools will be fixed with similar trivial patches. This continues the patch series to eliminate StringRef forms of GNU triples from the internals of LLVM that began in r239036. Reviewers: rengolin Reviewed By: rengolin Subscribers: llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10366 llvm-svn: 239721
* Object: Prepend __imp_ when mangling a dllimport symbol in IRObjectFile.Peter Collingbourne2015-06-111-0/+3
| | | | | | | | | | | | | | | | | We cannot prepend __imp_ in the IR mangler because a function reference may be emitted unmangled in a constant initializer. The linker is expected to resolve such references to thunks. This is covered by the new test case. Strictly speaking we ought to emit two undefined symbols, one with __imp_ and one without, as we cannot know which symbol the final object file will refer to. However, this would require rather intrusive changes to IRObjectFile, and lld works fine without it for now. This reimplements r239437, which was reverted in r239502. Differential Revision: http://reviews.llvm.org/D10400 llvm-svn: 239560
* Remove object_error::success and use std::error_code() insteadRui Ueyama2015-06-091-2/+2
| | | | | | | | | | | | 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
* Remove MCAssembler.h include from MCStreamer.h and fix users of MCStreamer.hPete Cooper2015-05-151-0/+1
| | | | llvm-svn: 237483
* Be lazy about loading metadata in IRObjectFile.Rafael Espindola2015-03-131-1/+3
| | | | | | | This speeds up llvm-ar building lib64/libclangSema.a with debug IR files from 8.658015807 seconds to just 0.351036519 seconds :-) llvm-svn: 232221
* Make DataLayout Non-Optional in the ModuleMehdi Amini2015-03-041-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: DataLayout keeps the string used for its creation. As a side effect it is no longer needed in the Module. This is "almost" NFC, the string is no longer canonicalized, you can't rely on two "equals" DataLayout having the same string returned by getStringRepresentation(). Get rid of DataLayoutPass: the DataLayout is in the Module The DataLayout is "per-module", let's enforce this by not duplicating it more than necessary. One more step toward non-optionality of the DataLayout in the module. Make DataLayout Non-Optional in the Module Module->getDataLayout() will never returns nullptr anymore. Reviewers: echristo Subscribers: resistor, llvm-commits, jholewinski Differential Revision: http://reviews.llvm.org/D7992 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 231270
* Add missing includes. make_unique proliferated everywhere.Benjamin Kramer2015-03-011-0/+1
| | | | llvm-svn: 230909
* Introduce Target::createNullTargetStreamer and use it from IRObjectFile.Peter Collingbourne2015-02-191-0/+1
| | | | | | | | | A null MCTargetStreamer allows IRObjectFile to ignore target-specific directives. Previously we were crashing. Differential Revision: http://reviews.llvm.org/D7711 llvm-svn: 229797
* [cleanup] Re-sort all the #include lines in LLVM usingChandler Carruth2015-01-141-3/+3
| | | | | | | | | | | utils/sort_includes.py. I clearly haven't done this in a while, so more changed than usual. This even uncovered a missing include from the InstrProf library that I've added. No functionality changed here, just mechanical cleanup of the include order. llvm-svn: 225974
* Silence more static analyzer warnings.Michael Ilseman2014-12-151-0/+2
| | | | | | | | Add in definedness checks for shift operators, null checks when pointers are assumed by the code to be non-null, and explicit unreachables. llvm-svn: 224255
* Rename createIRObjectFile to just create.Rafael Espindola2014-12-091-2/+2
| | | | | | | It is a static method of IRObjectFile, so having to use IRObjectFile::createIRObjectFile was redundant. llvm-svn: 223822
* Move method out of line to make buildbot happy.Rafael Espindola2014-12-091-0/+2
| | | | llvm-svn: 223781
* Don't lookup an object symbol name in the module.Rafael Espindola2014-12-091-5/+2
| | | | | | | | | | | Instead, walk the obj symbol list in parallel to find the GV. This shouldn't change anything on ELF where global symbols are not mangled, but it is a step toward supporting other object formats. Gold itself is ELF only, but bfd ld supports COFF and the logic in the gold plugin could be reused on lld. llvm-svn: 223780
* Don't ever call materializeAllPermanently during LTO.Rafael Espindola2014-10-241-11/+1
| | | | | | | | | | To do this, change the representation of lazy loaded functions. The previous representation cannot differentiate between a function whose body has been removed and one whose body hasn't been read from the .bc file. That means that in order to drop a function, the entire body had to be read. llvm-svn: 220580
* LTO: introduce object file-based on-disk module format.Peter Collingbourne2014-09-181-1/+41
| | | | | | | | | | | | | | | | | | This format is simply a regular object file with the bitcode stored in a section named ".llvmbc", plus any number of other (non-allocated) sections. One immediate use case for this is to accommodate compilation processes which expect the object file to contain metadata in non-allocated sections, such as the ".go_export" section used by some Go compilers [1], although I imagine that in the future we could consider compiling parts of the module (such as large non-inlinable functions) directly into the object file to improve LTO efficiency. [1] http://golang.org/doc/install/gccgo#Imports Differential Revision: http://reviews.llvm.org/D4371 llvm-svn: 218078
* unique_ptrify IRObjectFile::createIRObjectFileDavid Blaikie2014-09-031-2/+2
| | | | | | | | I took a guess at the changes to the gold plugin, because that doesn't seem to build by default for me. Not sure what dependencies I might be missing for that. llvm-svn: 217056
* Pass a && to getLazyBitcodeModule.Rafael Espindola2014-09-031-1/+1
| | | | | | | | This forces callers to use std::move when calling it. It is somewhat odd to have code with std::move that doesn't always move, but it is also odd to have code without std::move that sometimes moves. llvm-svn: 217049
* Pass a std::unique_ptr<MemoryBuffer>& to getLazyBitcodeModule.Rafael Espindola2014-08-261-2/+1
| | | | | | | By taking a reference we can do the ownership transfer in one place instead of expecting every caller to do it. llvm-svn: 216492
* Pass a MemoryBufferRef when we can avoid taking ownership.Rafael Espindola2014-08-261-4/+1
| | | | | | | | | | | | | The attached patch simplifies a few interfaces that don't need to take ownership of a buffer. For example, both parseAssembly and parseBitcodeFile will parse the entire buffer before returning. There is no need to take ownership. Using a MemoryBufferRef makes it obvious in the type signature that there is no ownership transfer. llvm-svn: 216488
* Explicitly pass ownership of the MemoryBuffer to AddNewSourceBuffer using ↵David Blaikie2014-08-211-1/+1
| | | | | | std::unique_ptr llvm-svn: 216223
* Don't own the buffer in object::Binary.Rafael Espindola2014-08-191-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Make RecordStreamer.h private.Rafael Espindola2014-07-041-2/+2
| | | | llvm-svn: 212361
* Ignore llvm.* globals.Rafael Espindola2014-07-041-6/+3
| | | | | | | It is not clear if llvm.global_ctors should or should not be in llvm.metadata, but in practice it is not and we need to ignore it for LTO. llvm-svn: 212351
* Implement LTOModule on top of IRObjectFile.Rafael Espindola2014-07-041-14/+12
| | | | | | | | | | | | | IRObjectFile provides all the logic for producing mangled names and getting symbols from inline assembly. LTOModule then adds logic for linking specific tasks, like constructing llvm.compiler_user or extracting linker options from the bitcode. The rule of the thumb is that IRObjectFile has the functionality that is needed by both LTO and llvm-ar. llvm-svn: 212349
* Mark intrinsic functions as llvm-specific.Rafael Espindola2014-07-041-0/+5
| | | | llvm-svn: 212347
* Don't include llvm.metadata variables in archive symbol tables.Rafael Espindola2014-07-041-0/+5
| | | | llvm-svn: 212344
* Move createIRObjectFile to the IRObjectFile class and return the concrete type.Rafael Espindola2014-07-031-1/+1
| | | | llvm-svn: 212301
* Add support for inline asm symbols to IRObjectFile.Rafael Espindola2014-07-031-21/+130
| | | | | | This also enables it in llvm-nm so that it can be tested. llvm-svn: 212282
* Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola2014-06-241-8/+9
| | | | | | | Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. llvm-svn: 211595
* Make ObjectFile and BitcodeReader always own the MemoryBuffer.Rafael Espindola2014-06-231-8/+10
| | | | | | | | | | 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
* Change IRObjectFile to parse the bitcode lazily.Rafael Espindola2014-06-181-2/+13
| | | | | | | The main point of this class is to provide a cheap object interface to a bitcode file, so it has to be as lazy as possible. llvm-svn: 211207
* Remove 'using std::errro_code' from lib.Rafael Espindola2014-06-131-5/+4
| | | | 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
OpenPOWER on IntegriCloud