aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOUniversal.cpp
AgeCommit message (Collapse)AuthorFilesLines
2019-07-25[Object] Add public MaxSectionAlignment to MachOUniversalShoaib Meenai1-6/+7
Change MAXSECTALIGN to a public MaxSectionAlignment in MachOUniversal. Will be used in a follow-up. Patch by Anusha Basana <anusha.basana@gmail.com> Differential Revision: https://reviews.llvm.org/D65117 llvm-svn: 366969
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2016-12-16Fix a bugs with using some Mach-O command line flags like "-arch armv7m".Kevin Enderby1-1/+1
The Mach-O command line flag like "-arch armv7m" does not match the arch name part of its llvm Triple which is "thumbv7m-apple-darwin”. I think the best way to fix this is to have llvm::object::MachOObjectFile::getArchTriple() optionally return the name of the Mach-O arch flag that would be used with -arch that matches the CPUType and CPUSubType. Then change llvm::object::MachOUniversalBinary::ObjectForArch::getArchTypeName() to use that and change it to getArchFlagName() as the type name is really part of the Triple and the -arch flag name is a Mach-O thing for a specific Triple with a specific Mcpu value. rdar://29663637 llvm-svn: 290001
2016-11-28Add error checking for Mach-O universal files.Kevin Enderby1-6/+67
Add the checking for both the MachO::fat_header and the MachO::fat_arch struct values in the constructor for MachOUniversalBinary. Such that when the constructor for ObjectForArch is called it can assume the values in the MachO::fat_arch for the offset and size are contained in the file after the MachOUniversalBinary constructor is called for the Parent. llvm-svn: 288084
2016-11-11Make the Error class constructor protectedMehdi Amini1-1/+1
This is forcing to use Error::success(), which is in a wide majority of cases a lot more readable. Differential Revision: https://reviews.llvm.org/D26481 llvm-svn: 286561
2016-11-07[lib/Object] Modernize. NFCI.Davide Italiano1-4/+3
llvm-svn: 286146
2016-10-24nother additional error check for an invalid Mach-O fileKevin Enderby1-3/+7
when contained in a Mach-O universal file and the cputypes in both headers don’t match. llvm-svn: 285026
2016-07-22[Support] Make ErrorAsOutParameter take an Error* rather than an Error&.Lang Hames1-1/+1
This allows ErrorAsOutParameter to work better with "optional" errors. For example, consider a function where for certain input values it is known that the function can't fail. This can now be written as: Result foo(Arg X, Error *Err) { ErrorAsOutParameter EAO(Err); if (<Error Condition>) { if (Err) *Err = <report error>; else llvm_unreachable("Unexpected failure!"); } } Rather than having to construct an ErrorAsOutParameter under every conditional where Err is known to be non-null. llvm-svn: 276430
2016-06-29Change Archive::create() from ErrorOr<...> to Expected<...> and updateKevin Enderby1-1/+1
its clients. This commit will break the next lld builds. I’ll be committing the matching change for lld next. llvm-svn: 274160
2016-06-29[Object] Fix a -Wpessimizing-move error; clang-format; NFCVedant Kumar1-5/+8
llvm-svn: 274085
2016-06-28Finish cleaning up most of the error handling in libObject’s ↵Kevin Enderby1-6/+12
MachOUniversalBinary and its clients to use the new llvm::Error model for error handling. Changed getAsArchive() from ErrorOr<...> to Expected<...> so now all interfaces there use the new llvm::Error model for return values. In the two places it had if (!Parent) this is actually a program error so changed from returning errorCodeToError(object_error::parse_failed) to calling report_fatal_error() with a message. In getObjectForArch() added error messages to its two llvm::Error return values instead of returning errorCodeToError(object_error::arch_not_found) with no error message. For the llvm-obdump, llvm-nm and llvm-size clients since the only binary files in Mach-O Universal Binaries that are supported are Mach-O files or archives with Mach-O objects, updated their logic to generate an error when a slice contains something like an ELF binary instead of ignoring it. And added a test case for that. The last error stuff to be cleaned up for libObject’s MachOUniversalBinary is the use of errorOrToExpected(Archive::create(ObjBuffer)) which needs Archive::create() to be changed from ErrorOr<...> to Expected<...> first, which I’ll work on next. llvm-svn: 274079
2016-06-27Change all but the last ErrorOr<...> use for MachOUniversalBinary to ↵Kevin Enderby1-11/+22
Expected<...> to allow a good error message to be produced. I added the one test case that the object file tools could produce an error message. The other two errors can’t be triggered if the input file is passed through sys::fs::identify_magic(). But the malformedError("bad magic number") does get triggered by the logic in llvm-dsymutil when dealing with a normal Mach-O file. The other "File too small ..." error would take a logic error currently to produce and is not tested for. llvm-svn: 273946
2016-06-22[MachO] Finish moving fat header swap functions to MachO.hChris Bieneman1-29/+1
This is a follow-up to r273479. At the time I wrote r273479 I didn't connect the dots that the functions I was adding had to exist somewhere. Turns out, they do. This finishes moving the functions to MachO.h. Existing MachO fat header tests like test/tools/llvm-readobj/Inputs/macho-universal-archive.x86_64.i386 execute this code. llvm-svn: 273502
2016-06-20Add support for Darwin’s 64-bit universal files with 64-bit offsets and ↵Kevin Enderby1-11/+47
sizes for the objects. Darwin added support in its Xcode 8.0 tools (released in the beta) for universal files where offsets and sizes for the objects are 64-bits to allow support for objects contained in universal files to be larger then 4gb. The change is very straight forward. There is a new magic number that differs by one bit, much like the 64-bit Mach-O files. Then there is a new structure that follow the fat_header that has the same layout but with the offset and size fields using 64-bit values instead of 32-bit values. rdar://26899493 llvm-svn: 273207
2016-05-31Change llvm-objdump, llvm-nm and llvm-size when reporting an object file errorKevin Enderby1-6/+6
when the object is from a slice of a Mach-O Universal Binary use something like "foo.o (for architecture i386)" as part of the error message when expected. Also fixed places in these tools that were ignoring object file errors from MachOUniversalBinary::getAsObjectFile() when the code moved on to see if the slice was an archive. To do this MachOUniversalBinary::getAsObjectFile() and MachOUniversalBinary::getObjectForArch() were changed from returning ErrorOr<...> to Expected<...> then that was threaded up to its users. Converting these interfaces to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now the use of errorToErrorCode() is still used in two places yet to be fully converted. llvm-svn: 271332
2016-03-25[Object] Make createMachOObjectFile return Expected<...> rather thanLang Hames1-1/+1
ErrorOr<...>. llvm-svn: 264473
2015-08-03Use early return NFC.Frederic Riss1-8/+8
llvm-svn: 243863
2015-06-22[Object] Search for architecures by name in ↵Frederic Riss1-16/+4
MachOUniversalBinary::getObjectForArch() The reason we need to search by name rather than by Triple::ArchType is to handle subarchitecture correclty. There is no different ArchType for the x86_64h architecture (it identifies itself as x86_64), or for the various ARM subarches. The only way to get to the subarch slice in an universal binary is to search by name. This issue led to hard to debug and transient symbolication failures in Asan tests (it mostly works, because the files are very similar). This also affects the Profiling infrastucture as it is the other user of that API. Reviewers: samsonov, bogner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10604 llvm-svn: 240339
2015-06-09Remove object_error::success and use std::error_code() insteadRui Ueyama1-1/+1
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
2015-01-14[cleanup] Re-sort all the #include lines in LLVM usingChandler Carruth1-1/+1
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
2014-12-09Return ErrorOr<std::unique_ptr<Archive>> form getAsArchive.Rafael Espindola1-14/+10
This is the same return type of Archive::create. llvm-svn: 223827
2014-10-20Be more specific about return type of MachOUniversalBinary::getObjectForArchAlexey Samsonov1-2/+2
llvm-svn: 220230
2014-09-03unique_ptrify MachOUniversalBinary::createDavid Blaikie1-2/+2
llvm-svn: 217052
2014-08-19Fix a pair of use after free. Should bring the bots back.Rafael Espindola1-2/+2
llvm-svn: 216005
2014-08-19Don't own the buffer in object::Binary.Rafael Espindola1-13/+9
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
2014-07-31A std::unique_ptr case I missed in the previous patch.Rafael Espindola1-2/+3
llvm-svn: 214379
2014-06-24Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola1-8/+9
Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. llvm-svn: 211595
2014-06-23Pass a std::unique_ptr& to the create??? methods is lib/Object.Rafael Espindola1-2/+2
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
2014-06-23Convert a few methods to use ErrorOr.Rafael Espindola1-10/+6
It used to be inconvenient to mix ErrorOr and UniquePtr, but with c++11 they work OK together. llvm-svn: 211532
2014-06-19Change the output of llvm-nm and llvm-size for Mach-O universal files (akaKevin Enderby1-6/+2
fat files) to print “ (for architecture XYZ)” for fat files with more than one architecture to be like what the darwin tools do for fat files. Also clean up the Mach-O printing of archive membernames in llvm-nm to use the darwin form of "libx.a(foo.o)". llvm-svn: 211316
2014-06-18Teach llvm-size to know about Mach-O universal files (aka fat files) andKevin Enderby1-1/+1
fat files containing archives. Also fix a bug in MachOUniversalBinary::ObjectForArch::ObjectForArch() where it needed a >= when comparing the Index with the number of objects in a fat file. As the index starts at 0. llvm-svn: 211230
2014-06-14Replacing the private implementations of SwapValue with calls to ↵Artyom Skrobov1-12/+7
sys::swapByteOrder() llvm-svn: 210980
2014-06-14Renaming SwapByteOrder() to getSwappedBytes()Artyom Skrobov1-1/+1
The next commit will add swapByteOrder(), acting in-place llvm-svn: 210973
2014-06-13Remove 'using std::errro_code' from lib.Rafael Espindola1-10/+8
llvm-svn: 210871
2014-06-12Don't use 'using std::error_code' in include/llvm.Rafael Espindola1-0/+1
This should make sure that most new uses use the std prefix. llvm-svn: 210835
2014-05-14Teach llvm-nm to know about fat archives (aka MachOUniversal filesKevin Enderby1-0/+20
containing archives). First step as other tools will be updated next. llvm-svn: 208812
2014-04-15[C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper1-1/+1
instead of comparing to nullptr. llvm-svn: 206252
2014-03-06Replace OwningPtr<T> with std::unique_ptr<T>.Ahmed Charles1-5/+5
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
2014-03-05[C++11] Replace OwningPtr::take() with OwningPtr::release().Ahmed Charles1-1/+1
llvm-svn: 202957
2014-01-21Be a bit more consistent about using ErrorOr when constructing Binary objects.Rafael Espindola1-4/+14
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
2014-01-07Re-sort all of the includes with ./utils/sort_includes.py so thatChandler Carruth1-1/+0
subsequent changes are easier to review. About to fix some layering issues, and wanted to separate out the necessary churn. Also comment and sink the include of "Windows.h" in three .inc files to match the usage in Memory.inc. llvm-svn: 198685
2013-09-01Move everything depending on Object/MachOFormat.h over to Support/MachO.h.Charles Davis1-29/+29
llvm-svn: 189728
2013-08-27Revert "Fix the build broken by r189315." and "Move everything depending on ↵Charles Davis1-29/+29
Object/MachOFormat.h over to Support/MachO.h." This reverts commits r189319 and r189315. r189315 broke some tests on what I believe are big-endian platforms. llvm-svn: 189321
2013-08-27Move everything depending on Object/MachOFormat.h over to Support/MachO.h.Charles Davis1-29/+29
llvm-svn: 189315
2013-06-19MachOUniversal.cpp: Fix abuse of Twine. It would be sufficient to use ↵NAKAMURA Takumi1-3/+3
std::string instead. llvm-svn: 184291
2013-06-18Basic support for parsing Mach-O universal binaries in LLVMObject libraryAlexey Samsonov1-0/+139
llvm-svn: 184191