1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
Commit Graph

132 Commits

Author SHA1 Message Date
Saleem Abdulrasool
9599f4edb3 CodeGen: support an extension to pass linker options on ELF
Introduce an extension to support passing linker options to the linker.
These would be ignored by older linkers, but newer linkers which support
this feature would be able to process the linker.

Emit a special discarded section `.linker-option`.  The content of this
section is a pair of strings (key, value).  The key is a type identifier for
the parameter.  This allows for an argument free parameter that will be
processed by the linker with the value being the parameter.  As an example,
`lib` identifies a library to be linked against, traditionally the `-l`
argument for Unix-based linkers with the parameter being the library name.

Thanks to James Henderson, Cary Coutant, Rafael Espinolda, Sean Silva
for the valuable discussion on the design of this feature.

llvm-svn: 323783
2018-01-30 16:29:29 +00:00
Sam Clegg
06d24e0d9c [llvm-readobj] Consistent use of ScopedPrinter
There were a few places where outs() was being used
directly rather than the ScopedPrinter object.

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

llvm-svn: 322141
2018-01-10 00:14:19 +00:00
Michael Zolotukhin
66a95d7c09 Remove redundant includes from tools.
llvm-svn: 320631
2017-12-13 21:31:10 +00:00
Zachary Turner
62abbe245b Split TypeTableBuilder into two classes.
llvm-svn: 319456
2017-11-30 18:39:50 +00:00
Zachary Turner
df13ea0927 [llvm-readobj] Fix mismatched line endings
llvm-svn: 319453
2017-11-30 18:33:34 +00:00
Aaron Ballman
b071b10879 Add llvm::for_each as a range-based extensions to <algorithm> and make use of it in some cases where it is a more clear alternative to std::for_each.
llvm-svn: 317356
2017-11-03 20:01:25 +00:00
Konstantin Zhuravlyov
eadde56dfb llvm-readobj: Print AMDGPU note contents
Differential Revision: https://reviews.llvm.org/D38752

llvm-svn: 315819
2017-10-14 18:21:42 +00:00
Marek Sokolowski
2b8a5c6709 [llvm-readobj] Teach readobj to dump .res files (WindowsResource).
This enables readobj to output Windows resource files (.res). This way,
we'll be able to test .res outputs without comparing them byte-by-byte
with "magic binary files" generated by MS toolchain.

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

llvm-svn: 313790
2017-09-20 18:33:35 +00:00
Petr Hosek
72231eb582 [llvm-readobj] Install llvm-readelf alias
Install an llvm-readelf symlink to llvm-readobj.
When invoked as *readelf*, default to -elf-output-style=GNU.

Patch by Roland McGrath

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

llvm-svn: 308408
2017-07-19 02:09:37 +00:00
Petr Hosek
d5560f679f [llvm-readobj] Accept (and ignore) --wide (-W) command-line switch
Accept and ignore --wide/-W. In GNU readelf this switch is
necessary to get the output format that's consistent between
32-bit and 64-bit targets. llvm-readobj always produces that
output format.

Patch by Roland McGrath

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

llvm-svn: 308396
2017-07-18 23:58:15 +00:00
Petr Hosek
ef25350bba [llvm-readobj] Accept -S as an alias for --sections
In GNU readelf, the short option for --sections is upper-case -S.

Note that GNU uses lower-case -s to mean --symbols, while LLVM
uses -s to mean --sections and -t to mean --symbols (-t has yet a
different meaning in GNU). So command-line uses with -S can now
be compatible, but uses with -s or -t are still incompatible.

Patch by Roland McGrath

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

llvm-svn: 308392
2017-07-18 23:35:22 +00:00
Reid Kleckner
4846404769 [llvm-readobj] Dump the COFF image load config
This includes the safe SEH tables and the control flow guard function
table. LLD will emit the guard table soon, and I need a tool that dumps
them for testing.

llvm-svn: 305979
2017-06-22 01:10:29 +00:00
Sam Clegg
aaf3055813 [llvm-readobj] Improve errors on invalid binary
The previous code was discarding the error message from
createBinary() by calling errorToErrorCode().
This meant that such error were always reported unhelpfully
as "Invalid data was encountered while parsing the file".

Other tools such as llvm-objdump already produce a more
the error message in this case.

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

