aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj
AgeCommit message (Collapse)AuthorFilesLines
2020-03-05[ARM] Rewrite ARMAttributeParserFangrui Song1-1/+3
* Delete boilerplate * Change functions to return `Error` * Test parsing errors * Update callers of ARMAttributeParser::parse() to check the `Error` return value. Since this patch touches nearly everything in the file, I apply http://llvm.org/docs/Proposals/VariableNames.html and change variable names to lower case. Reviewed By: compnerd Differential Revision: https://reviews.llvm.org/D75015
2020-03-05[llvm-readobj] Include section name of notes.Jordan Rupprecht1-9/+20
This changes the output of `llvm-readelf -n` from: ``` Displaying notes found at file offset 0x<...> with length 0x<...>: ``` to: ``` Displaying notes found in: .note.foo ``` And similarly, adds a `Name:` field to the `llvm-readobj -n` output for notes. This change not only increases GNU compatibility, it also makes it much easier to read notes. Note that we still fall back to printing the file offset/length in cases where we don't have a section name, such as when printing notes in program headers or printing notes in a partially stripped file (GNU readelf does the same). Fixes llvm.org/PR41339. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D75647
2020-03-04[llvm-readelf] Make --all output order closer to GNU readelfFangrui Song1-10/+10
https://bugs.llvm.org/show_bug.cgi?id=43403 The new order makes it easy to compare the two tools' --all. Reviewed By: grimar, rupprecht Differential Revision: https://reviews.llvm.org/D75592
2020-02-29[llvm-readobj] - Report warnings instead of errors for broken relocations.Georgii Rymar1-23/+42
This is a follow-up for https://reviews.llvm.org/D74545. It adds test cases for each incorrect case returned in `getRelocationTarget`. Differential revision: https://reviews.llvm.org/D74595
2020-02-21[ARM] Change ARMAttributeParser::Parse to use support::endianness and simplifyFangrui Song1-1/+1
2020-02-19[WebAssembly] Use llvm::Optional to store optional symbol attributes. NFC.Sam Clegg1-2/+6
The changes the in-memory representation of wasm symbols such that their optional ImportName and ImportModule use llvm::Optional. ImportName is set whenever WASM_SYMBOL_EXPLICIT_NAME flag is set. ImportModule (for imports) is currently always set since it defaults to "env". In the future we can possibly extent to binary format distingish import which have explit module names. Tags: #llvm Differential Revision: https://reviews.llvm.org/D74109
2020-02-18[llvm-readobj] - Report a warning when an unexpected DT_SYMENT tag value is met.Georgii Rymar1-0/+10
There was a short discussion about this: https://reviews.llvm.org/D73484#inline-676942 To summarize: It is a bit unclear to me why the `DT_SYMENT` tag exist. LLD has the code that does: "addInt(DT_SYMENT, sizeof(Elf_Sym));" and I guess other linkers has the same logic. It is unclear why it can be possible to have other values rather than values of a size of platform symbol. Seems it is not possible, and atm for me it looks that this tag should not be used. This patch starts reporting the warning when the value it contains differs from a symbol size for a 32/64 bit platform for safety. It keeps the rest of the logic we have unchanged. Before this patch we did not handle the tag at all. Differential review: https://reviews.llvm.org/D74479
2020-02-16[llvm-readobj] - Refactor the code that dumps relocations.Georgii Rymar1-31/+48
The current code has following issues: 1) It has a duplicated logic part. 2) This logic relies on unwrapOrError calls, but if we want to convert them to warnings, we will need to change all of them what is hard to do because of the duplication. In this patch I've created a new method that returns Expected<> what allows now to catch all errors in a single place and remove the code duplication. Note: this change is itself a refactor NFC. It does not change the current logic anyhow. It prepares the code for the follow-up(s). Differential revision: https://reviews.llvm.org/D74545
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-1/+1
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-1/+1
2020-02-10[llvm-readobj] - Change the error to warning when a section name is unknown.Georgii Rymar1-3/+7
We reported the error in this case. But it was asked (https://reviews.llvm.org/D73193#inline-665595) to convert it to a warning. This patch does it. Differential revision: https://reviews.llvm.org/D74047
2020-02-09[DebugInfo] Add a DWARFDataExtractor constructor that takes ArrayRef<uint8_t>Fangrui Song1-6/+3
Similar to D67797 (DataExtractor).
2020-01-31[llvm-readobj] - Don't crash when dumping invalid dynamic relocation.Georgii Rymar1-11/+25
Currently when we dump dynamic relocation with use of DT_RELA/DT_RELASZ/DT_RELAENT tags, we crash when a symbol index is larger than the number of dynamic symbols or when there is no dynamic symbol table. This patch adds test cases and fixes the issues. Differential revision: https://reviews.llvm.org/D73560
2020-01-30[llvm-readobj] - Improve error message reported by DynRegionInfo.Georgii Rymar1-10/+49
DynRegionInfo is a helper class used to create memory ranges. It is used for many things and can report errors. Errors reported currently do not provide a good diagnostic. This patch fixes it and adds a test for each possible case. Differential revision: https://reviews.llvm.org/D73484
2020-01-30[llvm-readobj] - Add a few warnings for --gnu-hash-table.Georgii Rymar1-6/+44
The current implementation stops dumping in case of a single error it handles, though we can continue dumping. This patch refines it: it adds a few warnings and a few test cases. Differential revision: https://reviews.llvm.org/D73269
2020-01-29Make bugpoint work with gcc5 again.Benjamin Kramer1-1/+1
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer4-18/+21
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-27[llvm-readobj] - Refine --needed-libs implementation and add a test.Georgii Rymar1-2/+2
We have no good test for --needed-libs option. The one we have as a part of Object/readobj-shared-object.test is not complete. In this patch I've did a minor NFC changes to the implementation and added a test. This allowed to remove this piece from Object/readobj-shared-object.test Differential revision: https://reviews.llvm.org/D73174
2020-01-24[llvm-readelf] - Improve dumping of objects without a section header string ↵Georgii Rymar1-2/+8
table. We have a test/Object/no-section-header-string-table.test which checks what happens when an object does not have a section header string table. It does not check the full output though. Currently our output is different from GNU readelf, because the latter prints "<no-strings>" instead of a section name, while we print nothing. This patch fixes this, adds a proper test case and removes the one from test/Object, as it is not a right folder for llvm-readelf tests. Differential revision: https://reviews.llvm.org/D73193
2020-01-21[llvm-readelf][llvm-readobj] - Fix the indentation when printing dynamic tags.Georgii Rymar1-14/+32
This change is similar to one made for llvm-objdump in D72838. llvm-readelf/llvm-readobj tools do not align the "Name/Value" column properly. This patch adds a logic to calculate the size of indentation on fly to fix such issues. Differential revision: https://reviews.llvm.org/D72843
2020-01-06[llvm-readelf] Print EI_ABIVERSION as decimal instead of hexadecimalFangrui Song1-2/+2
This matches GNU readelf and llvm-readobj. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D72234
2019-12-24[llvm-readobj] - Remove an excessive helper for printing dynamic tags.Georgii Rymar1-81/+9
This removes the `getTypeString` from readeobj source because it almost duplicates the existent method: `ELFFile<ELFT>::getDynamicTagAsString`. Side effect: now it prints "<unknown:>0xHEXVALUE" instead of "(unknown)" for unknown values. llvm-readelf before this patch printed: ``` 0x0000000012345678 (unknown) 0x8765432187654321 0x000000006abcdef0 (unknown) 0x9988776655443322 0x0000000076543210 (unknown) 0x5555666677778888 ``` and now it prints: ``` 0x0000000012345678 (<unknown:>0x12345678) 0x8765432187654321 0x000000006abcdef0 (<unknown:>0x6abcdef0) 0x9988776655443322 0x0000000076543210 (<unknown:>0x76543210) 0x5555666677778888 ``` GNU reaedlf prints different thing: ``` 0x0000000012345678 (<unknown>: 12345678) 0x8765432187654321 0x000000006abcdef0 (Operating System specific: 6abcdef0) 0x9988776655443322 0x0000000076543210 (Processor Specific: 76543210) 0x5555666677778888 ``` I am not sure we want to follow GNU here. Even if we do, it should be separate patch probably. The new output looks better and closer to GNU anyways, and the code is a bit simpler. Differential revision: https://reviews.llvm.org/D71835
2019-12-22[Tools] Fixes -Wrange-loop-analysis warningsMark de Wever2-5/+5
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71808
2019-12-18[llvm-readob] - Refactor printing of sections flags. NFCI.Georgii Rymar1-50/+54
This is a natural clean-up after D71462/D71464. It allows to define known section letters used for GNU style in one place. Differential revision: https://reviews.llvm.org/D71591
2019-12-18[llvm-readelf] - Change letters used for SHF_ARM_PURECODE and ↵Georgii Rymar1-10/+27
SHF_X86_64_LARGE flags. GNU uses `l` for SHF_X86_64_LARGE and `y` for SHF_ARM_PURECODE. Lets follow. To do this I had to refactor and refine how we print the help flags description. It was too generic and inconsistent with GNU readelf. Differential revision: https://reviews.llvm.org/D71464
2019-12-18[llvm-readelf][llvm-readobj] - Reimplement the logic of section flags dumping.Georgii Rymar1-27/+42
Our logic that dumped the flags was buggy. For LLVM style it dumped SHF_MASKPROC/SHF_MASKOS named constants, though they are not flags, but masks. For GNU style it was just very inconsistent with GNU which has logic that is not straightforward. Imagine we have sh_flags == 0x90000000. SHF_EXCLUDE ("E") has a value of 0x80000000 and SHF_MASKPROC is 0xf0000000. GNU readelf will not print "E" or "Ep" in this case, but will print just "p". It only will print "E" when no other processor flag is set. I had to investigate the GNU source to find the algorithm and now our logic should match it. Differential revision: https://reviews.llvm.org/D71462
2019-12-13[llvm-readobj] - Fix letters used for dumping section types in GNU style.Georgii Rymar1-3/+4
I've noticed that when we have all regular flags set, we print "WAEXMSILoGTx" instead of "WAXMSILOGTCE" printed by GNU readelf. It happens because: 1) We print SHF_EXCLUDE at the wrong place. 2) We do not recognize SHF_COMPRESSED, we print "x" instead of "C". 3) We print "o" instead of "O" for SHF_OS_NONCONFORMING. This patch fixes differences and adds test cases. Differential revision: https://reviews.llvm.org/D71418
2019-12-11[llvm-readobj][llvm-readelf] - Remove excessive empty lines when reporting ↵Georgii Rymar1-2/+0
errors and warnings. After recent changes it is now seems possible to get rid of printing '\n' before each error and warning. This makes the output cleaner. Differential revision: https://reviews.llvm.org/D71246
2019-12-11[llvm-readelf] - Do no print an empty symbol version as "<corrupt>"Georgii Rymar1-1/+1
It is discussed here https://reviews.llvm.org/D71118#inline-643172 Currently when a version is empty, llvm-readelf prints: "000: 0 (*local*) 2 (<corrupt>)" But GNU readelf does not treat empty section as corrupt. There is no sense in having empty versions anyways it seems, but this change is for consistency with GNU. Differential revision: https://reviews.llvm.org/D71243
2019-12-11[llvm-readobj] Fix/improve printing WinEH unwind info for linked PE imagesMartin Storsjö2-6/+56
ARMWinEHPrinter was already designed to handle linked PE images (since d2941b43f40d), but resolving symbols didn't consistently take the image base into account (as linked images seldom have a symbol table, except for in MinGW setups). Win64EHDumper wasn't really designed to handle linked images (it would crash if executed on such a file), but a few concepts (getSymbol, taking a virtual address instead of a relocation, and getSectionContaining for finding the section containing a certain virtual address) can be borrowed from ARMWinEHPrinter. Adjust ARMWinEHPrinter to print the address of the exception handler routine as a VA instead of an RVA, consistently with other addresses in the same printout, and make Win64EHDumper print addresses similarly for image cases. Differential Revision: https://reviews.llvm.org/D71303
2019-12-10[llvm-readelf/llvm-readobj] - Improved the error reporting in a few method ↵Georgii Rymar1-42/+60
related to versioning. I was investigating a change previously discussed that eliminates an excessive empty lines from the output when we report warnings and errors (https://reviews.llvm.org/D70826#inline-639055) and found that we need this refactoring or alike to achieve that. The problem is that some of our functions that finds symbol versions just fail instead of returning errors or printing warnings. Another problem is that they might print a warning on the same line with the regular output. In this patch I've splitted getting of the version information and dumping of it for GNU printVersionSymbolSection(). I had to change a few methods to return Error or Expected<> to do that properly. Differential revision: https://reviews.llvm.org/D71118
2019-12-06[llvm-readobj][llvm-readelf] - Refactor parsing of the SHT_GNU_versym section.Georgii Rymar1-28/+118
This introduce a new helper which is used to parse the SHT_GNU_versym section. LLVM/GNU styles implementations now use it to share the logic. Differential revision: https://reviews.llvm.org/D71054
2019-12-06[llvm-readobj] - Implement --dependent-libraries flag.Georgii Rymar3-0/+57
There is no way to dump SHT_LLVM_DEPENDENT_LIBRARIES sections currently. This patch implements this. The section is described here: https://llvm.org/docs/Extensions.html#sht-llvm-dependent-libraries-section-dependent-libraries Differential revision: https://reviews.llvm.org/D70665
2019-12-05[llvm-readelf/llvm-readobj] - Remove getSecTypeName() helper.Georgii Rymar1-16/+10
We do not need it, we have `object::getELFSectionTypeName` that can be used instead. Differential revision: https://reviews.llvm.org/D71017
2019-12-04[ELF] Support for PT_GNU_PROPERTY in header and toolsPeter Smith1-0/+2
The PT_GNU_PROPERTY is generated by a linker to describe the .note.gnu.property section. The Linux kernel uses this program header to locate the .note.gnu.property section. It is described in "The Linux gABI extension" Include support for llvm-readelf, llvm-readobj and the yaml reader and writers. Differential Revision: https://reviews.llvm.org/D70959
2019-12-02[llvm-readobj/llvm-readelf] - Simplify the code that dumps versions.Georgii Rymar1-131/+45
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[llvm-readelf/llvm-readobj] - Check the version of SHT_GNU_verneed section ↵Georgii Rymar1-0/+6
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[llvm-readobj/llvm-readelf] - Reimplement dumping of the SHT_GNU_verneed ↵Georgii Rymar1-84/+168
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-11-29[llvm-readelf/llvm-readobj] - Check version of SHT_GNU_verdef section ↵Georgii Rymar1-0/+6
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-28[llvm-readelf] - Make GNU style dumping of invalid SHT_GNU_verdef be ↵Georgii Rymar1-16/+24
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-27[llvm-readobj] - Always print "Predecessors" for version definition sections.Georgii Rymar1-3/+0
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-26[llvm-readobj/llvm-readelf] - Reimplement dumping of the SHT_GNU_verdef section.Georgii Rymar1-68/+149
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-20[llvm-readobj] - Improve dumping of the SHT_LLVM_LINKER_OPTIONS sections.Georgii Rymar1-6/+26
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[llvm-readobj/llvm-readelf] - Improve dumping of versioning sections.Georgii Rymar1-2/+2
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-07Using crtp to refactor the xcoff section headerdiggerlin1-11/+2
SUMMARY: According to https://reviews.llvm.org/D68575#inline-617586, Create a NFC patch for it. Using crtp to refactor the xcoff section header Move the define of SectionFlagsReservedMask and SectionFlagsTypeMask from XCOFFDumper.cpp to XCOFFObjectFile.h Reviewers: hubert.reinterpretcast,jasonliu Subscribers: rupprecht, seiyai,hiraditya Differential Revision: https://reviews.llvm.org/D69131
2019-11-04[llvm-readobj] Change errors to warnings for symbol section name dumpingJames Henderson1-15/+53
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-01[NFC][llvm-readobj] Split getSectionIndexName function into twoJames Henderson1-36/+48
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[NFC][llvm-readobj] Pull common code into a helperJames Henderson1-18/+13
This will make planned changes to this code easier to make. Reviewed by: MaskRay, grimar Differential Revision: https://reviews.llvm.org/D69669
2019-10-31[llvm-readelf/llvm-readobj] - Improve dumping of broken versioning sections.Georgii Rymar1-11/+31
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-21[llvm/Object] - Make ELFObjectFile::getRelocatedSection return ↵George Rimar1-2/+10
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