Commit Graph

1102 Commits

Author SHA1 Message Date
Peter Collingbourne
c3f644ae98 ArchiveWriter: Remove unused variables. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297987 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-16 20:35:07 +00:00
Rafael Espindola
22bd70fa31 Archives require a symbol table on Solaris, even if empty.
On Solaris ld (and some other tools that use the underlying utility
libraries, such as elfdump) chokes on an archive library that has no
symbol table. The Solaris tools always create one, even if it's empty.

That bug has been fixed in the latest development line, and can
probably be backported to a supported release, but it would be nice if
LLVM's archiver could emit the empty symbol table, too.

Patch by Danek Duvall!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297773 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-14 19:57:13 +00:00
Teresa Johnson
611bafa4c4 Perform symbol binding for .symver versioned symbols
Summary:
In a .symver assembler directive like:
.symver name, name2@@nodename
"name2@@nodename" should get the same symbol binding as "name".

While the ELF object writer is updating the symbol binding for .symver
aliases before emitting the object file, not doing so when the module
inline assembly is handled by the RecordStreamer is causing the wrong
behavior in *LTO mode.

E.g. when "name" is global, "name2@@nodename" must also be marked as
global. Otherwise, the symbol is skipped when iterating over the LTO
InputFile symbols (InputFile::Symbol::shouldSkip). So, for example,
when performing any *LTO via the gold-plugin, the versioned symbol
definition is not recorded by the plugin and passed back to the
linker. If the object was in an archive, and there were no other symbols
needed from that object, the object would not be included in the final
link and references to the versioned symbol are undefined.

The llvm-lto2 tests added will give an error about an unused symbol
resolution without the fix.

Reviewers: rafael, pcc

Reviewed By: pcc

Subscribers: mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D30485

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297332 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-09 00:19:49 +00:00
Kevin Enderby
505b77004a Actually add error handling to unpacking the dyld compact bind and
other tables.  Providing a helpful error message to what the error is and
where the error occurred based on which opcode it was associated with.

There have been handful of bug fixes dealing with bad bind info in
object files, r294021 and r249845, which only put a band aid on the
problem after a bad bind table was created after unpacking from
its compact info.  In these cases a bind table should have never been
created and an error should have simply been generated.

This change puts in place the plumbing to allow checking and returning
of an error when the compact info is unpacked.  This follows the model
of iterators that can fail that Lang Hanes designed when fixing the problem
for bad archives r275316 (or r275361).

This change uses one of the existing test cases that now causes an
error instead of printing <<bad library ordinal>> after a bad bind table
is created.  The error uses the offset into the opcode table as shown with
the macOS dyldinfo(1) tool to indicate where the error is and which
opcode and which parameter is in error.

For example the exiting test case has this lazy binding opcode table:

% dyldinfo -opcodes test/tools/llvm-objdump/Inputs/bad-ordinal.macho-x86_64 
…
lazy binding opcodes:
0x0000 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB(0x02, 0x00000010)
0x0002 BIND_OPCODE_SET_DYLIB_ORDINAL_IMM(2)

In the test case the binary only has one library so setting the library 
ordinal to the value of 2 in the BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
opcode at 0x0002 above is an error.  This now produces this error message:

% llvm-objdump -lazy-bind bad-ordinal.macho-x86_64 
…
llvm-objdump: 'bad-ordinal.macho-x86_64': truncated or malformed object (for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad library ordinal: 2 (max 1) for opcode at: 0x2)

This change provides the plumbing for the error handling and one example
of an error message.  Other error checks and test cases will be added in follow
on commits.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296527 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-28 21:47:07 +00:00
Rafael Espindola
2504ec9f08 Move llvm_unreachable out of switch.
This should make gcc happy and still produce a clang warning if we add
another value to the enum.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295865 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22 19:42:14 +00:00
Rui Ueyama
9a736108d4 Fix -Wcovered-switch-default.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295799 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22 01:01:45 +00:00
Rafael Espindola
13f0c80b28 Don't modify archive members unless really needed.
For whatever reason ld64 requires that member headers (not the member
themselves) should be aligned. The only way to do that is to edit the
previous member so that it ends at an aligned boundary.

Since modifying data put in an archive is an undesirable property,
llvm-ar should only do it when it is absolutely necessary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295765 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-21 20:40:54 +00:00
Kevin Enderby
0aa6910479 Yet another fix llvm-objdump so it picks a good CPU based for Mach-O files,
in this case for CPU_SUBTYPE_ARM64_ALL.

For this cpusubtype it should default to a cyclone CPU
to give proper disassembly without a -mcpu= flag.

rdar://27767188


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294771 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 19:27:10 +00:00
Rafael Espindola
940b0c036d Move some error handling down to MCStreamer.
This makes sure we get the same redefinition rules regardless of who
is printing (asm parser, codegen) and to what (asm, obj).

This fixes an unintentional regression in r293936.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294752 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 15:13:12 +00:00
Saleem Abdulrasool
3e83030148 Object: pad out BSD archive members to 8-bytes
ld64 requires its archive members to be 8-byte aligned for 64-bit
content and 4-byte aligned for 32-bit content.  Opt for the larger
alignment requirement.  This ensures that ld64 can consume archives
generated by llvm-ar.

Thanks to Kevin Enderby for the hint about the ld64/cctools behaviours!

