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

1188 Commits

Author SHA1 Message Date
Kazu Hirata
e503e87089 [readobj] Use ListSeparator (NFC) 2021-03-01 23:40:31 -08:00
Kazu Hirata
ff7df6f0b8 [llvm-readobj] Use ListSeparator (NFC) 2021-02-27 10:09:22 -08:00
Stanislav Mekhanoshin
f1c6dbc4d5 [AMDGPU] gfx90a support
Differential Revision: https://reviews.llvm.org/D96906
2021-02-17 16:01:32 -08:00
Alex Richardson
9d4a31c573 [llvm-readobj] Add support for decoding FreeBSD ELF notes
The current support only printed coredump notes, but most binaries also
contain notes. This change adds names for four FreeBSD-specific notes and
pretty-prints three of them:

NT_FREEBSD_ABI_TAG:
This note holds a 32-bit (decimal) integer containing the value of the
__FreeBSD_version macro, which is defined in crt1.o and will hold a value
such as 1300076 for a binary build on a FreeBSD 13 system.

NT_FREEBSD_ARCH_TAG:
A string containing the value of the build-time MACHINE_ARCH

NT_FREEBSD_FEATURE_CTL: A 32-bit flag that indicates to the kernel that
the binary wants certain bevahiour. Examples include setting
NT_FREEBSD_FCTL_ASLR_DISABLE which tells the kernel to disable ASLR.

After this change llvm-readobj also no longer decodes coredump-only
FreeBSD notes in non-coredump files. I've also converted the
note-freebsd.s test to use yaml2obj instead of llvm-mc.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D74393
2021-02-09 16:59:22 +00:00
Alex Richardson
458893076b [llvm-readelf] Print raw ELF note contents if we can't parse it
Currently, if the note name is known, but the value isn't we don't print
the contents.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D74367
2021-02-09 16:59:22 +00:00
Alex Richardson
6da083491b [llvm-readobj] Print empty line between note sections in GNU mode
This matches GNU binutils.

Reviewed By: rupprecht, jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D96010
2021-02-09 16:59:21 +00:00
Fangrui Song
4be3ad3853 [yaml2obj/obj2yaml/llvm-readobj] Support SHF_GNU_RETAIN
In binutils, the flag is defined for ELFOSABI_GNU and ELFOSABI_FREEBSD.
It can be used to mark a section as a GC root.

In practice, the flag has generic semantics and can be applied to many
EI_OSABI values, so we consider it generic.

Differential Revision: https://reviews.llvm.org/D95728
2021-02-02 09:19:53 -08:00
Kazu Hirata
e0a8f45e5f [llvm] Drop unnecessary const from return types (NFC)
Identified with const-return-type.
2021-01-31 10:23:43 -08:00
Kazu Hirata
04422f73a1 [llvm] Use append_range (NFC) 2021-01-29 23:23:34 -08:00
Georgii Rymar
a153345c4f [llvm-readobj/elf] - Report "bitcode files are not supported" warning for bitcode files.
Fixes https://bugs.llvm.org/show_bug.cgi?id=43543

Currently we report "The file was not recognized as a valid object file" for BC files.
Also, we terminate dumping.

Instead we could report a better warning and try to continue dumping other files.
This is what this patch implements.

Differential revision: https://reviews.llvm.org/D95605
2021-01-29 12:04:41 +03:00
Georgii Rymar
2900e3238f [libObject,llvm-readelf/obj] - Don't use @@ when printing versions of undefined symbols.
A default version (@@) is only available for defined symbols.

Currently we use "@@" for undefined symbols too.
This patch fixes the issue and improves our test case.

Differential revision: https://reviews.llvm.org/D95219
2021-01-26 12:05:59 +03:00
Georgii Rymar
43999a3d98 [Object, llvm-readelf] - Move the API for retrieving symbol versions to ELF.h
`ELFDumper.cpp` implements the functionality that allows to get symbol versions.
It is used for dumping versioned symbols.

This helps to implement https://bugs.llvm.org/show_bug.cgi?id=48670 ("make llvm-nm -D print version names"):
we can move out and reuse the code from `ELFDumper.cpp`.
This is what this patch do: it moves the related functionality to `ELFFile<ELFT>`.

