summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* llvm-readobj: fix MachO relocatoin printing a bit.Tim Northover2014-07-041-0/+3
| | | | | | | | | | | | | | | | There were two issues here: 1. At the very least, scattered relocations cannot use the same code to determine the corresponding symbol being referred to. For some reason we pretend there is no symbol, even when one actually exists in the symtab, so to match this behaviour getRelocationSymbol should simply return symbols_end for scattered relocations. 2. Printing "-" when we can't get a symbol (including the scattered case, but not exclusively), isn't that helpful. In both cases there *is* interesting information in that field, so we should print it. As hex will do. Small part of rdar://problem/17553104 llvm-svn: 212332
* Speculatively fix some code handling Power64 MachO filesReid Kleckner2014-06-301-1/+1
| | | | | | | MSVC was warning on a switch containing only default labels. In this instance, it looks like it uncovered a real bug. :) llvm-svn: 212062
* Add the -arch flag support to llvm-nm to select the slice out of a Mach-OKevin Enderby2014-06-301-0/+102
| | | | | | | | universal file. This also includes support for -arch all, selecting the host architecture by default from a universal file and checking if -arch is used with a standard Mach-O it matches that architecture. llvm-svn: 212054
* macho-dump: add code to print LC_ID_DYLIB load commands.Tim Northover2014-06-301-0/+6
| | | | | | I want to check them in lld. llvm-svn: 212043
* Revert "Introduce a string_ostream string builder facilty"Alp Toker2014-06-261-3/+4
| | | | | | Temporarily back out commits r211749, r211752 and r211754. llvm-svn: 211814
* Introduce a string_ostream string builder faciltyAlp Toker2014-06-261-4/+3
| | | | | | | | | | | | | | | | | | | | string_ostream is a safe and efficient string builder that combines opaque stack storage with a built-in ostream interface. small_string_ostream<bytes> additionally permits an explicit stack storage size other than the default 128 bytes to be provided. Beyond that, storage is transferred to the heap. This convenient class can be used in most places an std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair would previously have been used, in order to guarantee consistent access without byte truncation. The patch also converts much of LLVM to use the new facility. These changes include several probable bug fixes for truncated output, a programming error that's no longer possible with the new interface. llvm-svn: 211749
* [RuntimeDyld] Adds the necessary hooks to MCJIT to be able to debug generatedLang Hames2014-06-251-1/+5
| | | | | | | | MachO files using the GDB JIT debugging interface. Patch by Keno Fischer. Thanks Keno! llvm-svn: 211652
* Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola2014-06-241-7/+8
| | | | | | | 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-8/+7
| | | | | | | | 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-9/+7
| | | | | | | | | | 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
* Fix a warning about the use of const being ignored with a cast.Kevin Enderby2014-06-201-1/+1
| | | | llvm-svn: 211383
* Replacing the private implementations of SwapValue with calls to ↵Artyom Skrobov2014-06-141-118/+113
| | | | | | sys::swapByteOrder() llvm-svn: 210980
* Renaming SwapByteOrder() to getSwappedBytes()Artyom Skrobov2014-06-141-1/+1
| | | | | | The next commit will add swapByteOrder(), acting in-place llvm-svn: 210973
* Remove 'using std::errro_code' from lib.Rafael Espindola2014-06-131-1/+0
| | | | llvm-svn: 210871
* Don't use 'using std::error_code' in include/llvm.Rafael Espindola2014-06-121-59/+62
| | | | | | This should make sure that most new uses use the std prefix. llvm-svn: 210835
* Add "-format darwin" to llvm-nm to be like darwin's nm(1) -m output.Kevin Enderby2014-06-051-0/+223
| | | | | | | | | | | | | | | This is a first step in seeing if it is possible to make llvm-nm produce the same output as darwin's nm(1). Darwin's default format is bsd but its -m output prints the longer Mach-O specific details. For now I added the "-format darwin" to do this (whos name may need to change in the future). As there are other Mach-O specific flags to nm(1) which I'm hoping to add some how in the future. But I wanted to see if I could get the correct output for -m flag using llvm-nm and the libObject interfaces. I got this working but would love to hear what others think about this approach to getting object/format specific details printed with llvm-nm. llvm-svn: 210285
* MachO: support N_INDR aliases in assembly files.Tim Northover2014-05-301-0/+3
| | | | | | | | | This makes LLVM create N_INDR aliases (to be resolved by the linker) when appropriate. rdar://problem/15125513 llvm-svn: 209894
* Update MachOObjectFile::getSymbolAddress so it returns UnknownAddressOrSizeKevin Enderby2014-05-201-3/+17
| | | | | | | | | | | | for undefined symbols, so it matches what COFFObjectFile::getSymbolAddress does. This allows llvm-nm to print spaces instead of 0’s for the value of undefined symbols in Mach-O files. To make this change other uses of MachOObjectFile::getSymbolAddress are updated to handle when the Value is returned as UnknownAddressOrSize. Which is needed to keep two of the ExecutionEngine tests working for example. llvm-svn: 209253
* Revert r209235 as it broke two tests:Kevin Enderby2014-05-201-10/+2
| | | | | | | | Failing Tests (2): LLVM :: ExecutionEngine/MCJIT/stubs-sm-pic.ll LLVM :: ExecutionEngine/MCJIT/stubs.ll llvm-svn: 209236
* Update MachOObjectFile::getSymbolAddress so it returns UnknownAddressOrSizeKevin Enderby2014-05-201-2/+10
| | | | | | | for undefined symbols. Allowing llvm-nm to print spaces instead of 0’s for the value of undefined symbols in Mach-O files. llvm-svn: 209235
* Implement MachOObjectFile::isSectionData() and MachOObjectFile::isSectionBSSKevin Enderby2014-05-191-6/+12
| | | | | | | | so that llvm-size will total up all the sections in the Berkeley format. This allows for rough categorizations for Mach-O sections. And allows the total of llvm-size’s Berkeley and System V formats to be the same. llvm-svn: 209158
* [RuntimeDyld] Add support for MachO __jump_table and __pointers sections, andLang Hames2014-05-121-7/+15
| | | | | | | | | | | SECTDIFF relocations on 32-bit x86. This fixes several of the MCJIT regression test failures that show up on 32-bit builds. <rdar://problem/16886294> llvm-svn: 208635
* [C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper2014-04-151-1/+2
| | | | | | instead of comparing to nullptr. llvm-svn: 206252
* Add an assert that this is only used with .o files.Rafael Espindola2014-04-041-2/+4
| | | | | | | I am not sure how to get a relocation in a .dylib, but this function would return the wrong value if passed one. llvm-svn: 205592
* Implement getRelocationAddress for MachO and ET_REL elf files.Rafael Espindola2014-04-031-1/+9
| | | | | | With that, fix the symbolizer to work with any ELF file. llvm-svn: 205588
* Implement macho relocation iterators with section number + relocation number.Rafael Espindola2014-04-031-22/+20
| | | | | | This will make it possible to implement getRelocationAddress. llvm-svn: 205587
* Fix llvm-objdump crash.Rafael Espindola2014-04-031-4/+4
| | | | llvm-svn: 205581
* Remove section_rel_empty. Just compare begin() and end() instead.Rafael Espindola2014-04-031-10/+0
| | | | llvm-svn: 205577
* Implement get getSymbolFileOffset with getSymbolAddress.Rafael Espindola2014-04-031-23/+0
| | | | | | | | | | | | This has the following advantages: * Less code. * The old ELF implementation was wrong for non-relocatable objects. * The old ELF implementation (and I think MachO) was wrong for thumb. No current testcase since this is only used from MCJIT and it only uses relocatable objects and I don't think it supports thumb yet. llvm-svn: 205508
* Remove getSymbolValue.Rafael Espindola2014-04-031-5/+0
| | | | | | All existing users explicitly ask for an address or a file offset. llvm-svn: 205503
* Revert "Fix a nomenclature error in llvm-nm."Rafael Espindola2014-04-031-2/+1
| | | | | | | | | | | | | | | | This reverts commit r205479. It turns out that nm does use addresses, it is just that every reasonable relocatable ELF object has sections with address 0. I have no idea if those exist in reality, but it at least it shows that llvm-nm should use the name address. The added test was includes an unusual .o file with non 0 section addresses. I created it by hacking ELFObjectWriter.cpp. Really sorry for the churn. llvm-svn: 205493
* Fix a nomenclature error in llvm-nm.Rafael Espindola2014-04-021-1/+2
| | | | | | | | | | | What llvm-nm prints depends on the file format. On ELF for example, if the file is relocatable, it prints offsets. If it is not, it prints addresses. Since it doesn't really need to care what it is that it is printing, use the generic term value. Fix or implement getSymbolValue to keep llvm-nm working. llvm-svn: 205479
* ARM64: initial backend importTim Northover2014-03-291-0/+22
| | | | | | | | | | | | This adds a second implementation of the AArch64 architecture to LLVM, accessible in parallel via the "arm64" triple. The plan over the coming weeks & months is to merge the two into a single backend, during which time thorough code review should naturally occur. Everything will be easier with the target in-tree though, hence this commit. llvm-svn: 205090
* [RuntimeDyld] Allow processRelocationRef to process more than one relocation ↵Juergen Ributzka2014-03-211-0/+10
| | | | | | | | | | | | | entry at a time. Some targets require more than one relocation entry to perform a relocation. This change allows processRelocationRef to process more than one relocation entry at a time by passing the relocation iterator itself instead of just the relocation entry. Related to <rdar://problem/16199095> llvm-svn: 204439
* Darwin: Add assembler directives to create version-min load commands.Jim Grosbach2014-03-181-0/+13
| | | | | | | | | | | | Allow object files to be tagged with a version-min load command for iOS or MacOSX. Teach macho-dump to understand the version-min load commands for testcases. rdar://11337778 llvm-svn: 204190
* [C++11] Introduce ObjectFile::symbols() to use range-based loops.Alexey Samsonov2014-03-171-7/+7
| | | | | | | | | | | | Reviewers: rafael Reviewed By: rafael CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3081 llvm-svn: 204031
* [C++11] Introduce ObjectFile::sections().Alexey Samsonov2014-03-131-5/+5
| | | | | | | | | | | | | | | | | | Summary: This adds ObjectFile::section_iterator_range, that allows to write range-based for-loops running over all sections of a given file. Several files from lib/ are converted to the new interface. Similar fixes should be applied to a variety of llvm-* tools. Reviewers: rafael Reviewed By: rafael CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3069 llvm-svn: 203799
* Replace OwningPtr<T> with std::unique_ptr<T>.Ahmed Charles2014-03-061-1/+1
| | | | | | | | | | This compiles with no changes to clang/lld/lldb with MSVC and includes overloads to various functions which are used by those projects and llvm which have OwningPtr's as parameters. This should allow out of tree projects some time to move. There are also no changes to libs/Target, which should help out of tree targets have time to move, if necessary. llvm-svn: 203083
* [C++11] Replace OwningPtr::take() with OwningPtr::release().Ahmed Charles2014-03-051-1/+1
| | | | llvm-svn: 202957
* Add a SymbolicFile interface between Binary and ObjectFile.Rafael Espindola2014-02-211-6/+6
| | | | | | | | | | | 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
* Change the begin and end methods in ObjectFile to match the style guide.Rafael Espindola2014-02-101-14/+14
| | | | llvm-svn: 201108
* Remove unused SF_ThreadLocal.Rafael Espindola2014-02-041-1/+0
| | | | llvm-svn: 200800
* Simplify getSymbolFlags.Rafael Espindola2014-01-311-8/+5
| | | | | | | None of the object formats require extra parsing to compute these flags, so the method cannot fail. llvm-svn: 200574
* Only ELF has a dynamic symbol table. Remove it from ObjectFile.Rafael Espindola2014-01-301-10/+0
| | | | | | | | | COFF has only one symbol table. MachO has a LC_DYSYMTAB, but that is not a symbol table, just extra info about the one symbol table (LC_SYMTAB). IR (coming soon) also has only one table. llvm-svn: 200488
* Simplify the handling of iterators in ObjectFile.Rafael Espindola2014-01-301-36/+13
| | | | | | | | | | | | None of the object file formats reported error on iterator increment. In retrospect, that is not too surprising: no object format stores symbols or sections in a linked list or other structure that requires chasing pointers. As a consequence, all error checking can be done on begin() and end(). This reduces the text segment of bin/llvm-readobj in my machine from 521233 to 518526 bytes. llvm-svn: 200442
* Make ObjectFile ownership of the MemoryBuffer optional.Rafael Espindola2014-01-241-9/+10
| | | | | | This allows llvm-ar to mmap the input files only once. llvm-svn: 200040
* Be a bit more consistent about using ErrorOr when constructing Binary objects.Rafael Espindola2014-01-211-10/+10
| | | | | | | | | | | | | | | | | | | | | | | 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
* Fix a pair of array index checks.Eric Christopher2013-12-061-2/+5
| | | | | | Patch by Marius Wachtler. llvm-svn: 196560
* move getSymbolNMTypeChar to the one program that needs it: nm.Rafael Espindola2013-11-021-37/+0
| | | | llvm-svn: 193933
* Fix llvm-nm to mach OS X's nm on some tests.Rafael Espindola2013-11-021-6/+17
| | | | | | | There is still a long way to go for llvm-nm, but at least we now match nm's letter output in the cases we test for. llvm-svn: 193912
OpenPOWER on IntegriCloud