llvm-svn: 302664
2017-05-10 14:18:11 +00:00
Zachary Turner
6c7757043d [llvm-readobj] Dump COFF Resources section.
This patch dumps the raw bytes of the .rsrc sections that
are present in COFF object and executable files.  Subsequent
patches will parse this information and dump in a more human
readable format.

Differential Revision: https://reviews.llvm.org/D32463
Patch By: Eric Beckmann

llvm-svn: 301578
2017-04-27 19:38:38 +00:00
Reid Kleckner
5da414c396 [PDB] Split item and type records when merging type streams
Summary: MSVC does this when producing a PDB.

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 298717
2017-03-24 17:26:38 +00:00
Konstantin Zhuravlyov
fb4712fdf8 [AMDGPU] Restructure code object metadata creation
- Rename runtime metadata -> code object metadata
  - Make metadata not flow
  - Switch enums to use ScalarEnumerationTraits
  - Cleanup and move AMDGPUCodeObjectMetadata.h to AMDGPU/MCTargetDesc
  - Introduce in-memory representation for attributes
  - Code object metadata streamer
  - Create metadata for isa and printf during EmitStartOfAsmFile
  - Create metadata for kernel during EmitFunctionBodyStart
  - Finalize and emit metadata to .note during EmitEndOfAsmFile
  - Other minor improvements/bug fixes

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