Resolves PR28361!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294615 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-09 19:29:35 +00:00
Saleem Abdulrasool
1cf80ab83c Object: add a comment explaining a divergence
Add a note about the reason for the divergence from the specification
for ld64.  Addresses post-commit review comments from Davide.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294594 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-09 15:47:58 +00:00
Saleem Abdulrasool
97b3cf4302 Object: pad BSD ar string table to 4-bytes
cctools would pad the string table to a sizeof(int32_t) (explicitly
printed out by cctools rather than 4).  This adjusts the string table to
make it more compatible with cctools, but is insufficient to make ld64
happy.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294557 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-09 04:26:21 +00:00
Eugene Zelenko
3a124c0e3d [MC] Fix some Clang-tidy modernize and Include What You Use warnings in SubtargetFeature; other minor fixes (NFC).
Same changes in files affected by reduced SubtargetFeature.h dependencies.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294548 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-09 01:09:54 +00:00
Kevin Enderby
b1b66d4aca Fix a typo in an error message for a check of invalid Mach-O files where
it was printing the field name fileoff instead of filesize.  The original check
was added in r278557.

This was found in tracking down the problem that lead to the fix in
r293842 - [dsymutil] Fix __LINKEDIT vmsize in dsymutil upgrade path

rdar://30386075


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294354 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-07 21:20:44 +00:00
Derek Schuff
c20099fa53 [WebAssembly] Add wasm support for llvm-readobj
Create a WasmDumper subclass of ObjDumper to support Webassembly binary
files.

Patch by Sam Clegg

Differential Revision: https://reviews.llvm.org/D27355

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293569 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 23:30:52 +00:00
Kevin Enderby
61fed38d43 Fix llvm-objdump so it picks a good CPU based for Mach-O files
for CPU_SUBTYPE_ARM_V7S and CPU_SUBTYPE_ARM_V7K.

For these two cpusubtypes they should default to a cortex-a7 CPU
to give proper disassembly without a -mcpu= flag.

rdar://27431703


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292993 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 23:41:04 +00:00
Kevin Enderby
af0e1c5e93 Add support for the x86_thread_state32_t and
in llvm-objdump for Mach-O files add the printing of the
x86_thread_state32_t in the same format as
otool-classic(1) on darwin.

To do this the 32-bit x86 general tread state
needed to be defined in include/llvm/Support/MachO.h .

rdar://30110111


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292829 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 21:13:29 +00:00
Steven Wu
6d5a027d71 Add LC_BUILD_VERSION load command
Summary:
Add a new load command LC_BUILD_VERSION. It is a generic version of
LC_*_VERSION_MIN load_command used on Apple platforms. Instead of having
a seperate load command for each platform, LC_BUILD_VERSION is recording
platform info as an enum. It also records SDK version, min_os, and tools
that used to build the binary.

rdar://problem/29781291

Reviewers: enderby

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D29044

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292824 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 20:07:55 +00:00
Kevin Enderby
045015ed1f Add support for the new LC_NOTE load command.
It describes a region of arbitrary data included in a Mach-O file.
Its initial use is to record extra data in MH_CORE files.

rdar://30001545
rdar://30001731


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292500 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19 17:36:31 +00:00
Sam Parker
56e5bde913 [ARM] Create SubtargetFeatures from build attrs
An ELFObjectFile can now create SubtargetFeatures from the available
ARM build attributes, in a similar manner to MIPS. I've moved the
MIPS code into its own function and the ARM handler also has a
separate function.

Differential Revision: https://reviews.llvm.org/D28291



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292403 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 15:52:11 +00:00
Sam Parker
aa96763063 [ARM] Create objdump subtarget from build attrs
Enable an ELFObjectFile to read the its arm build attributes to
produce a target triple with a specific ARM architecture.
llvm-objdump now uses this functionality to automatically produce
a more accurate target.

Differential Revision: https://reviews.llvm.org/D28769


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292366 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 13:52:12 +00:00
George Rimar
ef935cd26f Recommit r292214 "[Support/Compression] - Change zlib API to return Error instead of custom status"
No any changes, will follow up with D28807 commit containing APLi change for clang
to fix build issues happened.

Original commit message:
[Support/Compression] - Change zlib API to return Error instead of custom status.

Previously API returned custom enum values.
Patch changes it to return Error with string description.
That should help users to report errors in universal way.

Differential revision: https://reviews.llvm.org/D28684



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292226 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 15:45:07 +00:00
George Rimar
7c0ccdc11d Revert r292214 "[Support/Compression] - Change zlib API to return Error instead of custom status."
It broked clang:
http://lab.llvm.org:8080/green//job/clang-stage1-cmake-RA-incremental_build/34218/consoleFull#46141505449ba4694-19c4-4d7e-bec5-911270d8a58c

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292217 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 13:27:58 +00:00
George Rimar
4a6a534c0c [Support/Compression] - Change zlib API to return Error instead of custom status.
Previously API returned custom enum values.
Patch changes it to return Error with string description.
That should help users to report errors in universal way.

Differential revision: https://reviews.llvm.org/D28684

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292214 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 13:20:17 +00:00
Ivan Krasin
d6d6b83a0b Revert r291903 and r291898. Reason: they break check-lld on the bots.
Summary:
Revert [ARM] Fix ubig32_t read in ARMAttributeParser

Now using support functions to read data instead of trying to
perform casts.
===========================================================

Revert [ARM] Enable objdump to construct triple for ARM

Now that The ARMAttributeParser has been moved into the library,
it has been modified so that it can parse the attributes without
printing them and stores them in a map. ELFObjectFile now queries
the attributes to fill out the architecture details of a provided
triple for 'arm' and 'thumb' targets. llvm-objdump uses this new
functionality.

Subscribers: llvm-commits, samparker, aemerson, mgorny

Differential Revision: https://reviews.llvm.org/D28683

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291911 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 16:45:15 +00:00
Sam Parker
6968dd2f43 [ARM] Enable objdump to construct triple for ARM
Now that The ARMAttributeParser has been moved into the library,
it has been modified so that it can parse the attributes without
printing them and stores them in a map. ELFObjectFile now queries
the attributes to fill out the architecture details of a provided
triple for 'arm' and 'thumb' targets. llvm-objdump uses this new
functionality.