Differential revision: https://reviews.llvm.org/D94771
2021-01-18 12:50:29 +03:00
Kazu Hirata
3754cf9a03 [llvm] Use *::empty (NFC) 2021-01-16 09:40:55 -08:00
Georgii Rymar
d2ec69d971 [llvm-readobj] - Fix the compilation with GCC < 7.0.
This addressed post commit comments for D93900.

GCC had an issue and requires placing a specialization of
`printUnwindInfo` to a namespace to compile:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480
2021-01-15 11:58:04 +03:00
Andy Wingo
a312ae5a63 [lld][WebAssembly] Add support for handling table symbols
This commit adds table symbol support in a partial way, while still
including some special cases for the __indirect_function_table symbol.
No change in tests.

Differential Revision: https://reviews.llvm.org/D94075
2021-01-14 11:13:13 +01:00
Georgii Rymar
8e4afeec9b [llvm-readelf/obj] - Add support of multiple SHT_SYMTAB_SHNDX sections.
Currently we don't support multiple SHT_SYMTAB_SHNDX sections
and the DT_SYMTAB_SHNDX tag currently.

This patch implements it and fixes the
https://bugs.llvm.org/show_bug.cgi?id=43991.

I had to introduce the `struct DataRegion` to ELF.h,
it is used to represent a region that might have no known size.
It is needed, because we don't know the size of the extended
section indices table when it is located via DT_SYMTAB_SHNDX.
In this case we still want to validate that we don't read
past the end of the file.

Differential revision: https://reviews.llvm.org/D92923
2021-01-13 11:36:43 +03:00
Georgii Rymar
09dcbafb1d [llvm-readobj] - One more attempt to fix BB.
Add `this->` for `W`, which is the member of `ObjDumper`

An example of error:
readobj/ELFDumper.cpp:738:13: error: use of undeclared identifier 'W'
    assert(&W.getOStream() == &llvm::fouts());
2021-01-12 13:17:59 +03:00
Georgii Rymar
b88a437339 [llvm-readobj] - An attempt to fix BB.
This adds the `template` keyword for 'getAsArrayRef' calls.

An example of error:
/b/1/openmp-gcc-x86_64-linux-debian/llvm.src/llvm/tools/llvm-readobj/ELFDumper.cpp:4491:50: error: use 'template' keyword to treat 'getAsArrayRef' as a dependent template name
    for (const Elf_Rel &Rel : this->DynRelRegion.getAsArrayRef<Elf_Rel>())
2021-01-12 13:09:49 +03:00
Georgii Rymar
861dc1490e [llvm-readobj] - Add 'override' to fix build bots.
This should fix bots after landing D93900.

An example of error is:

/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/llvm/tools/llvm-readobj/ELFDumper.cpp:883:8: warning: 'printSectionMapping' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  void printSectionMapping() {}
2021-01-12 13:01:15 +03:00
Georgii Rymar
519478e0e8 [llvm-readef/obj] - Change the design structure of ELF dumper. NFCI.
This is a refactoring for design of stuff in `ELFDumper.cpp`.
The current design of ELF dumper is far from ideal.

Currently most overridden functions (inherited from `ObjDumper`) in `ELFDumper` just forward to
the functions of `ELFDumperStyle` (which can be either `GNUStyle` or `LLVMStyle`).
A concrete implementation may be in any of `ELFDumper`/`DumperStyle`/`GNUStyle`/`LLVMStyle`.

This patch reorganizes the classes by introducing `GNUStyleELFDumper`/`LLVMStyleELFDumper`
which inherit from `ELFDumper`. The implementations are moved:

`DumperStyle` -> `ELFDumper`
`GNUStyle` -> `GNUStyleELFDumper`
`LLVMStyle` -> `LLVMStyleELFDumper`

With that we can avoid having a lot of redirection calls and helper methods.
The number of code lines changes from 7142 to 6922 (reduced by ~3%) and the
code overall looks cleaner.

Differential revision: https://reviews.llvm.org/D93900
2021-01-12 12:36:17 +03:00
Georgii Rymar
03029fc3ec [llvm-readelf/obj] - Index phdrs and relocations from 0 when reporting warnings.
As was mentioned in comments here:
https://reviews.llvm.org/D92636#inline-864967

we are not consistent and sometimes index things from 0, but sometimes
from 1 in warnings.

This patch fixes 2 places: messages reported for
program headers and messages reported for relocations.

