1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00
Commit Graph

420 Commits

Author SHA1 Message Date
Georgii Rymar
8150e1e4ce [llvm-readobj/llvm-readelf] - Simplify the code that dumps versions.
After changes introduced in D70495 and D70826 its now possible
to significantly simplify the code we have.

This also fixes an issue: previous code assumed that version strings
should always be read from the dynamic string table. While it is
normally true, the string table should be taken from the corresponding
sh_link field.

Differential revision: https://reviews.llvm.org/D70855
2019-12-02 15:14:30 +03:00
Georgii Rymar
1ce68f67b9 [llvm-readelf/llvm-readobj] - Check the version of SHT_GNU_verneed section entries.
It is a follow-up for D70826 and it is similar to D70810.

SHT_GNU_verneed contains the following fields:
`vn_version`: Version of structure. This value is currently set to 1, and will be reset
if the versioning implementation is incompatibly altered.
(https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/symversion.html)

We should check it for correctness.

Differential revision: https://reviews.llvm.org/D70842
2019-12-02 12:57:23 +03:00
Georgii Rymar
7c3b5b40df [llvm-readobj/llvm-readelf] - Reimplement dumping of the SHT_GNU_verneed section.
This is similar to D70495, but for SHT_GNU_verneed section.
It solves the same problems: different implementations, lack of error reporting
and no test coverage.

DIfferential revision: https://reviews.llvm.org/D70826
2019-12-02 12:27:31 +03:00
Georgii Rymar
ca244599d2 [llvm-readelf/llvm-readobj] - Check version of SHT_GNU_verdef section entries when dumping.
Elfxx_Verdef contains the following field:

vd_version
Version revision. This field shall be set to 1.
(https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/symversion.html)

Our code should check the struct version for correctness. This patch does that.
(This will help to simplify or eliminate ELFDumper<ELFT>::LoadVersionDefs() which
has it's own logic to parse version definitions for no reason. It checks the
struct version currently).

Differential revision: https://reviews.llvm.org/D70810
2019-11-29 11:09:56 +03:00
Georgii Rymar
63432001d0 [llvm-readelf] - Make GNU style dumping of invalid SHT_GNU_verdef be consistent with LLVM style.
When we dump SHT_GNU_verdef section that has sh_link that references a non-existent section,
llvm-readobj reports a warning and continues dump, but llvm-readelf fails with a error.

This patch fixes the issue and opens road for futher follow-ups for
improving the printGNUVersionSectionProlog().

Differential revision: https://reviews.llvm.org/D70776
2019-11-28 12:41:29 +03:00
Georgii Rymar
d849bd18c8 [llvm-readobj] - Always print "Predecessors" for version definition sections.
This is a follow-up discussed in D70495 thread.

The current logic is unusual for llvm-readobj. It doesn't print predecessors
list when it is empty. This is not good for machine parsers.
D70495 had to add this condition during refactoring to reduce amount of changes,
in tests, because the original code also had a similar logic.

Now seems it is time to get rid of it. This patch does it.

Differential revision: https://reviews.llvm.org/D70717
2019-11-27 12:29:55 +03:00
Georgii Rymar
39d296957d [llvm-readobj/llvm-readelf] - Reimplement dumping of the SHT_GNU_verdef section.
Currently we have following issues:
1) We have 2 different implementations with a different behaviors for GNU/LLVM styles.
2) Errors are either not handled at all or we call report_fatal_error with not helpfull messages.
3) There is no test coverage even for those errors that are reported.

This patch reimplements parsing of the SHT_GNU_verdef section entries
in a single place, adds a few error messages and test coverage.

Differential revision: https://reviews.llvm.org/D70495
2019-11-26 17:15:39 +03:00
Georgii Rymar
d833762862 [llvm-readobj] - Improve dumping of the SHT_LLVM_LINKER_OPTIONS sections.
I've added a few tests that shows how the current code could overrun the section data
buffer while dumping. I had to rewrite the code to fix this.

Differential revision: https://reviews.llvm.org/D70112
2019-11-20 12:11:13 +03:00
Georgii Rymar
ca203ebeb8 [llvm-readobj/llvm-readelf] - Improve dumping of versioning sections.
Our elf-versioninfo.test is not perfect. It does not properly test how
flags are dumped and also we have a bug: they are dumped as enums in
LLVM style now, i.e not dumped properly.