Differential Revision: https://reviews.llvm.org/D28281



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291898 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 11:04:21 +00:00
Davide Italiano
83229eeee3 [lib/Object] Unbreak build with -Werror (unused variable). NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291691 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 19:05:27 +00:00
George Rimar
bdfaae10c4 [lib/Object] - Introduce Decompressor class.
Decompressor intention is to reduce duplication of code.
Currently LLD has own implementation of decompressor
for compressed debug sections.

This class helps to avoid it and share the code.
LLD patch for reusing it is D28106

Differential revision: https://reviews.llvm.org/D28105

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291675 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 15:26:41 +00:00
Saleem Abdulrasool
8204fd7320 llvm-objdump: speed up -objc-meta-data
Running a Debug build of objdump -objc-meta-data with a large Mach-O file is
currently unnecessarily slow.

With some local test input, this change reduces the run time from 75-85s down
to 15-20s.

The two changes are:
  Assert on pointer equality not array equality
  Replace vector<pair<address, symbol>> with DenseMap<address, symbol>

Additionally, use a std::unique_ptr rather than handling the memory manually.

Patch by Dave Lee!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291398 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-08 19:14:15 +00:00
Teresa Johnson
12722f7e6c [ThinLTO] Optionally ignore empty index file
Summary:
In order to simplify distributed build system integration, where actions
may be scheduled before the Thin Link which determines the list of
objects selected by the linker. The gold plugin currently will emit
0-sized index files for objects not selected by the link, to enable
checking for expected output files by the build system. If the build
system then schedules a backend action for these bitcode files, we want
to be able to fall back to normal compilation instead of failing.

This is the LLVM side support for optionally enabling fallback
instead of issuing an error. Return a null CombinedIndex from
llvm::getModuleSummaryIndexForFile under the option when the file
is empty. Clang can then ignore the index when it is null.

Clang patch is D28362.

Reviewers: mehdi_amini

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D28410

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291302 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 23:37:17 +00:00
Kevin Enderby
398ecdfe0a Fix a bugs with using some Mach-O command line flags like "-arch armv7m".
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290001 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16 22:54:02 +00:00
Teresa Johnson
f638013746 [ThinLTO] Import composite types as declarations
Summary:
When reading the metadata bitcode, create a type declaration when
possible for composite types when we are importing. Doing this in
the bitcode reader saves memory. Also it works naturally in the case
when the type ODR map contains a definition for the same composite type
because it was used in the importing module (buildODRType will
automatically use the existing definition and not create a type
declaration).

For Chromium built with -g2, this reduces the aggregate size of the
generated native object files by 66% (from 31G to 10G). It reduced
the time through the ThinLTO link and backend phases by about 20% on
my machine.

Reviewers: mehdi_amini, dblaikie, aprantl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27775

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289993 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16 21:25:01 +00:00
Peter Collingbourne
265ab521b8 Object: Make IRObjectFile own multiple modules and enumerate symbols from all modules.
This implements multi-module support in IRObjectFile.

Differential Revision: https://reviews.llvm.org/D26951

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289578 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-13 20:20:17 +00:00
Peter Collingbourne
e976df103e Object: Remove module accessors from IRObjectFile, and hide its constructor.
Differential Revision: https://reviews.llvm.org/D27079

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289577 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-13 20:10:22 +00:00
Lang Hames
85334ad0c5 [Object][MachO] Reference-ify some helper function arguments. NFC.
Changes all static helper functions in MachOObjectFile.cpp that expect a
non-null MachOObjectFile pointer to take a reference instead.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288608 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-04 01:56:10 +00:00
Pavel Labath
f8e7cdba56 Remove iostream include from WasmObjectFile
The file does not seems to use c++ iostreams (and is is llvm policy to avoid
that). Committing as obvious.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288364 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01 15:20:34 +00:00
Peter Collingbourne
e3134b8c5c Object: Set SF_Indirect in ModuleSymbolTable.
This lets us remove the last use of IRObjectFile::getSymbolGV() in llvm-nm.

Differential Revision: https://reviews.llvm.org/D27076

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288321 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01 07:00:35 +00:00
Peter Collingbourne
71fc8a346a Object: Add SF_Executable symbol flag.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288320 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01 06:53:47 +00:00
Peter Collingbourne
dc61d3e913 Object: Extract a ModuleSymbolTable class from IRObjectFile.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288319 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01 06:51:47 +00:00
David Callahan
bcdc161524 Only computeRelativePath() on new members
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288280 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 22:32:58 +00:00
Derek Schuff
7a578c9156 [WebAssembly] Add llvm-objdump support for wasm file format
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288251 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 16:49:11 +00:00
Kevin Enderby
2431dc2720 Add error checking for Mach-O universal files.
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288084 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-28 22:40:50 +00:00
Peter Collingbourne
045ffc4b32 Object: Add IRObjectFile::getTargetTriple().
This lets us remove a use of IRObjectFile::getModule() in llvm-nm.

Differential Revision: https://reviews.llvm.org/D27074

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287846 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-24 01:13:09 +00:00
Peter Collingbourne
4384b55c02 Object: Simplify the IRObjectFile symbol iterator implementation.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287845 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-24 00:41:05 +00:00
Peter Collingbourne
b9b390899e Object: Make SymbolicFile::symbol_{begin,end}() virtual and remove unnecessary wrappers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287611 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-22 03:38:40 +00:00
Peter Collingbourne
fde9b8bfc2 Object: Simplify; remove unnecessary use of unique_ptr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287305 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-18 03:20:36 +00:00
Peter Collingbourne
0f03473737 Object: replace backslashes with slashes in embedded relative thin archive paths on Windows.
This makes these thin archives portable between *nix and Windows.