Differential revision: https://reviews.llvm.org/D93805
2021-01-11 15:13:54 +03:00
Martin Storsjö
f2ee9eef1a [llvm-readobj] [ARMWinEH] Clearly print an invalid case of packed unwind info as such
As the actual windows unwinder doesn't support this case, don't
pretend that it is supported when dumping the generated unwind info
either, even if it would be possible to interpret it as something
sensible.

This should reduce the risk of us emitting such a case in code
(although it's unlikely as long as the unwind info is generated
through the SEH opcodes, as the opcodes can't describe this case).

Differential Revision: https://reviews.llvm.org/D91529
2021-01-08 10:04:44 +02:00
Kazu Hirata
a5e31bfa6a [llvm] Use llvm::any_of (NFC) 2021-01-04 11:42:47 -08:00
Georgii Rymar
625780544e [llvm-readelf/obj] - Improve the warning reported when unable to read the stack size.
It was discussed in D92545 that we might want to improve messages
reported when something is wrong with the stack size section.
This patch does it.

Differential revision: https://reviews.llvm.org/D93802
2020-12-25 11:40:35 +03:00
Georgii Rymar
8638aa3531 [libObject] - Add more ELF types to LLVM_ELF_IMPORT_TYPES_ELFT define (ELFTypes.h).
This allows to get rid of lots for typedefs/usings from many places.

Differential revision: https://reviews.llvm.org/D93801
2020-12-25 11:39:05 +03:00
Georgii Rymar
baa62a1798 [llvm-readobj] - Dump the ELF file type better.
Currently llvm-readelf might print "OS Specific/Processor Specific/<unknown>"
hint when dumping the ELF file type. The patch teaches llvm-readobj to do the same.

This fixes https://bugs.llvm.org/show_bug.cgi?id=40868

I am removing `Object/elf-unknown-type.test` test because it is not in the right place,
it is outdated and very limited.
The `readobj/ELF/file-types.test` checks the functionality much better.

Differential revision: https://reviews.llvm.org/D93689
2020-12-23 11:13:19 +03:00
Arthur O'Dwyer
bf9fb2bea1 Replace T(x) with reinterpret_cast<T>(x) everywhere it means reinterpret_cast. NFC.
Differential Revision: https://reviews.llvm.org/D76572
2020-12-22 19:54:29 -05:00
Georgii Rymar
6ae506ec2d [libObject, llvm-readobj] - Reimplement ELFFile<ELFT>::getEntry.
Currently, `ELFFile<ELFT>::getEntry` does not check an index of
an entry. Because of that the code might read past the end of the symbol
table silently. I've added a test to `llvm-readobj\ELF\relocations.test`
to demonstrate the possible issue. Also, I've added a unit test for
this method.

After this change, `getEntry` stops reporting the section index and
reuses the `getSectionContentsAsArray` method, which already has
all the validation needed. Our related warnings now provide
more and better context sometimes.

Differential revision: https://reviews.llvm.org/D93209
2020-12-18 16:52:27 +03:00
Adhemerval Zanella
f54cbc7c92 [llvm-readobj/elf] - AArch64: Handle AARCH64_VARIANT_PCS for GNUStyle
It mimics the GNU readelf where it prints a [VARIANT_PCS] for symbols
with st_other with STO_AARCH64_VARIANT_PCS.

Reviewed By: grimar, MaskRay

Differential Revision: https://reviews.llvm.org/D93044
2020-12-17 11:09:53 -03:00
Georgii Rymar
e16531589c [llvm-readelf/obj] - Handle out-of-order PT_LOADs better.
This is https://bugs.llvm.org/show_bug.cgi?id=45698.

Specification says that
"Loadable segment entries in the program header table appear
in ascending order, sorted on the p_vaddr member."

Our `toMappedAddr()` relies on this condition. This patch
adds a warning when the sorting order of loadable segments is wrong.
In this case we force segments sorting and that allows
`toMappedAddr()` to work as expected.

Differential revision: https://reviews.llvm.org/D92641
2020-12-16 12:59:32 +03:00
Georgii Rymar
0f9894fe39 [llvm-readelf] - Don't print OS/Processor specific prefix for known ELF file types.
This is a change suggested in post commit comments for
D93096 (https://reviews.llvm.org/D93096#2451796).

Imagine we want to add a custom OS specific ELF file type.
For that we can update the `ElfObjectFileType` array:

```
static const EnumEntry<unsigned> ElfObjectFileType[] = {
...
  {"Core",         "CORE (Core file)",         ELF::ET_CORE},
  {"MyType",       "MyType (my description)",     0xfe01},
};
```

The current code then might print:
```
OS Specific: (MyType (my description))
```

Though instead we probably would like to see a nicer output, e.g:
```
Type: MyType (my description)
```

To achieve that we can reorder the code slightly.

It is impossible to add a test I think, because we have no custom values in
the `ElfObjectFileType` array in LLVM.

Differential revision: https://reviews.llvm.org/D93217
2020-12-15 10:56:25 +03:00
Georgii Rymar
c7112b7126 [llvm-readobj] - For SHT_REL relocations, don't display an addend.
This is https://bugs.llvm.org/show_bug.cgi?id=44257.

In LLVM style we always print `0` as addend when dumping
SHT_REL relocations. It is confusing, this patch stops
printing it as the first comment on the bug page suggests.

Differential revision: https://reviews.llvm.org/D93033
2020-12-14 12:03:00 +03:00
Georgii Rymar
dff27ca0da [llvm-readelf] - Improve ELF type field dumping.
This is related to https://bugs.llvm.org/show_bug.cgi?id=40868.

Currently we don't print `OS Specific`/``Processor Specific`/`<unknown>`
prefixes when dumping the ELF file type. This is not consistent
with GNU readelf. The patch fixes it.

Also, this patch removes the `types.test`, because we already have
`file-types.test`, which tests more cases and this patch revealed that
we have such a duplicate.

Differential revision: https://reviews.llvm.org/D93096
2020-12-14 11:24:08 +03:00
Georgii Rymar
c56960224e [llvm-readelf/obj] - Improve diagnostics when printing NT_FILE notes.
This changes the `printNotesHelper` to report warnings on its side when
there are errors when dumping notes.

With that we can provide more content when reporting warnings about broken notes.

Differential revision: https://reviews.llvm.org/D92636
2020-12-09 12:31:46 +03:00
Georgii Rymar
a9fdb4b116 [llvm-readobj/elf] - Refine the implementation of "printFunctionStackSize".
This rewrites the logic to get rid of "ELFSymbolRef" API where possible.
This allowed to handle possible errors better, improve warnings reported and add new ones.
Also 'reportWarning' was replaced with 'reportUniqueWarning'

Differential revision: https://reviews.llvm.org/D92545
2020-12-07 14:57:44 +03:00
Fangrui Song
9bf35cadb5 [llvm-readobj] Delete unused declaration 2020-12-06 15:54:17 -08:00
Georgii Rymar
437027774a [lib/Object, tools] - Make ELFObjectFile::getELFFile return reference.
We always have an object, so we don't have to return a pointer.

Differential revision: https://reviews.llvm.org/D92560
2020-12-04 16:02:29 +03:00
Georgii Rymar
e63e1a7cd7 [llvm-readobj] - Report unique warnings in printProgramHeaders.
This converts `reportWarning` -> `reportUniqueWarning`

Differential revision: https://reviews.llvm.org/D92568
2020-12-04 13:35:44 +03:00
Georgii Rymar
4ad44d85e5 [llvm-readelf/obj] - Report unique warnings in getSymbolForReloc() helper.
Use `reportUniqueWarning` instead of `reportWarning` and refine the
interface of the helper.

Differential revision: https://reviews.llvm.org/D92556
2020-12-03 14:13:26 +03:00
Georgii Rymar
924cd26a7e [llvm-readelf] - Report unique warnings when dumping hash symbols/histogram.
This converts 2 more places to use `reportUniqueWarning` and adds tests.

Differential revision: https://reviews.llvm.org/D92551
2020-12-03 14:05:04 +03:00
Georgii Rymar
ae44f6b6df [llvm-readobj, libSupport] - Refine the implementation of the code that dumps build attributes.
This implementation of `ELFDumper<ELFT>::printAttributes()` in llvm-readobj has issues:
1) It crashes when the content of the attribute section is empty.
2) It uses `unwrapOrError` and `reportWarning` calls, though
   ideally we want to use `reportUniqueWarning`.
