aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/ObjDumper.h
AgeCommit message (Collapse)AuthorFilesLines
2025-09-29Add --offoading option to llvm-readobj (#143342)David Salinas1-0/+2
Utilize new extensions to LLVM Offloading API to handle offloading fatbin Bundles. The tool will output a list of available offload bundles using URI syntax. --------- Co-authored-by: dsalinas_amdeng <david.salinas@amd.com>
2025-08-27[llvm-readobj][COFF] Implement --coff-pseudoreloc in llvm-readobj to dump ↵Tomohiro Kashiwada1-0/+1
runtime pseudo-relocation records (#151816) MinGW toolchain uses "runtime pseudo-relocation" mechanism to support auto-importing symbols from DLLs. There is no commonly used tools for dump the pseudo-relocation records, so we implement that functionality in llvm-readobj.
2025-07-21[Object] Beginnings of SFrame parser and dumper (#147294)Pavel Labath1-0/+5
This PR adds the SFrameParser class and uses it from llvm-readobj to dump the section contents. Currently, it only supports parsing the SFrame section header. Other parts of the section will be added in follow-up patches. llvm-readobj uses the same sframe flag syntax as GNU readelf, but I have not attempted match the output format of the tool. I'm starting with the "llvm" output format because it's easier to generate and lets us tweak the format to make it useful for testing the generation code. If needed, support for the GNU format could be added by overriding this functionality in the GNU ELF Dumper. For more information, see the [sframe specification](https://sourceware.org/binutils/wiki/sframe) and the related [RFC](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900).
2025-06-03[llvm-readobj] Support --string-table for COFF (#141552)Haohai Wen1-1/+3
2024-02-27[SHT_LLVM_BB_ADDR_MAP] Adds pretty printing of BFI and BPI for PGO Analysis ↵Micah Weston1-1/+3
Map in tools. (#82292) Primary change is to add a flag `--pretty-pgo-analysis-map` to llvm-readobj and llvm-objdump that prints block frequencies and branch probabilities in the same manner as BFI and BPI respectively. This can be helpful if you are manually inspecting the outputs from the tools. In order to print, I moved the `printBlockFreqImpl` function from Analysis to Support and renamed it to `printRelativeBlockFreq`.
2024-02-22[llvm-readobj,ELF] Support --decompress/-z (#82594)Fangrui Song1-2/+2
When a section has the SHF_COMPRESSED flag, -p/-x dump the compressed content by default. In GNU readelf, if --decompress/-z is specified, -p/-x will dump the decompressed content. This patch implements the option. Close #82507
2023-10-13[tools] Stop including llvm/ADT/StringMap.h (NFC)Kazu Hirata1-1/+0
These source files do not use StringMap.h.
2023-10-13Stop including llvm/ADT/STLFunctionalExtras.h (NFC)Kazu Hirata1-1/+0
These source files do not use function_ref.
2023-09-11[llvm-readelf] Add --extra-sym-info (#65580)Fangrui Song1-4/+6
GNU readelf introduced --extra-sym-info/-X to display the section name for --syms (https://sourceware.org/PR30684). Port the feature, which is currently llvm-readelf only. For STO_AARCH64_VARIANT_PCS/STO_RISCV_VARIANT_PCS, the Ndx and Name columns may not be aligned.
2023-03-01[llvm-readobj] Add --memtagMitch Phillips1-0/+1
This adds functionality to readelf/readobj to specifically handle MTE-related bits, like the AARCH64_MEMTAG_* dynamic entries, and a decoder for the Android-specific ELF note. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D143693
2022-12-14Don't include Optional.hKazu Hirata1-1/+0
These files no longer use llvm::Optional.
2022-12-14[XCOFF] Decode the relocation entries of loader section of xcoff for ↵zhijian1-5/+4
llvm-readobj Summary: support decoding the relocation entries of loader section of xcoff for llvm-readobj https://www.ibm.com/docs/en/aix/7.2?topic=formats-xcoff-object-file-format#XCOFF__vra3i31ejbau Reviewers: James Henderson, Esme Yi Differential Revision: https://reviews.llvm.org/D136787
2022-12-14[llvm-readobj] llvm::Optional => std::optionalFangrui Song1-3/+3
Temporarily add expectedToStdOptional to llvm/Support/Error.h for migration.
2022-11-21[XCOFF] llvm-readobj support display symbol table of loader section of xcoff ↵zhijian1-1/+1
object file. Reviewers: James Henderson, Esme Yi Differential Revision: https://reviews.llvm.org/D135887
2022-11-19Revert "[XCOFF] llvvm-readobj support display symbol table of loader section ↵Vitaly Buka1-1/+1
of xcoff object file." Use of uninitialized value. This reverts commit 037f5c283a2278ef156189be48db0738323206bd.
2022-11-18[XCOFF] llvvm-readobj support display symbol table of loader section of ↵zhijian1-1/+1
xcoff object file. Reviewers: James Henderson, Esme Yi Differential Revision: https://reviews.llvm.org/D135887
2022-10-24[XCOFF] llvm-readobj support decoding the loader section header field for ↵zhijian1-0/+1
XCOFF object file. Reviewers: James Henderson, Esme Yi Differential Revision: https://reviews.llvm.org/D134883
2022-09-19[AIX] llvm-readobj support a new option --exception-section for xcoff object ↵zhijian1-0/+1
file. Summary: llvm-readobj support a new option --exception-section for xcoff object file. https://www.ibm.com/docs/en/aix/7.2?topic=formats-xcoff-object-file-format#XCOFF__iua3i23ajbau Reviewers: James Henderson,Paul Scoropan Differential Revision: https://reviews.llvm.org/D133030
2022-03-31better syntaxNico Weber1-1/+1
2022-03-31[llvm-readobj] Fix forward build breakages caused by ↵Vy Nguyen1-1/+2
https://reviews.llvm.org/rG33b3c86afab06ad61d46456c85c0b565cfff8287 Change: use std::function instead of function_ref because it's not safe to store a function_ref (original phab: https://reviews.llvm.org/D116787)
2022-03-31Reland "[llvm-readobj][MachO] Add option to sort the symbol table before ↵Vy Nguyen1-1/+56
dumping (MachO only, for now)." https://reviews.llvm.org/D116787 This reverts commit 33b3c86afab06ad61d46456c85c0b565cfff8287. New change: fixed build failures: - in stabs-sorted:restore the the ERR-KEY statements, which were accidentally deleted during refactoring - in ObjDumper.h/MachODumper.cpp: refactor so that current dumpers which didn't provide an impl that accept a SymCom still works
2022-03-31Revert "[llvm-readobj][MachO] Add option to sort the symbol table before ↵Vy Nguyen1-53/+5
dumping (MachO only, for now)." This reverts commit ea9cf2dc96c765773ee574a9189d529175a57751. Broke LLDB - reverting to investigage
2022-03-31[llvm-readobj][MachO] Add option to sort the symbol table before dumping ↵Vy Nguyen1-5/+53
(MachO only, for now). This would help making tests less brittle as the order will be fixed. (see also PR/53026) Differential Revision: https://reviews.llvm.org/D116787
2021-12-10[llvm-readobj] Add JSONScopedPrinter to llvm-readelfJayson Yan1-0/+4
Adds JSONScopedPrinter to llvm-readelf. It includes an empty JSONELFDumper class which will be used to override any LLVMELFDumper methods which utilize startLine() which JSONScopedPrinter cannot provide. This introduces a change where calls to llvm-readelf with non-ELF object files that specify --elf-output-style=GNU will now print file summary information where it previously didn't. Fixes previous Windows test failure which occured due to JSON escaping of '\' by not relying on LIT substitution. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D114225
2021-12-10Revert "[llvm-readobj] Add JSONScopedPrinter to llvm-readelf"Jayson Yan1-4/+0
This reverts commit 824eef231a853d7054d55010c16654f6f20e0394. file-summary-json.test and pretty-print.test fails on Windows.
2021-12-10[llvm-readobj] Add JSONScopedPrinter to llvm-readelfJayson Yan1-0/+4
Adds JSONScopedPrinter to llvm-readelf. It includes an empty JSONELFDumper class which will be used to override any LLVMELFDumper methods which utilize startLine() which JSONScopedPrinter cannot provide. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D114225
2021-10-26[AIX][XCOFF] parsing xcoff object file auxiliary headerzhijian1-0/+3
Summary: The patch supports parsing the xcoff object file auxiliary header with llvm-readobj with option "auxiliary-headers" the format of auxiliary header as https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/filesreference/XCOFF.html#XCOFF__fyovh386shar Reviewers: James Henderson, Jason Liu, Hubert Tong, Esme yi, Sean Fertile. Differential Revision: https://reviews.llvm.org/D82549
2021-08-03[llvm-readobj][XCOFF] Fix the error dumping for the firstEsme-Yi1-1/+1
item of StringTable. Summary: For the string table in XCOFF, the first 4 bytes contains the length of the string table, so we should print the string entries from fifth bytes. This patch also adds tests for llvm-readobj dumping the string table. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D105522
2021-07-05[llvm-readobj][XCOFF] Add support for printing the String Table.Esme-Yi1-0/+5
Summary: The patch adds the StringTable dumping to llvm-readobj. Currently only XCOFF is supported. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D104613
2021-03-08[llvm-readelf] Support dumping the BB address map section with --bb-addr-map.Rahman Lavaee1-0/+1
This patch lets llvm-readelf dump the content of the BB address map section in the following format: ``` Function { At: <address> BB entries [ { Offset: <offset> Size: <size> Metadata: <metadata> }, ... ] } ... ``` Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D95511
2020-12-01[llvm-readobj] - Introduce `ObjDumper::reportUniqueWarning(const Twine &Msg)`.Georgii Rymar1-0/+1
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[llvm-readelf/obj] - Move unique warning handling logic to the `ObjDumper`.Georgii Rymar1-1/+8
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-11-09Recommit: [llvm-readelf/obj] - Allow dumping of ELF header even if some ↵Georgii Rymar1-0/+2
elements are corrupt. This is recommit for D90903 with fixes for BB: 1) Used std::move<> when returning Expected<> (http://lab.llvm.org:8011/#/builders/112/builds/913) 2) Fixed the name of temporarily file in the file-headers.test (http://lab.llvm.org:8011/#/builders/36/builds/1269) (a local old temporarily file was used before) For creating `ELFObjectFile` instances we have the factory method `ELFObjectFile<ELFT>::create(MemoryBufferRef Object)`. The problem of this method is that it scans the section header to locate some sections. When a file is truncated or has broken fields in the ELF header, this approach does not allow us to create the `ELFObjectFile` and dump the ELF header. This is https://bugs.llvm.org/show_bug.cgi?id=40804 This patch suggests a solution - it allows to delay scaning sections in the `ELFObjectFile<ELFT>::create`. It now allows user code to call an object initialization (`initContent()`) later. With that it is possible, for example, for dumpers just to dump the file header and exit. By default initialization is still performed as before, what helps to keep the logic of existent callers untouched. I've experimented with different approaches when worked on this patch. I think this approach is better than doing initialization of sections (i.e. scan of them) on demand, because normally users of `ELFObjectFile` API expect to work with a valid object. In most cases when a section header table can't be read (because of an error), we don't have to continue to work with object. So we probably don't need to implement a more complex API. Differential revision: https://reviews.llvm.org/D90903
2020-11-09Revert "[llvm-readelf/obj] - Allow dumping of ELF header even if some ↵Georgii Rymar1-2/+0
elements are corrupt." This reverts commit ea8a0b8b29eb08d3f0f6ac40942a2d8e98ab57ee. It broke BBots. http://lab.llvm.org:8011/#/builders/14/builds/1439 http://lab.llvm.org:8011/#/builders/112/builds/913
2020-11-09[llvm-readelf/obj] - Allow dumping of ELF header even if some elements are ↵Georgii Rymar1-0/+2
corrupt. For creating `ELFObjectFile` instances we have the factory method `ELFObjectFile<ELFT>::create(MemoryBufferRef Object)`. The problem of this method is that it scans the section header to locate some sections. When a file is truncated or has broken fields in the ELF header, this approach does not allow us to create the `ELFObjectFile` and dump the ELF header. This is https://bugs.llvm.org/show_bug.cgi?id=40804 This patch suggests a solution - it allows to delay scaning sections in the `ELFObjectFile<ELFT>::create`. It now allows user code to call an object initialization (`initContent()`) later. With that it is possible, for example, for dumpers just to dump the file header and exit. By default initialization is still performed as before, what helps to keep the logic of existent callers untouched. I've experimented with different approaches when worked on this patch. I think this approach is better than doing initialization of sections (i.e. scan of them) on demand, because normally users of `ELFObjectFile` API expect to work with a valid object. In most cases when a section header table can't be read (because of an error), we don't have to continue to work with object. So we probably don't need to implement a more complex API. Differential revision: https://reviews.llvm.org/D90903
2020-10-27[llvm-readelf] - Implement --section-details option.Georgii Rymar1-1/+2
--section-details/-t is a GNU readelf option that produce an output that is an alternative to --sections. Differential revision: https://reviews.llvm.org/D89304
2020-10-08[llvm-readobj] Add --coff-tls-directory flag to print TLS Directory & test.Luqman Aden1-0/+1
Akin to dumpbin's /TLS option, this will print out the TLS directory, if present, in the image. Example output: ``` > llvm-readobj --coff-tls-directory test.exe File: test.exe Format: COFF-x86-64 Arch: x86_64 AddressSize: 64bit TLSDirectory { StartAddressOfRawData: 0x140004000 EndAddressOfRawData: 0x140004040 AddressOfIndex: 0x140002000 AddressOfCallBacks: 0x0 SizeOfZeroFill: 0x0 Characteristics [ (0x0) ] } ``` Reviewed By: jhenderson, grimar Differential Revision: https://reviews.llvm.org/D88635
2020-09-23[llvm-readelf/obj] - Cleanup the code. NFCI.Georgii Rymar1-3/+3
This: 1) Replaces pointers with references in many places. 2) Adds few TODOs about fixing possible unhandled errors (in ARMEHABIPrinter.h). 3) Replaces `auto`s with actual types. 4) Removes excessive arguments. 5) Adds `const ELFFile<ELFT> &Obj;` member to `ELFDumper` to simplify the code. Differential revision: https://reviews.llvm.org/D88097
2020-08-28[llvm-readobj] - Simplify the code that creates dumpers. NFCI.Georgii Rymar1-15/+12
We have a few helper functions like the following: ``` std::error_code create*Dumper(...) ``` In fact we do not need or want to use `std::error_code` and the code can be simpler if we just return `std::unique_ptr<ObjDumper>`. This patch does this change and refines the signature of `createDumper` as well. Differential revision: https://reviews.llvm.org/D86718
2020-05-27[llvm-readelf] - Split GNUStyle<ELFT>::printHashHistogram. NFC.Georgii Rymar1-1/+1
As was mentioned in review comments for D80204, `printHashHistogram` has 2 lambdas that are probably too large and deserves splitting into member functions. This patch does it. Differential revision: https://reviews.llvm.org/D80546
2020-05-15[llvm-readobj] - --gnu-hash-table: do not crash when the GNU hash table goes ↵Georgii Rymar1-1/+1
past the EOF. We might have a scenario where a the `GbuHashTable` variable correctly points to a place inside the file (we validate this fact early in `parseDynamicTable`), but nbuckets/maskwords fields are broken in the way the code tries to read the data past the EOF. This patch fixes the issue. Differential revision: https://reviews.llvm.org/D79853
2019-12-06[llvm-readobj] - Implement --dependent-libraries flag.Georgii Rymar1-0/+1
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-10-04[llvm-readobj] Replace arch-specific ObjDumper methods by the single ↵Simon Atanasyan1-9/+1
`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-08-05[llvm-readelf] Support dumping of stack sizes sections with readelf ↵Wolfgang Pieb1-0/+1
--stack-sizes Reviewers: jhenderson, grimar, rupprecht Differential Revision: https://reviews.llvm.org/D65313 llvm-svn: 367942
2019-06-18[llvm-readobj] Allow --hex-dump/--string-dump to dump multiple sectionsFangrui Song1-2/+4
1) `-x foo` currently dumps one `foo`. This change makes it dump all `foo`. 2) `-x foo -x foo` currently dumps `foo` twice. This change makes it dump `foo` once. In addition, if foo has section index 9, `-x foo -x 9` dumps `foo` once. 3) Give a warning instead of an error if `foo` does not exist. The new behaviors match GNU readelf. Also, print a new line as a separator between two section dumps. GNU readelf uses two lines, but one seems good enough. Reviewed By: grimar, jhenderson Differential Revision: https://reviews.llvm.org/D63475 llvm-svn: 363683
2019-05-03[Object][XCOFF] Add an XCOFF dumper for llvm-readobj.Sean Fertile1-0/+4
Patch adds support for dumping of file headers with llvm-readobj. XCOFF object files are added to test dumping a well formed file, and dumping both negative timestamps and negative symbol counts, both of which are allowed in the XCOFF definition. Differential Revision: https://reviews.llvm.org/D60878 llvm-svn: 359878
2019-02-07[CodeView] Fix cycles in debug info when merging Types with global hashes Alexandre Ganea1-5/+9
When type streams with forward references were merged using GHashes, cycles were introduced in the debug info. This was caused by GlobalTypeTableBuilder::insertRecordAs() not inserting the record on the second pass, thus yielding an empty ArrayRef at that record slot. Later on, upon PDB emission, TpiStreamBuilder::commit() would skip that empty record, thus offseting all indices that came after in the stream. This solution comes in two steps: 1. Fix the hash calculation, by doing a multiple-step resolution, iff there are forward references in the input stream. 2. Fix merge by resolving with multiple passes, therefore moving records with forward references at the end of the stream. This patch also adds support for llvm-readoj --codeview-ghash. Finally, fix dumpCodeViewMergedTypes() which previously could reference deleted memory. Fixes PR40221 Differential Revision: https://reviews.llvm.org/D57790 llvm-svn: 353412
2019-02-01[llvm-readobj] Add a flag to dump just the section-to-segment mapping.Matt Davis1-3/+13
Summary: The following patch introduces a new function `printSectionMapping` which is responsible for dumping just the section-to-segment mapping. This patch also introduces a n option `-section-mapping` that outputs that mapping without the program headers. Previously, this functionality was controlled by `printProgramHeaders`, and the output from `-program-headers` has not been changed. I am happy to change the option name, I copied the name that was displayed when outputting the mapping table. Reviewers: khemant, jhenderson, grimar, rupprecht Reviewed By: jhenderson, grimar, rupprecht Subscribers: rupprecht, jhenderson, llvm-commits Differential Revision: https://reviews.llvm.org/D57365 llvm-svn: 352896
2019-01-23[llvm-readelf] Don't suppress static symbol table with --dyn-symbols + --symbolsJames Henderson1-2/+10
In r287786, a bug was introduced into llvm-readelf where it didn't print the static symbol table if both --symbols and --dyn-symbols were specified, even if there was no dynamic symbol table. This is obviously incorrect. This patch fixes this issue, by delegating the decision of which symbol tables should be printed to the final dumper, rather than trying to decide in the command-line option handling layer. The decision was made to follow the approach taken in this patch because the LLVM style dumper uses a different order to the original GNU style behaviour (and GNU readelf) for ELF output. Other approaches resulted in behaviour changes for other dumpers which felt wrong. In particular, I wanted to avoid changing the order of the output for --symbols --dyn-symbols for LLVM style, keep what is emitted by --symbols unchanged for all dumpers, and avoid having different orders of .dynsym and .symtab dumping for GNU "--symbols" and "--symbols --dyn-symbols". Reviewed by: grimar, rupprecht Differential Revision: https://reviews.llvm.org/D57016 llvm-svn: 351960
2019-01-22[llvm-readelf]Revert --dyn-symbols behaviour to make it GNU compatible, and ↵James Henderson1-0/+1
add new --hash-symbols switch for old behaviour In r287786, the behaviour of --dyn-symbols in llvm-readelf (but not llvm-readobj) was changed to print the dynamic symbols as derived from the hash table, rather than to print the dynamic symbol table contents directly. The original change was initially submitted without review, and some comments were made on the commit mailing list implying that the new behavious is GNU compatible. I argue that it is not: 1) It does not include a null symbol. 2) It prints the symbols based on an order derived from the hash table. 3) It prints an extra column indicating which bucket it came from. This could break parsers that expect a fixed number of columns, with the first column being the symbol index. 4) If the input happens to have both .hash and .gnu.hash section, it prints interpretations of them both, resulting in most symbols being printed twice. 5) There is no way of just printing the raw dynamic symbol table, because --symbols also prints the static symbol table. This patch reverts the --dyn-symbols behaviour back to its old behaviour of just printing the contents of the dynamic symbol table, similar to what is printed by --symbols. As the hashed interpretation is still desirable to validate the hash table, it puts it under a new switch "--hash-symbols". This is a no-op on all output forms except for GNU output style for ELF. If there is no hash table, it does nothing, unlike the previous behaviour which printed the raw dynamic symbol table, since the raw dynsym is available under --dyn-symbols. The yaml input for the test is based on that in test/tools/llvm-readobj/demangle.test, but stripped down to the bare minimum to provide a valid dynamic symbol. Note: some LLD tests needed updating. I will commit a separate patch for those. Reviewed by: grimar, rupprecht Differential Revision: https://reviews.llvm.org/D56910 llvm-svn: 351789