Differential Revision: https://reviews.llvm.org/D26696

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287038 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-15 21:36:35 +00:00
Kuba Brecka
4a7eeb4052 Fix llvm-symbolizer to correctly sort a symbol array and calculate symbol sizes
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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287028 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-15 21:07:03 +00:00
Rui Ueyama
648ba5f925 Fix -Wswitch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286920 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-15 00:58:50 +00:00
Rui Ueyama
baf920c9bc Add a file magic for CL.exe's object file created with /GL.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286919 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-15 00:54:54 +00:00
Kevin Enderby
34a869ca6c Add a checkSymbolTable() method to the MachOObjectFile class.
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)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286887 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-14 20:57:04 +00:00
Teresa Johnson
8e04a1bfa5 Restore "[ThinLTO] Prevent exporting of locals used/defined in module level asm"
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286844 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-14 17:12:32 +00:00
Peter Collingbourne
dead081fb2 Bitcode: Change module reader functions to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26562

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286752 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-13 07:00:17 +00:00
Rui Ueyama
6b8a0789f7 Fix -Wpessimizing-move warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286629 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 20:39:02 +00:00
Peter Collingbourne
aeb2eff8d2 Bitcode: Change getModuleSummaryIndex() to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26539

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286624 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 19:50:39 +00:00
Peter Collingbourne
9b252f03d9 Bitcode: Clean up error handling for certain bitcode query functions.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286623 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 19:50:24 +00:00
Teresa Johnson
a547919737 Split Bitcode/ReaderWriter.h into separate reader and writer headers
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286566 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 05:34:58 +00:00
Mehdi Amini
df0b8bce48 Make the Error class constructor protected
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286561 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 04:28:40 +00:00
Davide Italiano
88b31bfeb1 [lli] Simplify the code a bit. No functional change intended.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286555 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 03:07:45 +00:00
Mehdi Amini
129c9fcdb8 Revert "[ThinLTO] Prevent exporting of locals used/defined in module level asm"
This reverts commit r286297.
Introduces a dependency from libAnalysis to libObject, which I missed
during the review.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286329 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 01:45:13 +00:00
Teresa Johnson
92bee0fe98 [ThinLTO] Prevent exporting of locals used/defined in module level asm
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286297 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 21:53:35 +00:00
Peter Collingbourne
5498e18776 IR, Bitcode: Change bitcode reader to no longer own its memory buffer.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286214 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 06:03:43 +00:00
Davide Italiano
2d2f4b6521 [lib/Object] Modernize. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286146 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 21:01:42 +00:00
Kevin Enderby
00b62fb861 Add support for the ARM_THREAD_STATE64 and
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285967 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-03 20:51:28 +00:00
George Rimar
47d5d41c6b [Object/ELF] - Make getSymbol() return Error.
That is consistent with other methods around
and helps to handle error on a caller side.

Differential revision: https://reviews.llvm.org/D26247

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285886 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-03 08:40:55 +00:00
Kevin Enderby
4b3270e0a7 Add the rest of the additional error checks for invalid Mach-O files when
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285860 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 21:08:39 +00:00
Davide Italiano
74a715d8bc [lli/COFF] Set the correct alignment for common symbols
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285841 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 17:32:19 +00:00
Alex Bradbury
49b5e6b8a4 [RISCV] Add RISC-V ELF defines
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285708 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 16:59:37 +00:00
Kevin Enderby
e9885e072b More additional error checks for invalid Mach-O files when
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285632 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-31 20:29:48 +00:00
Kevin Enderby
60923f36b5 Another additional error check for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285342 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-27 20:59:10 +00:00
Kevin Enderby
aa45092c24 nother additional error check for an invalid Mach-O file
when contained in a Mach-O universal file and the
cputypes in both headers don’t match.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285026 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 21:15:11 +00:00
Pavel Labath
6df9562cc0 [Object] Replace TimeValue with std::chrono
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284974 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-24 13:38:27 +00:00
Kevin Enderby
d6842a6b77 Another additional error check for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284769 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-20 20:10:30 +00:00
Reid Kleckner
5b1c9f3223 Remove LLVM_NOEXCEPT and replace it with noexcept
Now that we have dropped MSVC 2013, all supported compilers support
noexcept and we can drop this portability macro.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284672 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-19 23:52:38 +00:00
Kevin Enderby
04e3307190 Next set of additional error checks for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284668 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-19 23:44:34 +00:00
Kevin Enderby
c6b8aca5b5 One more additional error check for invalid Mach-O files for a
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284529 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-18 20:24:12 +00:00
Kevin Enderby
640265dc47 Next set of additional error checks for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284504 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-18 17:54:17 +00:00
Justin Bogner
b3c2bab0a7 Object: Add a missing return in ObjectFile::createObjectFile
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284454 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-18 05:17:23 +00:00
Kevin Enderby
9296e5f5f6 Next set of additional error checks for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284431 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-17 22:09:25 +00:00
Kevin Enderby
9a966692d6 Next set of additional error checks for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283939 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-11 21:04:39 +00:00
Lang Hames
191187346b [Object] Fix a crash in Archive::child_iterator's default constructor.
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.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283387 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-05 21:20:00 +00:00
Kevin Enderby
ec53f4b255 Next set of additional error checks for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283250 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-04 20:37:43 +00:00
Rui Ueyama
eabc8ab76f [Object] Define Archive::isEmpty().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282884 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30 17:54:31 +00:00
Kevin Enderby
c681bf5560 Next set of additional error checks for invalid Mach-O files for the
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282766 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-29 21:07:29 +00:00
Kevin Enderby
9b04a40821 Next set of additional error checks for invalid Mach-O files for the
load command that uses the Mach::source_version_command type
but not used in llvm libObject code but used in llvm tool code.