3) It contains a TODO about redundant format version check.

`lib/Support/ELFAttributeParser.cpp` uses a hardcoded constant instead of the named constant.

This patch fixes all these issues.

Differential revision: https://reviews.llvm.org/D92318
2020-12-02 13:51:32 +03:00
Georgii Rymar
c4ac5014a0 [llvm-readelf/obj] - Lowercase the warning message reported.
Our warnings/errors reported are using lowercase normally.

This addresses one of review comments from D92382.
2020-12-02 13:09:47 +03:00
Georgii Rymar
b7a191f814 [llvm-readelf/obj] - Report unique warnings in parseDynamicTable.
This makes the warnings reported to be unique and adds test cases.

Differential revision: https://reviews.llvm.org/D92382
2020-12-02 12:52:42 +03:00
Georgii Rymar
6340cbbc6f [llvm-readelf/obj] - Refine the error message about the broken string table.
This:
1) Changes `reportWarning` to `reportUniqueWarning` (no-op here).
2) Adds more context to the message.
3) Merges `broken-dynsym-link.test` into `dyn-symbols.test`, adds more testing.

Differential revision: https://reviews.llvm.org/D92380
2020-12-02 12:06:16 +03:00
Georgii Rymar
f4dc2c0d44 [llvm-readobj] - Introduce ObjDumper::reportUniqueWarning(const Twine &Msg).
This introduces the overload for `reportUniqueWarning` which allows
to avoid using `createError` in many places.