GNU style uses a `versionFlagToString` method to build a string from flags
which seems is consistent with GNU readelf.

In this patch I fixed the issues mentioned.

Differential revision: https://reviews.llvm.org/D70399
2019-11-20 11:55:55 +03:00
James Henderson
8d3710516b [llvm-readobj] Change errors to warnings for symbol section name dumping
Also only print each such warning once.

LLVM-style output will now print "<?>" for sections it cannot identify,
e.g. because the section index is invalid. GNU output continues to print
the raw index. In both cases where the st_shndx value is SHN_XINDEX and
the index cannot be looked up in the SHT_SYMTAB_SHNDX section (e.g.
because it is missing), the symbol is printed like other symbols with
st_shndx >= SHN_LORESERVE.

Reviewed by: grimar, MaskRay

Differential Revision: https://reviews.llvm.org/D69671
2019-11-04 12:04:04 +00:00
James Henderson
f832a4b9a9 [NFC][llvm-readobj] Split getSectionIndexName function into two
getSectionIndexName was trying to fetch two things at once, which led to
a somewhat tricky to understand interface involving passing output
parameters in, and also made it hard to return Errors further up the
stack.

This change is in preparation for changing the error handling.

Additionally, update a related test now that yaml2obj supports
SHT_SYMTAB_SHNDX properly (see d3963051c490), and add missing LLVM-style
coverage for symbols with shndx SHN_XINDEX. This test (after fixing)
caught a mistake in my first attempt at this patch, hence I'm including
it as part of this patch.

Reviewed by: grimar, MaskRay

Differential Revision: https://reviews.llvm.org/D69670
2019-11-01 11:48:31 +00:00
James Henderson
800b92e1ca [NFC][llvm-readobj] Pull common code into a helper
This will make planned changes to this code easier to make.

Reviewed by: MaskRay, grimar

Differential Revision: https://reviews.llvm.org/D69669
2019-11-01 11:48:31 +00:00
Georgii Rymar
35b550c13e [llvm-readelf/llvm-readobj] - Improve dumping of broken versioning sections.
This updates the elf-invalid-versioning.test test case:
makes a cleanup, adds llvm-readobj calls and fixes 2
crash/assert issues I've found (test cases are provided).

Differential revision: https://reviews.llvm.org/D68705
2019-10-31 12:12:17 +03:00
George Rimar
9459104c4d [llvm/Object] - Make ELFObjectFile::getRelocatedSection return Expected<section_iterator>
It returns just a section_iterator currently and have a report_fatal_error call inside.
This change adds a way to return errors and handle them on caller sides.

The patch also changes/improves current users and adds test cases.

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

llvm-svn: 375408
2019-10-21 11:06:38 +00:00
George Rimar
9fbc4f59a7 [llvm-readobj] - Refine the LLVM-style output to be consistent.
Our LLVM-style output was inconsistent.
This patch changes the output in the following way:

SHT_GNU_verdef { -> VersionDefinitions [
SHT_GNU_verneed { -> VersionRequirements [
Version symbols [ -> VersionSymbols [
EH_FRAME Header [ -> EHFrameHeader {

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

llvm-svn: 375095
2019-10-17 10:23:48 +00:00
George Rimar
6bff65cac4 [llvm-readobj] - Remove excessive fields when dumping "Version symbols".
This removes a few fields that are not useful:
"Section Name", "Address", "Offset" and "Link"
(they duplicated the information available under
the "Sections [" tag).

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

llvm-svn: 374541
2019-10-11 12:27:11 +00:00
George Rimar
c1874049a8 [llvm-readelf] - Do not enter an infinite loop when printing histogram.
This is similar to D68086.
We are entering an infinite loop when dumping a histogram for a specially crafted
.hash section with a loop in a chain.

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

llvm-svn: 374344
2019-10-10 13:26:26 +00:00
George Rimar
d34a265180 [llvm-readelf/llvm-objdump] - Improve/refactor the implementation of SHT_LLVM_ADDRSIG section dumping.
This patch:

* Adds a llvm-readobj/llvm-readelf test file for SHT_LLVM_ADDRSIG sections. (we do not have any)
* Enables dumping of SHT_LLVM_ADDRSIG with --all.
* Changes the logic to report a warning instead of an error when something goes wrong during dumping
  (allows to continue dumping SHT_LLVM_ADDRSIG and other sections on error).
* Refactors a piece of logic to a new toULEB128Array helper which might be used for GNU-style
  dumping implementation.

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

llvm-svn: 373890
2019-10-07 10:29:38 +00:00
Simon Atanasyan
158935aa29 [llvm-readobj] Remove redundant semicolon. NFC
llvm-svn: 373735
2019-10-04 12:08:10 +00:00
Simon Atanasyan
58cf765cf6 [llvm-readobj][mips] Inline printMipsPLTGOT method
llvm-svn: 373733
2019-10-04 11:59:23 +00:00
Simon Atanasyan
bd5840681b [llvm-readobj][mips] Implement GNU-style printing of .MIPS.abiflags section
In this patch `llvm-readobj` prints ASEs flags on a single line
separated by a comma. GNU `readelf` prints each ASEs flag on
a separate line. It will be fixed later.

llvm-svn: 373732
2019-10-04 11:59:16 +00:00
Simon Atanasyan
861303204d [llvm-readobj] Replace arch-specific ObjDumper methods by the single printArchSpecificInfo
Initially llvm-readobj supports multiple command line options like
`--arm-attributes` and `--mips-plt-got` for display ELF arch-specific
information. Now all these options are superseded by the
`--arch-specific` one. It makes sense to have a single `printArchSpecificInfo`
method in the base `ObjDumper`, and hide all ELF/target specific details
in the `ELFDumper::printArchSpecificInfo` override.

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

llvm-svn: 373731
2019-10-04 11:59:06 +00:00
Simon Atanasyan
04544fff7f [llvm-readobj][mips] Do not show an error if GOT is missed
It is not an error if a file does not contain GOT.

llvm-svn: 373587
2019-10-03 12:06:56 +00:00
George Rimar
62c923265b [llvm-readelf] - Report a warning when .hash section contains a chain with a cycle.
It is possible to craft a .hash section that triggers an infinite loop
in llvm-readelf code. This patch fixes the issue and introduces
a warning.

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

llvm-svn: 373476
2019-10-02 14:11:35 +00:00
George Rimar
bb863a6357 [llvm-readobj/llvm-readelf] - .stack_sizes: demangle symbol names in warnings reported.
I started this patch as a refactoring, tried to make a helper for
getting symbol names, similar to how we get section names
used in warning messages.

So this patch cleanups the code and fixes an issue: symbol names
in warning messages were not demangled.

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

llvm-svn: 372867
2019-09-25 13:16:43 +00:00
George Rimar
c0e784aa57 [llvm-readobj] - Don't crash when dumping .stack_sizes and unable to find a relocation resolver.
The crash might happen when we have either a broken or unsupported object
and trying to resolve relocations when dumping the .stack_sizes section.

For the test case I used a 32-bits ELF header and a 64-bit relocation.
In this case a null pointer is returned by the code instead of the relocation
resolver function and then we crash.

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

llvm-svn: 372838
2019-09-25 10:14:50 +00:00
George Rimar
266885b489 [llvm-readobj] - Stop treating ".stack_sizes.*" sections as stack sizes sections.
llvm-readobj currently handles .stack_sizes.* (e.g. .stack_sizes.foo)
as a normal stack sizes section. Though MC does not produce sections with
such names. Also, linkers do not combine .stack_sizes.* into .stack_sizes.

A mini discussion about this correctness issue is here: https://reviews.llvm.org/D67757#inline-609274
This patch changes implementation so that only now only '.stack_sizes' name is
accepted as a real stack sizes section.

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

llvm-svn: 372578
2019-09-23 10:43:09 +00:00
George Rimar
ea118e0f80 [llvm-readobj] - Implement LLVM-style dumping for .stack_sizes sections.
D65313 implemented GNU-style dumping (llvm-readelf).
This one implements LLVM-style dumping (llvm-readobj).

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

llvm-svn: 372576
2019-09-23 10:33:19 +00:00
Fangrui Song
9ccaf1473c [Support] Add a DataExtractor constructor that takes ArrayRef<uint8_t>
The new constructor can simplify some llvm-readobj call sites.

Reviewed By: grimar, dblaikie

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

llvm-svn: 372473
2019-09-21 15:05:03 +00:00
George Rimar
dfd6c321a6 [llvm-readobj/llvm-objdump] - Improve how tool locate the dynamic table and report warnings about that.
Before this patch we gave a priority to a dynamic table found
from the section header.

It was discussed (here: https://reviews.llvm.org/D67078?id=218356#inline-602082)
that probably preferring the table from PT_DYNAMIC is better,
because it is what runtime loader sees.

This patch makes the table from PT_DYNAMIC be chosen at first place if it is available.
But also it adds logic to fall back to SHT_DYNAMIC if the table from the dynamic segment is
broken or fall back to use no table if both are broken.

It adds a few more diagnostic warnings for the logic above.

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

llvm-svn: 372122
2019-09-17 13:58:46 +00:00
George Rimar
008671759e [llvm-readobj] - Refactor the code.
It's a straightforward refactoring that allows to simplify and encapsulate the code.

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

llvm-svn: 372083
2019-09-17 08:53:18 +00:00
George Rimar
e10ef99eec [llvm-readelf] - Print unknown st_other value if present in GNU output.
This is a fix for https://bugs.llvm.org/show_bug.cgi?id=40785.

llvm-readelf does not print the st_value of the symbol when
st_value has any non-visibility bits set.

This patch:

* Aligns "Ndx" row for the default and a new cases.
(it was 1 space character off for the case when "PROTECTED" visibility was printed)

* Prints "[<other>: 0x??]" for symbols which has an additional st_other bits set.
In compare with GNU, this logic is a bit simpler and seems to be more consistent.

For MIPS GNU can print named flags, though can't print a mix of them:
0: 00000000 0 NOTYPE LOCAL DEFAULT UND 
1: 00000000 0 NOTYPE GLOBAL DEFAULT [OPTIONAL] UND a1
2: 00000000 0 NOTYPE GLOBAL DEFAULT [MIPS PLT] UND a2
3: 00000000 0 NOTYPE GLOBAL DEFAULT [MIPS PIC] UND a3
4: 00000000 0 NOTYPE GLOBAL DEFAULT [MICROMIPS] UND a4
5: 00000000 0 NOTYPE GLOBAL DEFAULT [MIPS16] UND a5
6: 00000000 0 NOTYPE GLOBAL DEFAULT [<other>: c] UND b1
7: 00000000 0 NOTYPE GLOBAL DEFAULT [<other>: 28] UND b2

On PPC64 it can print a localentry value that is encoded in the high bits of st_other
63: 0000000000000850 208 FUNC GLOBAL DEFAULT [<localentry>: 8] 12

We chose to print the raw st_other field, prefixed with '0x'.

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

llvm-svn: 371201
2019-09-06 13:05:34 +00:00
Fangrui Song
2a1caa980a [llvm-readobj][yaml2obj] Support SHT_LLVM_SYMPART, SHT_LLVM_PART_EHDR and SHT_LLVM_PART_PHDR
See http://lists.llvm.org/pipermail/llvm-dev/2019-February/130583.html
and D60242 for the lld partition feature.

This patch:

* Teaches yaml2obj to parse the 3 section types.
* Teaches llvm-readobj/llvm-readelf to dump the 3 section types.

There is no test for SHT_LLVM_DEPENDENT_LIBRARIES in llvm-readobj. Add
it as well.

Reviewed By: thakis

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

llvm-svn: 371157
2019-09-06 00:53:28 +00:00
George Rimar
2e7c3b12d7 [llvm-readelf] - Allow dumping dynamic symbols when there is no program headers.
D62179 introduced a regression. llvm-readelf lose the ability to dump the dynamic symbols
when there is .dynamic section with a DT_SYMTAB, but there are no program headers:
https://reviews.llvm.org/D62179#1652778

Below is a program flow before the D62179 change:

1) Find SHT_DYNSYM.
2) Find there is no PT_DYNAMIC => don't try to parse it.
3) Print dynamic symbols using information about them found on step (1).

And after the change it became:

1) Find SHT_DYNSYM.
2) Find there is no PT_DYNAMIC => find SHT_DYNAMIC.
3) Parse dynamic table, but fail to handle the DT_SYMTAB because of the absence of the PT_LOAD. Report the "Virtual address is not in any segment" error.

This patch fixes the issue. For doing this it checks that the value of DT_SYMTAB was
mapped to a segment. If not - it ignores it.

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

llvm-svn: 371071
2019-09-05 14:02:58 +00:00
George Rimar
2fdfc9c726 [llvm-readobj/llvm-readelf] - Report a proper warning when dumping a broken dynamic relocation.
When we have a dynamic relocation with a broken symbol's st_name,
tools report a useless error: "Invalid data was encountered while parsing the file".

After this change we report a warning + "<corrupt>" as a symbol name.

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

llvm-svn: 370330
2019-08-29 10:55:57 +00:00
George Rimar
f05e457a4a [llvm-readobj] - Remove reportError(std::error_code EC, StringRef Input) helper.
We do not need it, std::error_code is used mostly for COFF and
this patch rewrites the calls to use a different overload.

Having reportError(std::error_code EC, ... is excessive by itself,
because API that use error codes actually needs refactoring to
use Error/Expected<> instead.

DIfferential revision: https://reviews.llvm.org/D66521

llvm-svn: 369630
2019-08-22 08:56:24 +00:00
George Rimar
09776aab5d Recommit r369190 "[llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API."
Fix: Add a `consumeError` call removed by mistake to 'printStackSize',
this should fix the "Expected<T> must be checked before access or destruction." reported by following bot:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio

Original commit message:
Currently we have the following functions for error reporting:

LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(Error Err, StringRef Input); 
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);

Problems are: naming is inconsistent, arguments order is inconsistent,
some of the functions looks excessive.

After applying this patch we have:

void reportError(Error Err, StringRef Input); 
void reportError(std::error_code EC, StringRef Input);
void reportWarning(Error Err, StringRef Input);

I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it
is used by COFF heavily.

Test cases were updated, they show an improvement introduced.

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

llvm-svn: 369194
2019-08-17 16:07:18 +00:00
George Rimar
602860ff2d Revert r369190, r369192 ([llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API.)
It caused multiple BB failtures:

http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/26042/steps/ninja%20check%201/logs/FAIL%3A%20LLVM%3A%3Astack-sizes.test

llvm-svn: 369193
2019-08-17 15:36:06 +00:00
George Rimar
bdd80e6afb [llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API.
urrently we have the following functions for error reporting:

--
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(Error Err, StringRef Input); 
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);
---

Problems are: naming is inconsistent, arguments order is inconsistent,
some of the functions looks excessive.

After applying this patch we have:

---
LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input); 
LLVM_ATTRIBUTE_NORETURN void reportError(std::error_code EC, StringRef Input);
void reportWarning(Error Err, StringRef Input);
---

I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it
is used by COFF heavily.

Test cases were updated, they show an improvement introduced.

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

llvm-svn: 369190
2019-08-17 14:36:40 +00:00
Petr Hosek
353f33d2f8 [llvm-readobj] Unwrap the value first to avoid the error
This addresses the issue introduced in r369169, we need to unwrap
the value first before we can check whether it's empty. This also
swaps the two branches to put the common path first which should
be NFC.

llvm-svn: 369177
2019-08-17 00:07:26 +00:00
Petr Hosek
e14c8f4aaf [llvm-readobj] Fallback to PT_NOTE if file doesn't have sections
This is useful when trying to read notes from stripped files and matches
the behavior of GNU readelf and eu-readelf.

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

llvm-svn: 369169
2019-08-16 23:15:40 +00:00
George Rimar
21610566c8 Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
Changes: no changes. A fix for the clang code will be landed right on top.

Original commit message:

SectionRef::getName() returns std::error_code now.
Returning Expected<> instead has multiple benefits.

For example, it forces user to check the error returned.
Also Expected<> may keep a valuable string error message,
what is more useful than having a error code.
(Object\invalid.test was updated to show the new messages printed.)

This patch makes a change for all users to switch to Expected<> version.

Note: in a few places the error returned was ignored before my changes.
In such places I left them ignored. My intention was to convert the interface
used, and not to improve and/or the existent users in this patch.
(Though I think this is good idea for a follow-ups to revisit such places
and either remove consumeError calls or comment each of them to clarify why
it is OK to have them).

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

llvm-svn: 368826
2019-08-14 11:10:11 +00:00
George Rimar
f64562dc67 Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455

llvm-svn: 368813
2019-08-14 08:56:55 +00:00
George Rimar
3a9b0e354d [llvm/Object] - Convert SectionRef::getName() to return Expected<>
SectionRef::getName() returns std::error_code now.
Returning Expected<> instead has multiple benefits.

For example, it forces user to check the error returned.
Also Expected<> may keep a valuable string error message,
what is more useful than having a error code.
(Object\invalid.test was updated to show the new messages printed.)

This patch makes a change for all users to switch to Expected<> version.

Note: in a few places the error returned was ignored before my changes.
In such places I left them ignored. My intention was to convert the interface
used, and not to improve and/or the existent users in this patch.
(Though I think this is good idea for a follow-ups to revisit such places
and either remove consumeError calls or comment each of them to clarify why
it is OK to have them).

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

llvm-svn: 368812
2019-08-14 08:46:54 +00:00
Alex Langford
88fae211c4 [NFCI] Explicitly provide user-defined constructor for SectionRef
I am changing this to work around an issue that is being hit when
building with clang 3.8. Specifically, clang 3.8 requires that we have a user
defined default constructor for SectionRef for the default initialization of a
const SectionRef.

llvm-svn: 368758
2019-08-13 22:16:18 +00:00
Jordan Rupprecht
3abe0b3ab9 [llvm-readelf] Implement note parsing for NT_FILE and unknown descriptors
Summary:
This patch implements two note parsers; one for NT_FILE coredumps, e.g.:

```
  CORE                  0x00000080      NT_FILE (mapped files)
    Page size: 4096
                 Start                 End         Page Offset
    0x0000000000001000  0x0000000000002000  0x0000000000003000
        /path/to/a.out
    0x0000000000004000  0x0000000000005000  0x0000000000006000
        /path/to/libc.so
    0x0000000000007000  0x0000000000008000  0x0000000000009000
        [stack]
```

(A more realistic example can be tested locally by creating a crashing program and running `llvm-readelf -n core`)

And also implements a raw hex dump for unknown descriptor data for unhandled descriptor types.

Reviewers: MaskRay, jhenderson, grimar, alexshap

Reviewed By: MaskRay, grimar

Subscribers: emaste, llvm-commits, labath

Tags: #llvm

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

llvm-svn: 368698
2019-08-13 14:38:45 +00:00
George Rimar
cb83c675d9 [llvm-readobj] - Remove 'error(Error EC)' helper.
We do not need it. I replaced it with
reportError(StringRef Input, Error Err).

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

llvm-svn: 368677
2019-08-13 12:07:41 +00:00
Jordan Rupprecht
0d351d4f7c [llvm-readobj] Downgrade 'PT_DYNAMIC segment offset + size exceeds the size of the file' from an error to a warning
Summary: This allows llvm-readobj to print other useful information for truncated files instead of giving up.

Reviewers: jhenderson, grimar, MaskRay

Reviewed By: jhenderson, grimar, MaskRay

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 368576
2019-08-12 14:05:37 +00:00
George Rimar
da9ac1c3d1 [llvm-readobj] - Remove deprecated unwrapOrError(Expected<T> EO).
This patch changes the code to use a modern unwrapOrError(StringRef Input, Expected<T> EO)
version that contains the input source name and removes the deprecated version.

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

llvm-svn: 368428
2019-08-09 10:53:12 +00:00
George Rimar
644ccd71c4 [llvm-readobj/libObject] - Introduce a custom warning handler for ELFFile<ELFT> methods.
Currently, we have a code duplication in llvm-readobj which was introduced in D63266.
The duplication was introduced to allow llvm-readobj to dump the partially
broken object. Methods in ELFFile<ELFT> perform a strict validation of the inputs,
what is itself good, but not for dumper tools, that might want to dump the information,
even if some pieces are broken/unexpected.

This patch introduces a warning handler which can be passed to ELFFile<ELFT> methods
and can allow skipping the non-critical errors when needed/possible.

For demonstration, I removed the duplication from llvm-readobj and implemented a warning using
the new custom warning handler. It also deduplicates the strings printed, making the output less verbose.

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

llvm-svn: 368260
2019-08-08 07:17:35 +00:00