This includes just the LC_SOURCE_VERSION load command.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282736 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-29 17:45:23 +00:00
Kevin Enderby
dda50f2d84 Next set of additional error checks for invalid Mach-O files for the
load command that uses the Mach::rpath_command type
but not used in llvm libObject code but used in llvm tool code.

This includes just the LC_RPATH load command.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282649 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28 23:16:01 +00:00
Kevin Enderby
a2d2551a8e Next set of additional error checks for invalid Mach-O files for the
other load commands that use the Mach::version_min_command type
but not used in llvm libObject code but used in llvm tool code.

This includes LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS,
LC_VERSION_MIN_TVOS and LC_VERSION_MIN_WATCHOS load commands.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282635 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28 21:20:45 +00:00
Dylan McKay
38e397384e [AVR] Handle AVR relocations when handling ELF files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282586 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28 13:23:42 +00:00
Kevin Enderby
4bc0cbdef8 Next set of additional error checks for invalid Mach-O files for the
other load commands that use the MachO::dylinker_command type
but not used in llvm libObject code but used in llvm tool code.

This includes LC_ID_DYLINKER, LC_LOAD_DYLINKER
and LC_DYLD_ENVIRONMENT load commands.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282553 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-27 23:24:13 +00:00
Kevin Enderby
851d92e233 Next set of additional error checks for invalid Mach-O files for the
other load commands that use the Mach::linkedit_data_command type
but not used in llvm libObject code but used in llvm tool code.

This includes LC_FUNCTION_STARTS, LC_SEGMENT_SPLIT_INFO
and LC_DYLIB_CODE_SIGN_DRS load commands.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282441 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26 21:11:03 +00:00
Kevin Enderby
e10e0e3121 Next set of additional error checks for invalid Mach-O files for bad LC_UUID
load commands.  Added a missing check and made the check for more than
one like other other “more than one” checks.  And of course added test cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282104 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-21 20:03:09 +00:00
Kevin Enderby
7bcdeca5fc Next set of additional error checks for invalid Mach-O files for bad load commands
that use the Mach::dylib_command type for the load commands that are
currently used in the MachOObjectFile constructor.

This contains the missing checks for LC_ID_DYLIB, LC_ID_DYLIB, etc.
load commands and the fields for the Mach::dylib_command type.

Also checks that only an MH_DYLIB or MH_STUB_DYLIB has an
LC_ID_DYLIB load command (and others filetype don’t) and there
is not more than one of these load commands.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282008 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-20 20:14:14 +00:00
Davide Italiano
ad63f23c04 [IRObjectFile] Turn llvm_unreachable("foo") into something more explicative.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281742 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-16 16:07:19 +00:00
Davide Italiano
8471051cc5 [IRObjectFile] Handle undefined weak symbols in RecordStreamer.
Differential Revision:  https://reviews.llvm.org/D24594

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281629 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 17:54:22 +00:00
Kevin Enderby
7402add75d Next set of additional error checks for invalid Mach-O files for bad load commands
that use the Mach::dyld_info_command type for the load commands that are
currently use in the MachOObjectFile constructor.

This contains the missing checks for LC_DYLD_INFO and
LC_DYLD_INFO_ONLY load commands and the fields for the
Mach::dyld_info_command type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281400 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-13 21:42:28 +00:00
Kevin Enderby
f2e0338c22 Next set of additional error checks for invalid Mach-O files for bad load commands
that use the Mach::linkedit_data_command type for the load commands that are
currently used in the MachOObjectFile constructor.

This contains the missing checks for LC_DATA_IN_CODE and
LC_LINKER_OPTIMIZATION_HINT load commands and the fields for the
Mach::linkedit_data_command type.  Checking for other load commands that
use this type will be added later.

Also fixed a couple of places that was using sizeof(MachOObjectFile::LoadCommandInfo)
that should have been using sizeof(MachO::load_command).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280267 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 17:57:46 +00:00
Kevin Enderby
b8c2c1d3ff Next set of additional error checks for invalid Mach-O files for bad LC_DYSYMTAB’s.
This contains the missing checks for LC_DYSYMTAB load command fields.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280161 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-30 21:28:30 +00:00
David Majnemer
99edeba1c3 [COFFObjectFile] Ignore broken symbol table
When binaries are compressed by UPX, information about symbol table
offset and symbol count remain unchanged (but became invalid due to
compression).
This causes failure in the constructor and the rest of the binary cannot
be processed.

Instead, reset symbol related information (symbol/string table pointers,
sizes) - this should disable the related iterators and functions while
the rest of the binary can still be processed.

Patch by Bandzi Michal!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280147 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-30 20:20:24 +00:00
Kevin Enderby
ff19e2b684 Next set of additional error checks for invalid Mach-O files for bad LC_SYMTAB’s.
This contains the missing checks for LC_SYMTAB load command fields.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279854 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 19:34:07 +00:00
NAKAMURA Takumi
fb2d85d005 Reformat.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279409 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 00:58:47 +00:00
NAKAMURA Takumi
805f0aacc0 Untabify.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279408 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 00:58:04 +00:00
Justin Bogner
6673ea81f6 Replace "fallthrough" comments with LLVM_FALLTHROUGH
This is a mechanical change of comments in switches like fallthrough,
fall-through, or fall-thru to use the LLVM_FALLTHROUGH macro instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278902 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 05:10:15 +00:00
Kevin Enderby
296471b040 Next set of additional error checks for invalid Mach-O files.
This contains the two missing checks for LC_SEGMENT load command fields.
And checks for the Mach-O sections fields that would make them invalid.

