aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/llvm-readobj.cpp
AgeCommit message (Collapse)AuthorFilesLines
4 days[Object] Beginnings of SFrame parser and dumper (#147294)Pavel Labath1-0/+4
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-05-03[tools] Remove unused local variables (NFC) (#138384)Kazu Hirata1-1/+0
2024-12-11Rework the `Option` library to reduce dynamic relocations (#119198)Chandler Carruth1-6/+8
Apologies for the large change, I looked for ways to break this up and all of the ones I saw added real complexity. This change focuses on the option's prefixed names and the array of prefixes. These are present in every option and the dominant source of dynamic relocations for PIE or PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of them for the Clang driver which has a huge number of options. This PR addresses this by building a string table and a prefixes table that can be referenced with indices rather than pointers that require dynamic relocations. This removes almost 7k dynmaic relocations from the `clang` binary, roughly 8% of the remaining dynmaic relocations outside of vtables. For busy-boxing use cases where many different option tables are linked into the same binary, the savings add up a bit more. The string table is a straightforward mechanism, but the prefixes required some subtlety. They are encoded in a Pascal-string fashion with a size followed by a sequence of offsets. This works relatively well for the small realistic prefixes arrays in use. Lots of code has to change in order to land this though: both all the option library code has to be updated to use the string table and prefixes table, and all the users of the options library have to be updated to correctly instantiate the objects. Some follow-up patches in the works to provide an abstraction for this style of code, and to start using the same technique for some of the other strings here now that the infrastructure is in place.
2024-08-09[llvm-readobj][COFF] Dump hybrid objects for ARM64X files. (#102245)Jacek Caban1-0/+18
2024-07-07[llvm] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#97914)Kazu Hirata1-3/+3
2024-04-22[llvm-readobj] Remove --raw-relrFangrui Song1-2/+0
https://reviews.llvm.org/D47919 dumped RELR relocations as `R_*_RELATIVE` and added --raw-relr (not in GNU) for testing purposes (more readable than `llvm-readelf -x .relr.dyn`). The option is obsolete after `llvm-readelf -r` output gets improved (#89162). Since --raw-relr never seems to get more adoption. Let's remove it to avoid some complexity. Pull Request: https://github.com/llvm/llvm-project/pull/89426
2024-02-27[SHT_LLVM_BB_ADDR_MAP] Adds pretty printing of BFI and BPI for PGO Analysis ↵Micah Weston1-1/+7
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/+4
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
2024-01-11[llvm-driver] Fix usage of `InitLLVM` on Windows (#76306)Alexandre Ganea1-2/+0
Previously, some tools such as `clang` or `lld` which require strict order for certain command-line options, such as `clang -cc1` or `lld -flavor`, would not longer work on Windows, when these tools were linked as part of `llvm-driver`. This was caused by `InitLLVM` which was part of the `*_main()` function of these tools, which in turn calls `windows::GetCommandLineArguments`. That function completly replaces argc/argv by new UTF-8 contents, so any ajustements to argc/argv made by `llvm-driver` prior to calling these tools was reset. `InitLLVM` is now called by the `llvm-driver`. Any tool that participates in (or is part of) the `llvm-driver` doesn't call `InitLLVM` anymore.
2023-09-11[llvm-readelf] Add --extra-sym-info (#65580)Fangrui Song1-1/+4
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-08-04[llvm] Extract common `OptTable` bits into macrosJan Svoboda1-10/+2
All command-line tools using `llvm::opt` create an enum of option IDs and a table of `OptTable::Info` object. Most of the tools use the same ID (`OPT_##ID`), kind (`Option::KIND##Class`), group ID (`OPT_##GROUP`) and alias ID (`OPT_##ALIAS`). This patch extracts that common code into canonical macros. This results in fewer changes when tweaking the `OPTION` macros emitted by the TableGen backend. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D157028
2023-03-01[llvm-readobj] Add --memtagMitch Phillips1-0/+5
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
2023-02-10[llvm-driver] Pass extra arguments to toolsAlex Brachet1-1/+2
Differential Revision: https://reviews.llvm.org/D137799
2023-01-12[OptTable] Precompute OptTable prefixes union table through tablegenserge-sans-paille1-2/+4
This avoid rediscovering this table when reading each options, providing a sensible 2% speedup when processing and empty file, and a measurable speedup on typical workloads, see: This is optional, the legacy, on-the-fly, approach can still be used through the GenericOptTable class, while the new one is used through PrecomputedOptTable. https://llvm-compile-time-tracker.com/compare.php?from=4da6cb3202817ee2897d6b690e4af950459caea4&to=19a492b704e8f5c1dea120b9c0d3859bd78796be&stat=instructions:u Differential Revision: https://reviews.llvm.org/D140800
2022-12-27[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-1/+4
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This a recommit of e953ae5bbc313fd0cc980ce021d487e5b5199ea4 and the subsequent fixes caa713559bd38f337d7d35de35686775e8fb5175 and 06b90e2e9c991e211fecc97948e533320a825470. The above patchset caused some version of GCC to take eons to compile clang/lib/Basic/Targets/AArch64.cpp, as spotted in aa171833ab0017d9732e82b8682c9848ab25ff9e. The fix is to make BuiltinInfo tables a compilation unit static variable, instead of a private static variable. Differential Revision: https://reviews.llvm.org/D139881
2022-12-25Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵Vitaly Buka1-4/+1
builtin and call information" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4 (part 2)" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4" GCC build hangs on this bot https://lab.llvm.org/buildbot/#/builders/37/builds/19104 compiling CMakeFiles/obj.clangBasic.dir/Targets/AArch64.cpp.d The bot uses GNU 11.3.0, but I can reproduce locally with gcc (Debian 12.2.0-3) 12.2.0. This reverts commit caa713559bd38f337d7d35de35686775e8fb5175. This reverts commit 06b90e2e9c991e211fecc97948e533320a825470. This reverts commit e953ae5bbc313fd0cc980ce021d487e5b5199ea4.
2022-12-24[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-1/+4
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 that into account a GGC issue (probably https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92181) when dealing with intiailizer_list and constant expressions. Workaround this by avoiding initializer list, at the expense of a temporary plain old array. Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-3/+2
builtin and call information" There are still remaining issues with GCC 12, see for instance https://lab.llvm.org/buildbot/#/builders/93/builds/12669 This reverts commit 5ce4e92264102de21760c94db9166afe8f71fcf6.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-2/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 with a change to llvm/utils/TableGen/OptParserEmitter.cpp to cope with GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-3/+2
builtin and call information" Failing builds: https://lab.llvm.org/buildbot#builders/9/builds/19030 This is GCC specific and has been reported upstream: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 This reverts commit 719d98dfa841c522d8d452f0685e503538415a53.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-2/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139881
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-2/+7
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-1/+1
Temporarily add expectedToStdOptional to llvm/Support/Error.h for migration.
2022-12-08Store OptTable::Info::Name as a StringRefserge-sans-paille1-1/+1
This is a recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e, with a few cleanups. This avoids implicit conversion to StringRef at several points, which in turns avoid redundant calls to strlen. As a side effect, this greatly simplifies the implementation of StrCmpOptionNameIgnoreCase. It also eventually gives a consistent, humble speedup in compilation time (timing updated since original commit). https://llvm-compile-time-tracker.com/compare.php?from=de4b6a1bc64db33643f001ad45fae7b92b4a4688&to=c23a93d1292052b4be2fbe8c586fa31143d0c7ed&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139274
2022-11-21[XCOFF] llvm-readobj support display symbol table of loader section of xcoff ↵zhijian1-2/+5
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-5/+2
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-2/+5
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-2/+9
XCOFF object file. Reviewers: James Henderson, Esme Yi Differential Revision: https://reviews.llvm.org/D134883
2022-10-06Fix d5090cd94, MSVC mangling issueAlex Brachet1-1/+1
Evidently * and [] are mangled differently by MSVC...
2022-10-06[llvm-driver] Add various tools to the llvm-driverAlex Brachet1-1/+1
The llvm-driver, enabled with LLVM_TOOL_LLVM_DRIVER_BUILD combines many llvm executables into one to save overall toolchain size. This patch adds a few more llvm tools to the llvm-driver. Differential Revision: https://reviews.llvm.org/D135281
2022-09-19[AIX] llvm-readobj support a new option --exception-section for xcoff object ↵zhijian1-0/+8
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-31Reland "[llvm-readobj][MachO] Add option to sort the symbol table before ↵Vy Nguyen1-1/+52
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-52/+1
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-1/+52
(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
2022-01-12[MachO] Port call graph profile section and directiveLeonard Grey1-0/+2
This ports the `.cg_profile` assembly directive and call graph profile section generation to MachO from COFF/ELF. Due to MachO section naming rules, the section is called `__LLVM,__cg_profile` rather than `.llvm.call-graph-profile` as in COFF/ELF. Support for llvm-readobj is included to facilitate testing. Corresponding LLD change is D112164 Differential Revision: https://reviews.llvm.org/D112160
2022-01-08[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-2/+2
Identified with readability-redundant-member-init.
2022-01-03Revert "[llvm] Remove redundant member initialization (NFC)"Kazu Hirata1-2/+2
This reverts commit fd4808887ee47f3ec8a030e9211169ef4fb094c3. This patch causes gcc to issue a lot of warnings like: warning: base class ‘class llvm::MCParsedAsmOperand’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-01[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-2/+2
Identified with readability-redundant-member-init.
2021-12-10[llvm-readobj] Add JSONScopedPrinter to llvm-readelfJayson Yan1-23/+26
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-26/+23
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-23/+26
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/+11
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-10-18[llvm-readobj] Delete redundant 'static' from namespace scope 'static ↵Fangrui Song1-1/+1
const'. NFC By default, such a non-template variable of non-volatile const-qualified type having namespace-scope has internal linkage ([basic.link]), so no need for `static`.
2021-10-08Move TargetRegistry.(h|cpp) from Support to MCReid Kleckner1-1/+1
This moves the registry higher in the LLVM library dependency stack. Every client of the target registry needs to link against MC anyway to actually use the target, so we might as well move this out of Support. This allows us to ensure that Support doesn't have includes from MC/*. Differential Revision: https://reviews.llvm.org/D111454
2021-07-28[llvm] Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]]Fangrui Song1-2/+2
[[noreturn]] can be used since Oct 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015. Note: the definition of LLVM_ATTRIBUTE_NORETURN is kept for now.
2021-07-12[llvm-readobj] Switch command line parsing from llvm::cl to OptTableFangrui Song1-388/+208
Users should generally observe no difference as long as they don't use unintended option forms. Behavior changes: * `-t=d` is removed. Use `-t d` instead. * `--demangle=false` and `--demangle=0` cannot be used. Omit the option or use `--no-demangle`. Other flag-style options don't have `--no-` forms. * `--help-list` is removed. This is a `cl::` specific option. * llvm-readobj now supports grouped short options as well. * `--color` is removed. This is generally not useful (only apply to errors/warnings) but was inherited from Support. Some adjustment to the canonical forms (usually from GNU readelf; currently llvm-readobj has too many redundant aliases): * --dyn-syms is canonical. --dyn-symbols is a hidden alias * --file-header is canonical. --file-headers is a hidden alias * --histogram is canonical. --elf-hash-histogram is a hidden alias * --relocs is canonical. --relocations is a hidden alias * --section-groups is canonical. --elf-section-groups is a hidden alias OptTable avoids global option collision if we decide to support multiplexing for binary utilities. * Most one-dash long options are still supported. `-dt, -sd, -st, -sr` are dropped due to their conflict with grouped short options. * `--section-mapping=false` (D57365) is strange but is kept for now. * Many `cl::opt` variables were unnecessarily external. I added `static` whenever appropriate. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D105532
2021-07-05[llvm-readobj][XCOFF] Add support for printing the String Table.Esme-Yi1-0/+7
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-06-29[llvm-readobj] Make -s and -t match llvm-readelfFangrui Song1-20/+7
llvm-readobj is an internal testing tool for binary formats. Its output and command line options do not need to be stable. It isn't supposed to be part of a build process. llvm-readelf was created as a user-facing utility and its interface intends to be compatible with GNU readelf (unless there are good reasons not to). The two tools have mostly compatible options. -s and -t are noticeable exceptions due to history. I think the cost of keeping the inconsistency overweighs the little history-compatible benefit and hinders transition from cl::opt to OptTable, so let's change it. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D105055
2021-05-12[llvm-readelf] Unhide short options to match the command guidegbreynoo1-10/+11
The readelf command guide shows the short options used as aliases but these are not found in the help text unless --show-hidden is used, other tools show aliases with --help. This change fixes the help output to be consistent with the command guide. Differential Revision: https://reviews.llvm.org/D102173