aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object
AgeCommit message (Collapse)AuthorFilesLines
2016-12-04[Object][MachO] Reference-ify some helper function arguments. NFC.Lang Hames1-201/+200
Changes all static helper functions in MachOObjectFile.cpp that expect a non-null MachOObjectFile pointer to take a reference instead. llvm-svn: 288608
2016-12-01Remove iostream include from WasmObjectFilePavel Labath1-2/+0
The file does not seems to use c++ iostreams (and is is llvm policy to avoid that). Committing as obvious. llvm-svn: 288364
2016-12-01Object: Set SF_Indirect in ModuleSymbolTable.Peter Collingbourne1-0/+2
This lets us remove the last use of IRObjectFile::getSymbolGV() in llvm-nm. Differential Revision: https://reviews.llvm.org/D27076 llvm-svn: 288321
2016-12-01Object: Add SF_Executable symbol flag.Peter Collingbourne1-1/+4
This allows us to remove a few uses of IRObjectFile::getSymbolGV() in llvm-nm. While here change host-dependent logic in llvm-nm to target-dependent logic. Differential Revision: https://reviews.llvm.org/D27075 llvm-svn: 288320
2016-12-01Object: Extract a ModuleSymbolTable class from IRObjectFile.Peter Collingbourne3-144/+195
This class represents a symbol table built from in-memory IR. It provides access to GlobalValues and should only be used if such access is required (e.g. in the LTO implementation). We will eventually change IRObjectFile to read from a bitcode symbol table rather than using ModuleSymbolTable, so it would not be able to expose the module. Differential Revision: https://reviews.llvm.org/D27073 llvm-svn: 288319
2016-11-30Only computeRelativePath() on new membersDavid Callahan1-3/+8
Summary: When using thin archives, and processing the same archive multiple times, we were mangling existing entries. The root cause is that we were calling computeRelativePath() more than once. Here, we only call it when adding new members to an archive. Note that D27218 changes the way thin archives are printed, and will break the new unit test included here. Depending on which one lands first, the other will need to be slightly modified. Reviewers: rafael, davide Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27217 llvm-svn: 288280
2016-11-30[WebAssembly] Add llvm-objdump support for wasm file formatDerek Schuff5-1/+322
This is the first part of an effort to add wasm binary support across all llvm tools. Patch by Sam Clegg Differential Revision: https://reviews.llvm.org/D26172 llvm-svn: 288251
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-24Object: Add IRObjectFile::getTargetTriple().Peter Collingbourne1-0/+2
This lets us remove a use of IRObjectFile::getModule() in llvm-nm. Differential Revision: https://reviews.llvm.org/D27074 llvm-svn: 287846
2016-11-24Object: Simplify the IRObjectFile symbol iterator implementation.Peter Collingbourne1-89/+25
Change the IRObjectFile symbol iterator to be a pointer into a vector of PointerUnions representing either IR symbols or asm symbols. This change is in preparation for a future change for supporting multiple modules in an IRObjectFile. Although it causes an increase in memory consumption, we can deal with that issue separately by introducing a bitcode symbol table. Differential Revision: https://reviews.llvm.org/D26928 llvm-svn: 287845
2016-11-22Object: Make SymbolicFile::symbol_{begin,end}() virtual and remove ↵Peter Collingbourne3-6/+6
unnecessary wrappers. llvm-svn: 287611
2016-11-18Object: Simplify; remove unnecessary use of unique_ptr.Peter Collingbourne1-4/+4
llvm-svn: 287305
2016-11-15Object: replace backslashes with slashes in embedded relative thin archive ↵Peter Collingbourne1-0/+6
paths on Windows. This makes these thin archives portable between *nix and Windows. Differential Revision: https://reviews.llvm.org/D26696 llvm-svn: 287038
2016-11-15Fix llvm-symbolizer to correctly sort a symbol array and calculate symbol sizesKuba Brecka1-12/+6
Sometimes, llvm-symbolizer gives wrong results due to incorrect sizes of some symbols. The reason for that was an incorrectly sorted array in computeSymbolSizes. The comparison function used subtraction of unsigned types, which is incorrect. Let's change this to return explicit -1 or 1. Differential Revision: https://reviews.llvm.org/D26537 llvm-svn: 287028
2016-11-15Fix -Wswitch.Rui Ueyama2-0/+2
llvm-svn: 286920
2016-11-15Add a file magic for CL.exe's object file created with /GL.Rui Ueyama1-0/+1
This patch makes it possible to identify object files created by CL.exe with /GL option. Such file contains Microsoft proprietary intermediate code instead of target machine code to do LTO. I need this to print out user-friendly error message from LLD. Differential Revision: https://reviews.llvm.org/D26645 llvm-svn: 286919
2016-11-14Add a checkSymbolTable() method to the MachOObjectFile class.Kevin Enderby1-0/+68
The philosophy of the error checking in libObject for Mach-O files is that the constructor will check the load commands so for their tables the offsets and sizes are properly contained in the file. But there is no checking of the entries of any of the tables. For the contents of the tables themselves the methods accessing the contents of the entries return errors as needed. In some cases this however makes it difficult or cumbersome to produce a good error message which would include the tool name, file name, archive member, and name of the architecture of a slice of a universal file the error occurred in. So idea is that there will be a method to check a table which can be called up front before using it allowing a good error message to be produced before a table is used. And if only verification of the Mach-O file and its tables are wanted a new possible method checkAllTables() could be added to call all of the methods to check all the tables at some time when such methods exist. The checkSymbolTable() is the first of such methods to check one of the Mach-O file tables. This method initially will used in llvm-objdump’s DisassembleMachO() routine before it gets the section and symbol information. As if there are problems with the symbol table currently the error is first encountered by the bool operator() in the SymbolSorter() struct which passed to std::sort(). In this case there is no context as to the file name the symbol which results a poor error message: LLVM ERROR: truncated or malformed object (bad string index: 22 for symbol at index 1) with the added call to the checkSymbolTable() method the error message includes the tool name and file name: llvm-objdump: 'macho-invalid-symbol-strx': truncated or malformed object (bad string table index: 22 past the end of string table, for symbol at index 1) llvm-svn: 286887
2016-11-14Restore "[ThinLTO] Prevent exporting of locals used/defined in module level asm"Teresa Johnson1-2/+1
This restores the rest of r286297 (part was restored in r286475). Specifically, it restores the part requiring adding a dependency from the Analysis to Object library (downstream use changed to correctly model split BitReader vs BitWriter libraries). Original description of this part of patch follows: Module level asm may also contain defs of values. We need to prevent export of any refs to local values defined in module level asm (e.g. a ref in normal IR), since that also requires renaming/promotion of the local. To do that, the summary index builder looks at all values in the module level asm string that are not marked Weak or Global, which is exactly the set of locals that are defined. A summary is created for each of these local defs and flagged as NoRename. This required adding handling to the BitcodeWriter to look at GV declarations to see if they have a summary (rather than skipping them all). Finally, added an assert to IRObjectFile::CollectAsmUndefinedRefs to ensure that an MCAsmParser is available, otherwise the module asm parse would silently fail. Initialized the asm parser in the opt tool for use in testing this fix. Fixes PR30610. llvm-svn: 286844
2016-11-13Bitcode: Change module reader functions to return an llvm::Expected.Peter Collingbourne2-9/+9
Differential Revision: https://reviews.llvm.org/D26562 llvm-svn: 286752
2016-11-11Fix -Wpessimizing-move warning.Rui Ueyama1-1/+1
llvm-svn: 286629
2016-11-11Bitcode: Change getModuleSummaryIndex() to return an llvm::Expected.Peter Collingbourne1-22/+15
Differential Revision: https://reviews.llvm.org/D26539 llvm-svn: 286624
2016-11-11Bitcode: Clean up error handling for certain bitcode query functions.Peter Collingbourne1-12/+0
The functions getBitcodeTargetTriple(), isBitcodeContainingObjCCategory(), getBitcodeProducerString() and hasGlobalValueSummary() now return errors via their return value rather than via the diagnostic handler. To make this work, re-implement these functions using non-member functions so that they can be used without the LLVMContext required by BitcodeReader. Differential Revision: https://reviews.llvm.org/D26532 llvm-svn: 286623
2016-11-11Split Bitcode/ReaderWriter.h into separate reader and writer headersTeresa Johnson2-2/+2
Summary: Split ReaderWriter.h which contains the APIs into both the BitReader and BitWriter libraries into BitcodeReader.h and BitcodeWriter.h. This is to address Chandler's concern about sharing the same API header between multiple libraries (BitReader and BitWriter). That concern is why we create a single bitcode library in our downstream build of clang, which led to r286297 being reverted as it added a dependency that created a cycle only when there is a single bitcode library (not two as in upstream). Reviewers: mehdi_amini Subscribers: dlj, mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D26502 llvm-svn: 286566
2016-11-11Make the Error class constructor protectedMehdi Amini4-16/+15
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-11[lli] Simplify the code a bit. No functional change intended.Davide Italiano1-3/+1
llvm-svn: 286555
2016-11-09Revert "[ThinLTO] Prevent exporting of locals used/defined in module level asm"Mehdi Amini1-1/+2
This reverts commit r286297. Introduces a dependency from libAnalysis to libObject, which I missed during the review. llvm-svn: 286329
2016-11-08[ThinLTO] Prevent exporting of locals used/defined in module level asmTeresa Johnson1-2/+1
Summary: This patch uses the same approach added for inline asm in r285513 to similarly prevent promotion/renaming of locals used or defined in module level asm. All static global values defined in normal IR and used in module level asm should be included on either the llvm.used or llvm.compiler.used global. The former were already being flagged as NoRename in the summary, and I've simply added llvm.compiler.used values to this handling. Module level asm may also contain defs of values. We need to prevent export of any refs to local values defined in module level asm (e.g. a ref in normal IR), since that also requires renaming/promotion of the local. To do that, the summary index builder looks at all values in the module level asm string that are not marked Weak or Global, which is exactly the set of locals that are defined. A summary is created for each of these local defs and flagged as NoRename. This required adding handling to the BitcodeWriter to look at GV declarations to see if they have a summary (rather than skipping them all). Finally, added an assert to IRObjectFile::CollectAsmUndefinedRefs to ensure that an MCAsmParser is available, otherwise the module asm parse would silently fail. Initialized the asm parser in the opt tool for use in testing this fix. Fixes PR30610. Reviewers: mehdi_amini Subscribers: johanengelen, krasin, llvm-commits Differential Revision: https://reviews.llvm.org/D26146 llvm-svn: 286297
2016-11-08IR, Bitcode: Change bitcode reader to no longer own its memory buffer.Peter Collingbourne1-4/+1
Unique ownership is just one possible ownership pattern for the memory buffer underlying the bitcode reader. In practice, as this patch shows, ownership can often reside at a higher level. With the upcoming change to allow multiple modules in a single bitcode file, it will no longer be appropriate for modules to generally have unique ownership of their memory buffer. The C API exposes the ownership relation via the LLVMGetBitcodeModuleInContext and LLVMGetBitcodeModuleInContext2 functions, so we still need some way for the module to own the memory buffer. This patch does so by adding an owned memory buffer field to Module, and using it in a few other places where it is convenient. Differential Revision: https://reviews.llvm.org/D26384 llvm-svn: 286214
2016-11-07[lib/Object] Modernize. NFCI.Davide Italiano1-4/+3
llvm-svn: 286146
2016-11-03Add support for the ARM_THREAD_STATE64 andKevin Enderby1-0/+19
in llvm-objdump for Mach-O files add the printing of the ARM_THREAD_STATE64 in the same format as otool-classic(1) on darwin. To do this the 64-bit ARM general tread state needed to be defined in include/llvm/Support/MachO.h . rdar://28985800 llvm-svn: 285967
2016-11-03[Object/ELF] - Make getSymbol() return Error.George Rimar1-0/+2
That is consistent with other methods around and helps to handle error on a caller side. Differential revision: https://reviews.llvm.org/D26247 llvm-svn: 285886
2016-11-02Add the rest of the additional error checks for invalid Mach-O files whenKevin Enderby1-19/+103
the offsets and sizes of an element of the Mach-O file overlaps with another element in the Mach-O file. Some other tests for malformed Mach-O files now run into these checks so their tests were also adjusted. llvm-svn: 285860
2016-11-02[lli/COFF] Set the correct alignment for common symbolsDavide Italiano1-0/+9
Otherwise we set it always to zero, which is not correct, and we assert inside alignTo (Assertion failed: Align != 0u && "Align can't be 0."). Differential Revision: https://reviews.llvm.org/D26173 llvm-svn: 285841
2016-11-01[RISCV] Add RISC-V ELF definesAlex Bradbury1-0/+7
Add the necessary definitions for RISC-V ELF files, including relocs. Also make necessary trivial change to ELFYaml, llvm-objdump, and llvm-readobj in order to work with RISC-V ELFs. Differential Revision: https://reviews.llvm.org/D23557 llvm-svn: 285708
2016-10-31More additional error checks for invalid Mach-O files whenKevin Enderby1-5/+52
the offsets and sizes of an element of the file overlaps with another element in the Mach-O file. This shows the approach to this testing for three elements and contains for tests for their overlap. Checking for all the remain elements will be added next. llvm-svn: 285632
2016-10-27Another additional error check for invalid Mach-O files for theKevin Enderby1-0/+26
obsolete load commands. Again the philosophy of the error checking in libObject for Mach-O files, the idea behind the checking is that we never will return a Mach-O file out of libObject that contains unknown things the library code can’t operate on. So known obsolete load commands will cause a hard error. Also to make things clear I have added comments to the values and structures in Support/Mach-O.h and Support/MachO.def as to what is obsolete. As noted in a TODO in the code, there may need to be a non-default mode to allow some unknown values for well structured Mach-O files with things like unknown load load commands. So things like using an old lldb on a newer Mach-O file could still provide some limited functionality. llvm-svn: 285342
2016-10-24nother additional error check for an invalid Mach-O fileKevin Enderby2-11/+34
when contained in a Mach-O universal file and the cputypes in both headers don’t match. llvm-svn: 285026
2016-10-24[Object] Replace TimeValue with std::chronoPavel Labath2-25/+27
Summary: Most of the changes are very straight-forward. The only choice I had to make was to use second-precision time points in the Archive classes. I did this because the archive files use that precision in the on-disk representation anyway. Reviewers: rafael, zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25773 llvm-svn: 284974
2016-10-20Another additional error check for invalid Mach-O files for theKevin Enderby1-0/+34
load commands that use the MachO::twolevel_hints_command type which includes only the LC_TWOLEVEL_HINTS load command. This is not used in llvm libObject code or in llvm tool code. But does appear in one of the binary test files. While this load command is obsolete it is easier to add code for it in libObject than edit or change the binary test case. llvm-svn: 284769
2016-10-19Remove LLVM_NOEXCEPT and replace it with noexceptReid Kleckner1-2/+2
Now that we have dropped MSVC 2013, all supported compilers support noexcept and we can drop this portability macro. llvm-svn: 284672
2016-10-19Next set of additional error checks for invalid Mach-O files for theKevin Enderby1-0/+113
load commands that use the MachO::thread_command type but are not used in llvm libObject code but used in llvm tool code. This includes the LC_UNIXTHREAD and LC_THREAD load commands. A quick note about the philosophy of the error checking in libObject for Mach-O files, the idea behind the checking is that we never will return a Mach-O file out of libObject that contains unknown things in the load commands. To do this the 32-bit ARM and PPC general tread states needed to be defined as two test case binaries contained them. If other thread states for other CPUs need to be added we will do that as needed. Going forward the LC_MAIN load command is used to set the entry point in Mach-O executables these days instead of an LC_UNIXTHREAD as was done in the past. So today only in core files are LC_THREAD load commands and thread states usually found. Other thread states have not yet been defined in include/Support/MachO.h at this time. But that can be added as needed with their corresponding checking also added. llvm-svn: 284668
2016-10-18One more additional error check for invalid Mach-O files for aKevin Enderby1-0/+5
load command that use the MachO:: linkedit_data_command type but is not used in llvm libObject code but used in llvm tool code. This is for the LC_CODE_SIGNATURE load command. llvm-svn: 284529
2016-10-18Next set of additional error checks for invalid Mach-O files for theKevin Enderby1-0/+25
load commands that use the MachO::routines_command and and MachO::routines_command_64 types but are not used in llvm libObject code but used in llvm tool code. This includes the LC_ROUTINES and LC_ROUTINES_64 load commands. llvm-svn: 284504
2016-10-18Object: Add a missing return in ObjectFile::createObjectFileJustin Bogner1-2/+2
When Error was threaded through these APIs back in r265606 the "return" was missed here, which triggers a warning if/when I add LLVM_NODISCARD to the Error type. llvm-svn: 284454
2016-10-17Next set of additional error checks for invalid Mach-O files for theKevin Enderby1-0/+78
load commands that use the MachO::sub_framework_command, MachO::sub_umbrella_command, MachO::sub_library_command and MachO::sub_client_command types but are not used in llvm libObject code but used in llvm tool code. This includes the LC_SUB_FRAMEWORK, LC_SUB_UMBRELLA, LC_SUB_LIBRARY and LC_SUB_CLIENT load commands. llvm-svn: 284431
2016-10-11Next set of additional error checks for invalid Mach-O files for theKevin Enderby1-0/+36
load commands that uses the MachO::linker_option_command type but not used in llvm libObject code but used in llvm tool code. This includes just LC_LINKER_OPTION load command. llvm-svn: 283939
2016-10-05[Object] Fix a crash in Archive::child_iterator's default constructor.Lang Hames1-4/+7
To be default constructible, Archive::child_iterator needs to be able to construct an Archive::Child with a null parent, however Archive::Child's constructor always dereferenced its Parent argument to compute the remaining archive size. This commit fixes Archive::Child's constructor to only do the size calculation when the parent is non-null. llvm-svn: 283387
2016-10-04Next set of additional error checks for invalid Mach-O files for theKevin Enderby1-0/+47
load commands that uses the MachO::encryption_info_command and MachO::encryption_info_command types but not used in llvm libObject code but used in llvm tool code. This includes just LC_ENCRYPTION_INFO and LC_ENCRYPTION_INFO_64 load commands. llvm-svn: 283250
2016-09-30[Object] Define Archive::isEmpty().Rui Ueyama1-1/+4
llvm-svn: 282884
2016-09-29Next set of additional error checks for invalid Mach-O files for theKevin Enderby1-0/+12
load command that uses the MachO::entry_point_command type but not used in llvm libObject code but used in llvm tool code. This includes just the LC_MAIN load command. llvm-svn: 282766