With the new checks, some of the existing malformed file checks now trips one
of these instead of the issue it was having before so those tests were adjusted.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278557 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-12 20:10:25 +00:00
Rui Ueyama
837032f833 Re-commit r278066: Do not ignore SizeOfOptionalHeader in COFF header even if PE header is not present.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278429 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11 22:02:44 +00:00
Teresa Johnson
2d320e58a9 Restore "Resolution-based LTO API."
This restores commit r278330, with fixes for a few bot failures:
- Fix a late change I had made to the save temps output file that I
  missed due to existing files sitting on my disk
- Fix a bunch of Windows bot failures with "ambiguous call to overloaded
  function" due to confusion between llvm::make_unique vs
  std::make_unique (preface the new make_unique calls with "llvm::")
- Attempt to fix a modules bot failure by adding a missing include
  to LTO/Config.h.

Original change:

Resolution-based LTO API.

Summary:
This introduces a resolution-based LTO API. The main advantage of this API over
existing APIs is that it allows the linker to supply a resolution for each
symbol in each object, rather than the combined object as a whole. This will
become increasingly important for use cases such as ThinLTO which require us
to process symbol resolutions in a more complicated way than just adjusting
linkage.

Patch by Peter Collingbourne.

Reviewers: rafael, tejohnson, mehdi_amini

Subscribers: lhames, tejohnson, mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D20268

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278338 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11 14:58:12 +00:00
Teresa Johnson
6f0ab85031 Revert "Resolution-based LTO API."
This reverts commit r278330.

I made a change to the save temps output that is causing issues with the
bots. Didn't realize this because I had older output files sitting on
disk in my test output directory.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278331 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11 13:03:56 +00:00
Teresa Johnson
9fd977036c Resolution-based LTO API.
Summary:
This introduces a resolution-based LTO API. The main advantage of this API over
existing APIs is that it allows the linker to supply a resolution for each
symbol in each object, rather than the combined object as a whole. This will
become increasingly important for use cases such as ThinLTO which require us
to process symbol resolutions in a more complicated way than just adjusting
linkage.

Patch by Peter Collingbourne.

Reviewers: rafael, tejohnson, mehdi_amini

Subscribers: lhames, tejohnson, mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D20268

Address review comments

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278330 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11 12:56:40 +00:00
Saleem Abdulrasool
b79146f48d CodeView: extract the OMF Directory Header
The DebugDirectory contains a pointer to the CodeView info structure which is a
derivative of the OMF debug directory.  The structure has evolved a bit over
time, and PDB 2.0 used a slightly different definition from PDB 7.0.  Both of
these are specific to CodeView and not COFF.  Reflect this by moving the
structure definitions into the DebugInfo/CodeView headers.  Define a generic
DebugInfo union type that can be used to pass around a reference to the
DebugInfo irrespective of the versioning.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278075 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-09 00:25:12 +00:00
Rui Ueyama
922b42a995 Revert "Do not ignore SizeOfOptionalHeader in COFF header even if PE header is not present."
This reverts commit r278066 to unbreak buildbots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278070 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-08 23:07:03 +00:00
Rui Ueyama
2ea3c70816 Do not ignore SizeOfOptionalHeader in COFF header even if PE header is not present.
Attribute SizeOfOptionalHeader is ignored if no PE header is present
in the file. This attribute should be ignored according to standard,
however there are uses of this field even though it should not be used.

This change does not conform to PE/COFF standard, but there are several
COFF files without PE header, where you had to add up SizeOfOptionalHeader
in order to get proper section headers. Other tools and their own parsers
do take this into account.

Patch by Marek Milkovič!

https://reviews.llvm.org/D22750

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278066 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-08 22:54:22 +00:00
Kevin Enderby
cedb0b6b7e Add the first of what will be a long line of additional error checks for invalid Mach-O files.
This is where an LC_SEGMENT load command has a fileoff field that
extends past the end of the file.

Also fix llvm-nm and llvm-size to remove the errorToErrorCode() call so error messages are printed.
And needed to update a few test cases now that they do print the error messages just a
bit differently.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277845 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-05 18:19:40 +00:00
Kevin Enderby
74bccc3052 Clean up the logic of the Archive::Child::Child() with an assert to know Err is not a nullptr
when we are pointed at real data.

David Blaikie pointed out some odd logic in the case the Err value was a nullptr and
Lang Hames suggested it could be cleaned it up with an assert to know that Err is
not a nullptr when we are pointed at real data.  As only in the case of constructing
the sentinel value by pointing it at null data is Err is permitted to be a nullptr,
since no error could occur in that case.

With this change the testing for “if (Err)” is removed from the constructor’s logic
and *Err is used directly without any check after the assert().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277776 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-04 21:54:19 +00:00
Kevin Enderby
b48816b9fc Clean up of libObject/Archive interfaces and change the last three uses of ErrorOr<>
changing them to Expected<> to allow them to pass through llvm Errors.
No functional change.

This commit by itself will break the next lld builds.  I’ll be committing the
matching change for lld immediately next.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277656 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03 21:57:47 +00:00
Vedant Kumar
e5d157859c Reapply "More fixes to get good error messages for bad archives."
This reverts commit the revert commit r277627. The build errors
mentioned in r277627 were likely caused by an unclean build directory.
Sorry for the noise.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277630 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03 19:02:50 +00:00
Vedant Kumar
a0149b5f2f Revert "More fixes to get good error messages for bad archives."
This reverts commit r277540. It breaks the build with:

../lib/Object/Archive.cpp:264:41: error: return type of out-of-line definition of 'llvm::object::ArchiveMemberHeader::getUID' differs from that in the declaration
Expected<unsigned> ArchiveMemberHeader::getUID() const {
~~~~~~~~~~~~~~~~~~                      ^
include/llvm/Object/Archive.h:53:12: note: previous declaration is here
  unsigned getUID() const;
  ~~~~~~~~ ^

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277627 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03 18:44:32 +00:00
Mehdi Amini
e86c4eb06a RecordStreamer: handle inline asm "lazy_reference" and mark symbols as "used"
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277564 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03 03:51:42 +00:00
Kevin Enderby
d5adfbcabc More fixes to get good error messages for bad archives.
Fixed the last incorrect uses of llvm_unreachable() in the code
which were actually just cases of errors in the input Archives.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277540 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-02 22:58:55 +00:00
David Blaikie
4c028797dc Simplify some code found when it was moved in r277177
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277394 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-01 21:50:43 +00:00
David Majnemer
081d3f18a8 [COFF] Expose iterators for ImportAddressTableRVA
Patch by Bandzi Michal!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277298 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-31 19:40:02 +00:00
David Majnemer
e2fac43a5a [COFF] Remove a duplicate import_directory_table_entry definition
We had import_directory_table_entry and
coff_import_directory_table_entry, remove one.  Also, factor out the
logic which determins if a descriptor is a terminator.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277296 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-31 19:25:21 +00:00
Kevin Enderby
ebd83360ff Think this will fix issues with the error messages generated for malformed-archives.test
in r277177 and added back this test which was deleted in r277196 while
I tracked down these problems.

Changed from constructing Twine's to std::string's as Twine's don't work
across statements.  Also removed a few unneeded Twine() constructions.

Fix the write_escaped() calls to not pass the unintended second argument
fixing the warning on the ld-x86_64-win7 bot.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277223 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-29 22:32:02 +00:00
Kevin Enderby
2a7151766d The next step along the way to getting good error messages for bad archives.
As mentioned in commit log for r276686 this next step is adding a new
method in the ArchiveMemberHeader class to get the full name that
does proper error checking, and can be use for error messages.

To do this the name of ArchiveMemberHeader::getName() is changed to
ArchiveMemberHeader::getRawName() to be consistent with
Archive::Child::getRawName().  Then the “new” method is the addition
of a new implementation of ArchiveMemberHeader::getName() which gets
the full name and provides proper error checking.  Which is mostly a rewrite
of what was Archive::Child::getName() and cleaning up incorrect uses of
llvm_unreachable() in the code which were actually just cases of errors
in the input Archives.

Then Archive::Child::getName() is changed to return Expected<> and use
the new implementation of ArchiveMemberHeader::getName() .

Also needed to change Archive::getMemoryBufferRef() with these
changes to return Expected<> as well to propagate Errors up.
As well as changing Archive::isThinMember() to return Expected<> .


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277177 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-29 17:44:13 +00:00
Kevin Enderby
dc02554240 Next step along the way to getting good error messages for bad archives.
I consulted with Lang Hames on this work, and the goal was to add a bit
of "where" in the archive the error occurred along with what the error was.

So this step changes ArchiveMemberHeader into a class with a pointer
to the archive header and the parent archive.  Which allows the methods
in the ArchiveMemberHeader to determine which member the header is
for to include that information in the error message.

For this first step the "where" is just the offset to the member in the
archive.  The next step will be a new method on ArchiveMemberHeader
to get the full name, if possible, to be use in the error message.  Which
will now be possible as ArchiveMemberHeader contains a pointer to
the Archive with its string table and its size, etc. so the full name can
be determined from the header if it is valid.

Also this change adds the missing checks the archive header is actually
contained in the buffer and is not truncated, as well as if the terminating
characters are correct in the header.

And changes one error message in Archive::Child::getNext() where the
name or offset to member is now added.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276686 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-25 20:36:36 +00:00
Lang Hames
780954376e [Support] Make ErrorAsOutParameter take an Error* rather than an Error&.
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.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276430 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22 16:11:25 +00:00
Kevin Enderby
fa9076153b Next step along the way to getting good error messages for bad archives.
This step builds on Lang Hames work to change Archive::child_iterator
for better interoperation with Error/Expected.  Building on that it is now
possible to return an error message when the size field of an archive
contains non-decimal characters.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276025 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 20:47:07 +00:00
Alexei Starovoitov
36b9c09330 BPF: Use official ELF e_machine value
The same value for EM_BPF is being propagated to glibc,
elfutils, and binutils.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275633 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 22:27:55 +00:00
Lang Hames
36105c0dde [Object] Change Archive::findSym to return an Expected<Optional<Child>>.
As suggested by Rafael in review of D22079 - this was accidentally left out of
the final commit (r275316).



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275469 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-14 20:44:27 +00:00
Lang Hames
aacf2fbfe4 [Object] Re-apply r275316 now that I have the corresponding LLD patch ready.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275361 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-14 02:24:01 +00:00
Lang Hames
5daf897d80 [Object] Revert r275316, Archive::child_iterator changes, while I update lld.
Should fix the bots broken by r275316.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275353 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-14 00:37:04 +00:00
Lang Hames
9b42acafff [Object] Change Archive::child_iterator for better interop with Error/Expected.
See http://reviews.llvm.org/D22079

Changes the Archive::child_begin and Archive::children to require a reference
to an Error. If iterator increment fails (because the archive header is
damaged) the iterator will be set to 'end()', and the error stored in the
given Error&. The Error value should be checked by the user immediately after
the loop. E.g.:

Error Err;
for (auto &C : A->children(Err)) {
  // Do something with archive child C.
}
// Check the error immediately after the loop.
if (Err)
  return Err;

Failure to check the Error will result in an abort() when the Error goes out of
scope (as guaranteed by the Error class).



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275316 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-13 21:13:05 +00:00
Kevin Enderby
ac3d934510 Add checks to the MachOObjectFile() constructor to make sure load commands sizes
are the correct multiple.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274798 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07 22:11:42 +00:00
Saleem Abdulrasool
e88f1b3430 Object: support empty UID/GID fields
Normal archives do not have empty UID/GID fields.  However, the Microsoft
Import library format is a customized archive (it just uses an alternate symbol
index format).  When the import library is constructed by lib.exe, the UID and
GID fields are left empty.  Do not abort on such an input.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274528 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-05 00:23:05 +00:00
Benjamin Kramer
fc44a8b1e4 function_refify. NFC.
While there use emplace_back to create an expensive pair.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274344 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-01 11:05:15 +00:00
Peter Collingbourne
d9613da65c Object: Replace NewArchiveIterator with a simpler NewArchiveMember class. NFCI.
The NewArchiveIterator class has a problem: it requires too much context. Any
memory buffers added to the archive must be stored within an Archive::Member,
which must have an associated Archive. This makes it harder than necessary
to create new archive members (or new archives entirely) from scratch using
memory buffers.

This patch replaces NewArchiveIterator with a NewArchiveMember class that
stores just the memory buffer and the information that goes into the archive
member header.

Differential Revision: http://reviews.llvm.org/D21721

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274183 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-29 22:27:42 +00:00
Kevin Enderby
0b21d88fd3 Change Archive::create() from ErrorOr<...> to Expected<...> and update
its clients.

This commit will break the next lld builds.  I’ll be committing the matching
change for lld next.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274160 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-29 20:35:44 +00:00
Vedant Kumar
3cb7bf5952 [Object] Fix a -Wpessimizing-move error; clang-format; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274085 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-29 00:37:13 +00:00
Kevin Enderby
c827f2cd76 Finish cleaning up most of the error handling in libObject’s 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. 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274079 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-28 23:16:13 +00:00
Kevin Enderby
054620884a Change all but the last ErrorOr<...> use for MachOUniversalBinary to 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273946 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-27 21:39:39 +00:00
David Majnemer
6ea11a40aa [Object, COFF] An import data directory might not consist soley of imports
The last import is the penultimate entry, the last entry is nulled out.
Data beyond the null entry should not be considered to hold import
entries.

This fixes PR28302.

N.B.  I am working on a reduced testcase, the one in PR28302 is too
large.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273790 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-26 04:36:32 +00:00
Kevin Enderby
317de7ce5b Thread Expected<...> up from libObject’s getSymbolAddress() for symbols to allow
a good error message to be produced.

This is nearly the last libObject interface that used ErrorOr and the last one
that appears in llvm/include/llvm/Object/MachO.h .  For Mach-O objects this is
just a clean up because it’s version of getSymbolAddress() can’t return an
error.

I will leave it to the experts on COFF and ELF to actually add meaning full
error messages in their tests if they wish.  And also leave it to these experts
to change the last two ErrorOr interfaces in llvm/include/llvm/Object/ObjectFile.h
for createCOFFObjectFile() and createELFObjectFile() if they wish.

Since there are no test cases for COFF and ELF error cases with respect to
getSymbolAddress() in the test suite this is no functional change (NFC).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273701 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-24 18:24:42 +00:00
Rafael Espindola
c0b76e3114 Make sure Format is always initialized.
Should fix the msan bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273679 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-24 13:47:29 +00:00
Davide Italiano
788062df94 [IRObjectFile] Try to be defensive, add a break.
Suggested by Sean Silva.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273519 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-23 00:07:31 +00:00
Chris Bieneman
1a713c6e05 [MachO] Finish moving fat header swap functions to MachO.h
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273502 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-22 22:19:08 +00:00
Davide Italiano
90107652c0 [IRObjectFile] Propagate .weak attribute correctly for ASM symbols.
PR: 28256
Differential Revision:  http://reviews.llvm.org/D21616


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273474 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-22 20:48:15 +00:00
Kevin Enderby
f5d5db71df Add support for Darwin’s 64-bit universal files with 64-bit offsets and 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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273207 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-20 22:16:18 +00:00
Tom Stellard
7dc79e5898 Support/ELF: Add AMDGPU relocation definitions to match documentation
Reviewers: arsenm, kzhuravl, rafael

Subscribers: llvm-commits, kzhuravl

Differential Revision: http://reviews.llvm.org/D21443

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273066 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 22:38:08 +00:00
Kevin Enderby
68806ff6b6 Add support for Darwin’s static library table of contents with 64-bit offsets to the archive members.
Darwin added support in its Xcode 8.0 tools (released in the beta) for static
library table of contents with 64-bit offsets to the archive members.  The
change is very straight forward.  The table of contents member is named
___.SYMDEF_64 or "___.SYMDEF_64 SORTED" and same layout is used but with
fields using 64 bit values instead of 32 bit values.

rdar://26869808


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273058 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 22:16:06 +00:00
Benjamin Kramer
e5eb673413 Apply another batch of fixes from clang-tidy's performance-unnecessary-value-param.
Contains some manual fixes. No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273047 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 20:41:14 +00:00
Davide Italiano
f57147f09b [IRObjectFile] Handle .weak in RecordStreamer.
Differential Revision:  http://reviews.llvm.org/D21476

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273027 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 18:20:14 +00:00
Daniel Sanders
0b8fc77698 [llvm-objdump] Support detection of feature bits from the object and implement this for Mips.
Summary:
The Mips implementation only covers the feature bits described by the ELF
e_flags so far. Mips stores additional feature bits such as MSA in the
.MIPS.abiflags section.

Also fixed a small bug this revealed where microMIPS wouldn't add the
EF_MIPS_MICROMIPS flag when using -filetype=obj.

Reviewers: echristo, rafael

Subscribers: rafael, mehdi_amini, dsanders, sdardis, llvm-commits

Differential Revision: http://reviews.llvm.org/D21125

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272880 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 09:17:03 +00:00