llvm-svn: 298552
2017-03-22 22:32:22 +00:00
Derek Schuff
85b3f75e18 [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

llvm-svn: 293569
2017-01-30 23:30:52 +00:00
Mehdi Amini
15eaec3325 llvm-readobj: remove leading dash in '-a' option (ARMAttributesShort)
cl::opt does not accept such option

llvm-svn: 290465
2016-12-23 23:54:52 +00:00
Yaxun Liu
98de4b3c84 AMDGPU: Emit runtime metadata version 2 as YAML
Differential Revision: https://reviews.llvm.org/D25046

llvm-svn: 289674
2016-12-14 17:16:52 +00:00
Mehdi Amini
3d0dd0ec2c 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

llvm-svn: 286561
2016-11-11 04:28:40 +00:00
Zachary Turner
064bbdf4f2 [CodeView] Hook up CodeViewRecordIO to type serialization path.
Previously support had been added for using CodeViewRecordIO
to read (deserialize) CodeView type records.  This patch adds
support for writing those same records.  With this patch,
reading and writing of CodeView type records finally uses a single
codepath.

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

llvm-svn: 286304
2016-11-08 22:24:53 +00:00
Mehdi Amini
a6cfd067ac Turn cl::values() (for enum) from a vararg function to using C++ variadic template
The core of the change is supposed to be NFC, however it also fixes
what I believe was an undefined behavior when calling:

 va_start(ValueArgs, Desc);

with Desc being a StringRef.

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

llvm-svn: 283671
2016-10-08 19:41:06 +00:00
Zachary Turner
c2876ae1eb [pdb] Write PDB TPI Stream from Yaml.
This writes the full sequence of type records described in
Yaml to the TPI stream of the PDB file.

Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D24316

llvm-svn: 281063
2016-09-09 17:46:17 +00:00
Saleem Abdulrasool
c4b3302f82 llvm-readobj: add support for printing GNU Notes
Add support for printing the GNU Notes.  This allows an easy way to view the
build id for a binary built with the build id.  Currently, this only handles the
GNU notes, though it would be easy to extend for other note types (default,
FreeBSD, NetBSD, etc).  Only the GNU style is supported currently.

llvm-svn: 280131
2016-08-30 18:52:02 +00:00
Saleem Abdulrasool
1cd17d17bc llvm-readobj: handle import libraries with -coff-exports
`link -dump -exports` lists exported symbols from import libraries as well as
normal dlls.  Ensure that we can handle import libraries as well in
llvm-readobj.

llvm-svn: 279069
2016-08-18 14:32:11 +00:00
Zachary Turner
a3ce9cabee [CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.

For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).

This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.

With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks.  TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.

This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.

Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177

llvm-svn: 277871
2016-08-05 21:45:34 +00:00
Zachary Turner
aa1e2354eb [CodeView] Use llvm::Error instead of std::error_code.
This eliminates the remnants of std::error_code from the
DebugInfo libraries.

llvm-svn: 277758
2016-08-04 19:39:55 +00:00
Saleem Abdulrasool
7da6ab5c08 llvm-readobj: add some more aliases
Alias -d and -t from readelf in llvm-readobj which effectively replaces the
tool.

llvm-svn: 276075
2016-07-20 01:16:28 +00:00
Lang Hames
928a47733c [Object] Re-apply r275316 now that I have the corresponding LLD patch ready.
llvm-svn: 275361
2016-07-14 02:24:01 +00:00
Lang Hames
40892552d6 [Object] Revert r275316, Archive::child_iterator changes, while I update lld.
Should fix the bots broken by r275316.

llvm-svn: 275353
2016-07-14 00:37:04 +00:00
Lang Hames
c4fb566fb8 [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).

llvm-svn: 275316
2016-07-13 21:13:05 +00:00
Kevin Enderby
6e0594e553 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. 

llvm-svn: 274079
2016-06-28 23:16:13 +00:00
Richard Smith
f7f711ffaa Search for llvm-symbolizer binary in the same directory as argv[0], before
looking for it along $PATH. This allows installs of LLVM tools outside of
$PATH to find the symbolizer and produce pretty backtraces if they crash.

llvm-svn: 272232
2016-06-09 00:53:21 +00:00
Reid Kleckner
e95b89db7a [COFF] Expose the PE debug data directory and dump it
This directory is used to find if there is a PDB associated with an
executable. I plan to use this functionality to teach llvm-symbolizer
whether it should use DIA or DWARF to symbolize a given DLL.

Reviewers: majnemer

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

llvm-svn: 271539
2016-06-02 17:10:43 +00:00
Kevin Enderby
945617b128 Change llvm-objdump, llvm-nm and llvm-size when reporting an object file error
when the object is from a slice of a Mach-O Universal Binary use something like
"foo.o (for architecture i386)" as part of the error message when expected.

Also fixed places in these tools that were ignoring object file errors from
MachOUniversalBinary::getAsObjectFile() when the code moved on to see if
the slice was an archive.

To do this MachOUniversalBinary::getAsObjectFile() and
MachOUniversalBinary::getObjectForArch() were changed from returning
ErrorOr<...> to Expected<...> then that was threaded up to its users.

Converting these interfaces to Expected<> from ErrorOr<> does involve
touching a number of places. To contain the changes for now the use of
errorToErrorCode() is still used in two places yet to be fully converted.

llvm-svn: 271332
2016-05-31 20:35:34 +00:00
Kevin Enderby
9024f597c5 Change llvm-objdump, llvm-nm and llvm-size when reporting an object file error
when the object is in an archive to use something like libx.a(foo.o) as part of
the error message.

Also changed llvm-objdump and llvm-size to be like llvm-nm and ignore non-object
files in archives and not produce any error message.

To do this Archive::Child::getAsBinary() was changed from ErrorOr<...> to
Expected<...> then that was threaded up to its users.

Converting this interface to Expected<> from ErrorOr<> does involve
touching a number of places. To contain the changes for now the use of
errorToErrorCode() is still used in one place yet to be fully converted.

Again there some were bugs in the existing code that did not deal with the
old ErrorOr<> return values.  So now with Expected<> since they must be
checked and the error handled, I added a TODO and a comments for those.

llvm-svn: 269784
2016-05-17 17:10:12 +00:00
Reid Kleckner
79a13a2ef0 [codeview] Add type stream merging prototype
Summary:
This code is intended to be used as part of LLD's PDB writing. Until
that exists, this is exposed via llvm-readobj for testing purposes.

Type stream merging uses the following algorithm:

- Begin with a new empty stream, and a new empty hash table that maps
  from type record contents to new type index.
- For each new type stream, maintain a map from source type index to
  destination type index.
- For each record, copy it and rewrite its type indices to be valid in
  the destination type stream.
- If the new type record is not already present in the destination
  stream hash table, append it to the destination type stream, assign it
  the next type index, and update the two hash tables.
- If the type record already exists in the destination stream, discard
  it and update the type index map to forward the source type index to
  the existing destination type index.

Reviewers: zturner, ruiu

Subscribers: llvm-commits

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

llvm-svn: 269521
2016-05-14 00:02:53 +00:00
Simon Atanasyan
eba22b7e3c [llvm-readobj] Print MIPS .MIPS.options section content
.MIPS.options section specifies miscellaneous options to be applied
to an object file. LLVM as well as modern versions of GNU tools emit
the only type of the options - ODK_REGINFO. The patch teaches llvm-readobj
to print details of the ODK_REGINFO and skip contents of other options.

llvm-svn: 268478
2016-05-04 05:58:57 +00:00
Zachary Turner
6491f0eb80 Move llvm-readobj/StreamWriter to Support.
We wish to re-use this from llvm-pdbdump, and it provides a nice
way to print structured data in scoped format that could prove
useful for many other dumping tools as well.  Moving to support
and changing name to ScopedPrinter to better reflect its purpose.

llvm-svn: 268342
2016-05-03 00:28:04 +00:00
Hemant Kulkarni
6e8f9c1c5f [llvm-readobj] Add ELF hash histogram printing
Differential Revision: http://reviews.llvm.org/D18907

llvm-svn: 265967
2016-04-11 17:15:30 +00:00
Kevin Enderby
a6534d0295 Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump to produce a real error message
Produce the first specific error message for a malformed Mach-O file describing
the problem instead of the generic message for object_error::parse_failed of
"Invalid data was encountered while parsing the file”.  Many more good error
messages will follow after this first one.

This is built on Lang Hames’ great work of adding the ’Error' class for
structured error handling and threading Error through MachOObjectFile
construction.  And making createMachOObjectFile return Expected<...> .

So to to get the error to the llvm-obdump tool, I changed the stack of
these methods to also return Expected<...> :

  object::ObjectFile::createObjectFile()
  object::SymbolicFile::createSymbolicFile()
  object::createBinary()

Then finally in ParseInputMachO() in MachODump.cpp the error can
be reported and the specific error message can be printed in llvm-objdump
and can be seen in the existing test case for the existing malformed binary
but with the updated error message.

Converting these interfaces to Expected<> from ErrorOr<> does involve
touching a number of places. To contain the changes for now use of
errorToErrorCode() and errorOrToExpected() are used where the callers
are yet to be converted.

Also there some were bugs in the existing code that did not deal with the
old ErrorOr<> return values.  So now with Expected<> since they must be
checked and the error handled, I added a TODO and a comment:
“// TODO: Actually report errors helpfully” and a call something like
consumeError(ObjOrErr.takeError()) so the buggy code will not crash
since needed to deal with the Error.

Note there is one fix also needed to lld/COFF/InputFiles.cpp that goes along
with this that I will commit right after this.  So expect lld not to built
after this commit and before the next one.

llvm-svn: 265606
2016-04-06 22:14:09 +00:00
Tim Northover
352af6b0a6 Fix typo. NFC.
llvm-svn: 262405
2016-03-01 21:45:22 +00:00
Hemant Kulkarni
2e703c67d0 [llvm-readobj] Option to emit readelf like output
New option --elf-output-style=LLVM or GNU
Enables -file-headers in readelf style when elf-output-style=GNU

Differential revision: http://reviews.llvm.org/D14128

llvm-svn: 260430
2016-02-10 20:40:55 +00:00
Hemant Kulkarni
7bee7c2cd0 Revert "[llvm-readobj] Option to emit readelf like output"
This reverts commit a58765909660a7195b32e0cc8c7476168b913750.

llvm-svn: 260397
2016-02-10 18:21:01 +00:00
Hemant Kulkarni
212037f7cf [llvm-readobj] Option to emit readelf like output
New option --elf-output-style=LLVM or GNU
Enables -file-headers in readelf style when elf-output-style=GNU

Differential revision: http://reviews.llvm.org/D14128

llvm-svn: 260391
2016-02-10 17:51:28 +00:00
Hemant Kulkarni
e89fec8eee [llvm-readobj] Add -elf-section-groups option
Adds a way to inspect SHT_GROUP sections in ELF objects.
Displays signature, member sections of these sections.

Differential revision: http://reviews.llvm.org/D16555

llvm-svn: 258845
2016-01-26 19:46:39 +00:00
Davide Italiano
55611bd554 [llvm-readobj] Use stderr and not stdout for error messages.
llvm-svn: 256347
2015-12-23 19:29:34 +00:00
Reid Kleckner
a0000e2429 Reland "[llvm-readobj] Simplify usage of -codeview flag"
Relands r255790 with fixed tests.

llvm-svn: 255793
2015-12-16 18:28:12 +00:00
Reid Kleckner
e80fed4166 Revert "[llvm-readobj] Simplify usage of -codeview flag"
This reverts commit r255790.

llvm-svn: 255791
2015-12-16 18:19:34 +00:00
Reid Kleckner
958c5136d5 [llvm-readobj] Simplify usage of -codeview flag
llvm-svn: 255790
2015-12-16 18:18:39 +00:00