Differential revision: https://reviews.llvm.org/D92371
2020-12-01 12:36:44 +03:00
Georgii Rymar
950e7e96bb [llvm-readelf] - Switch to using from reportWarning to reportUniqueWarning in DynRegionInfo.
This is a part of the plan we had previously to convert all calls to
`reportUniqueWarning` and then rename it to just `reportWarning`.

I was a bit unsure about this particular change at first, because it doesn't add a
new functionality: seems it is impossible to trigger a warning duplication currently.

At the same time I find the idea of the plan mentioned very reasonable.
And with that we will be sure that `DynRegionInfo` can't report duplicate
warnings, what looks like a nice feature for possible refactorings and further tool development.

Differential revision: https://reviews.llvm.org/D92224
2020-12-01 11:09:30 +03:00
Georgii Rymar
37259d46e0 [llvm-readelf/obj] - Move unique warning handling logic to the ObjDumper.
This moves the `reportUniqueWarning` method to the base class.

My motivation is the following:
I've experimented with replacing `reportWarning` calls with `reportUniqueWarning`
in ELF dumper. I've found that for example for removing them from `DynRegionInfo` helper
class, it is worth to pass a dumper instance to it (to be able to call dumper()->reportUniqueWarning()).
The problem was that `ELFDumper<ELFT>` is a template class. I had to make `DynRegionInfo` to be templated
and do lots of minor changes everywhere what did not look reasonable/nice.

At the same time I guess one day other dumpers like COFF/MachO/Wasm etc might want to
start using `reportUniqueWarning` API too. Then it looks reasonable to move the logic to the
base class.

With that the problem of passing the dumper instance will be gone.

Differential revision: https://reviews.llvm.org/D92218
2020-12-01 10:53:00 +03:00
Georgii Rymar
e7de4f550f [llvm-readelf/obj] - Stop calling reportError in printArchSpecificInfo().
This is related to MIPS. Currently we might report an error and exit,
though there is no problem to report a warning and try to continue dumping
an object. The code uses `MipsGOTParser<ELFT> Parser`, which is isolated
in this method.

Differential revision: https://reviews.llvm.org/D92090
2020-11-27 10:27:00 +03:00
Georgii Rymar
883360393d [llvm-readelf/obj] - Report a warning when the value of the DT_PLTREL dynamic tag is invalid.
We report an error for unknown `DT_PLTREL` values.
This switches the error to warning.

Differential revision: https://reviews.llvm.org/D92087
2020-11-26 13:15:59 +03:00
Georgii Rymar
15373796cb [llvm-readobj] - Fix a warning.
This addresses post review comment for D92018.

The warning was:

```
error: loop variable 'Note' is always a copy because the range of type 'iterator_range<llvm::object::ELFFile<llvm::object::ELFType<llvm::support::big, true> >::Elf_Note_Iterator>' (aka 'iterator_range<Elf_Note_Iterator_Impl<ELFType<(llvm::support::endianness)0U, true> > >') does not return a reference [-Werror,-Wrange-loop-analysis]
      for (const typename ELFT::Note &Note : Obj.notes(S, Err))
```
2020-11-26 10:24:24 +03:00