aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-08MC: Add Triple overloads for more MC constructors (#157321)Matt Arsenault1-19/+20
Avoids more Triple->string->Triple round trip. This is a continuation of f137c3d592e96330e450a8fd63ef7e8877fc1908
2025-08-07[RISCV] Basic Objdump Mapping Symbol Support (#151452)Sam Elliott1-1/+7
This implements very basic support for RISC-V mapping symbols in llvm-objdump, sharing the implementation with how Arm/AArch64/CSKY implement this feature. This only supports the `$x` (instruction) and `$d` (data) mapping symbols for RISC-V, and not the version of `$x` which includes an architecture string suffix.
2025-08-04[DirectX] Add ObjectFile boilerplate for objdump (#151434)Chris B1-0/+3
This change adds boilerplate code to implement the object::ObjectFile interface for the DXContainer object file and an empty implementation of the objdump Dumper object. Adding an ObjectFile implementation for DXContainer is a bit odd because the DXContainer format doesn't have a symbol table, so there isn't a reasonable implementation for the SymbolicFile interfaces. That said, it does have sections, and it will be useful for objdump to be able to inspect some of the structured data stored in some of the special named sections. At this point in the implementation it can't do much other than dump the part names, offsets, and sizes. Dumping detailed structured section contents to be extended in subsequent PRs. Fixes #151433
2025-08-04[llvm] Use llvm::iterator_range::empty (NFC) (#151905)Kazu Hirata1-1/+1
2025-07-21[llvm-objdump] Add inlined function display support (#142246)gulfemsavrun1-62/+82
This patch adds the support for displaying inlined functions into llvm-objdump. 1) It extends the source variable display support for inlined functions both for ascii and unicode formats. 2) It also introduces a new format called limits-only that only prints a line for the start and end of an inlined function without line-drawing characters.
2025-07-18[Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807)quic-areg1-73/+107
Hexagon instructions are VLIW "bundles" of up to four instruction words encoded as a single MCInst with operands for each sub-instruction. Previously, the disassembler's getInstruction() returned the full bundle, which made it difficult to work with llvm-objdump. For example, since all instructions are bundles, and bundles do not branch, branch targets could not be printed. This patch modifies the Hexagon disassembler to return individual sub-instructions instead of entire bundles, enabling correct printing of branch targets and relocations. It also introduces `MCDisassembler::getInstructionBundle` for cases where the full bundle is still needed. By default, llvm-objdump separates instructions with newlines. However, this does not work well for Hexagon syntax: { inst1 inst2 inst3 inst4 <branch> } :endloop0 Instructions may be followed by a closing brace, a closing brace with `:endloop`, or a newline. Branches must appear within the braces. To address this, `PrettyPrinter::getInstructionSeparator()` is added and overridden for Hexagon.
2025-06-25[llvm-objdump] Support --symbolize-operand on AArch64Alexis Engelke1-1/+2
Similar to the existing implementations for X86 and PPC, support symbolizing branch targets for AArch64. Do not omit the address for ADRP as the target is typically not at an intended location. Pull Request: https://github.com/llvm/llvm-project/pull/145009
2025-05-30[Hexagon][llvm-objdump] Fix crash at a truncated instruction (#142082)Alexey Karyakin1-4/+8
Fixes #141740. Co-authored-by: Alexey Karyakin <quic-akaryaki@quicinc.com> Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2025-05-25[llvm-objdump] Remove unused includes (NFC) (#141390)Kazu Hirata1-3/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-23Extend llvm objdump fatbin (#140286)David Salinas1-1/+2
Utilize the new extensions to the LLVM Offloading API to extend to llvm-objdump to handle dumping fatbin offload bundles generated by HIP. This extension to llvm-objdump adds the option --offload-fatbin. Specifying this option will take the input object/executable and extract all offload fatbin bundle entries into distinct code object files with names reflecting the source file name combined with the Bundle Entry ID. Users can also use the --arch-name option to filter offload fatbin bundle entries by their target triple. --------- Co-authored-by: dsalinas <dsalinas@MKM-L1-DSALINAS.amd.com>
2025-05-20[llvm-objdump] --adjust-vma: Call getInstruction with adjusted addressFangrui Song1-1/+1
llvm-objdump currently calls MCDisassembler::getInstruction with unadjusted address and MCInstPrinter::printInst with adjusted address. The decoded branch targets will be adjusted as expected for most targets (as the getInstruction address is insignificant) but not for SystemZ (where the getInstruction address is displayed). Specify an adjust address to fix SystemZInstPrinter output. The added test utilizes llvm/utils/update_test_body.py to make updates easier and additionally checks that we don't adjust SHN_ABS symbol addresses. Pull Request: https://github.com/llvm/llvm-project/pull/140471
2025-05-16Revert "Reapply: [llvm-objdump] Add support for HIP offload bundles (#140128)"Kazu Hirata1-2/+1
This reverts commit 910220b84fa18ce2cbb2e21dd53b9f3d0ae582a7. Multiple buildbot failures have been reported: https://github.com/llvm/llvm-project/pull/140128
2025-05-16Reapply: [llvm-objdump] Add support for HIP offload bundles (#140128)David Salinas1-1/+2
Utilize the new extensions to the LLVM Offloading API to extend to llvm-objdump to handle dumping fatbin offload bundles generated by HIP. This extension to llvm-objdump adds the option --offload-fatbin. Specifying this option will take the input object/executable and extract all offload fatbin bundle entries into distinct code object files with names reflecting the source file name combined with the Bundle Entry ID. Users can also use the --arch-name option to filter offload fatbin bundle entries by their target triple. --------- Co-authored-by: dsalinas <dsalinas@MKM-L1-DSALINAS.amd.com>
2025-05-15[NFC][llvm-objdump] Add ostream param to control console prints (#139931)Prabhu Rajasekaran1-30/+29
2025-05-11[llvm-objdump] Print symbolized labels with increasing index (#139415)Sergei Barannikov1-4/+7
To make it easier to navigate the disassembly listing.
2025-05-10llvm-objdump --adjust-vma: Don't adjust VMA in inline reloc addressesFangrui Song1-9/+1
--adjust-vma adjusts the current section address. The address printed for inline relocs is relative to the current section address instead of the section that the referenced symbol resides in. Fix https://github.com/llvm/llvm-project/issues/75444
2025-05-08Revert "[llvm-objdump] Add support for HIP offload bundles (#114834)"Kazu Hirata1-2/+1
This reverts commit 06d6623bc304d5fc2fe11b80b62b4c5d10f9eaa1. Buildbot failure: https://lab.llvm.org/buildbot/#/builders/145/builds/6871/steps/5/logs/stdio
2025-05-08[llvm-objdump] Add support for HIP offload bundles (#114834)David Salinas1-1/+2
Utilize the new extensions to the LLVM Offloading API to extend to llvm-objdump to handle dumping fatbin offload bundles generated by HIP. This extension to llvm-objdump adds the option --offload-fatbin. Specifying this option will take the input object/executable and extract all offload fatbin bundle entries into distinct code object files with names reflecting the source file name combined with the Bundle Entry ID. Users can also use the --arch-name option to filter offload fatbin bundle entries by their target triple. --------- Co-authored-by: dsalinas <dsalinas@MKM-L1-DSALINAS.amd.com>
2025-04-14[tools] Use llvm::append_range (NFC) (#135721)Kazu Hirata1-2/+1
2025-03-28[tools] Use *Set::insert_range (NFC) (#133384)Kazu Hirata1-2/+1
We can use *Set::insert_range to replace "for" loop-based insertions. In some cases, we can further fold insert_range into the set declaration.
2025-03-26[llvm-objdump][ARM] Find ELF file PLT entries for arm, thumb (#130764)Vladislav Dzhidzhoev1-8/+38
This implements arm, armeb, thumb, thumbeb PLT entries parsing support in ELF for llvm-objdump. Implementation is similar to AArch64MCInstrAnalysis::findPltEntries. PLT entry signatures are based on LLD code for PLT generation (ARM::writePlt). llvm-objdump tests are produced from lld/test/ELF/arm-plt-reloc.s, lld/test/ELF/armv8-thumb-plt-reloc.s.
2025-03-20[llvm] Use *Set::insert_range (NFC) (#132325)Kazu Hirata1-1/+1
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2025-03-18[llvm-objdump] Pass MCSubtargetInfo to findPltEntries (NFC) (#131773)Vladislav Dzhidzhoev1-3/+3
It allows access to subtarget features, collected in llvm-objdump.cpp, from findPltEntries, which will be used in https://github.com/llvm/llvm-project/pull/130764.
2025-02-28[llvm-objdump] Rework .gnu.version_d dumpingFangrui Song1-1/+1
and fix crash when vd_aux is invalid (#86611). vd_version, vd_flags, vd_ndx, and vd_cnt in Elf{32,64}_Verdef are 16-bit. Change VerDef to use uint16_t instead. vda_name specifies a NUL-terminated string. Update getVersionDefinitions to remove some `.c_str()`. Pull Request: https://github.com/llvm/llvm-project/pull/128434
2025-01-22[StrTable] Switch the option parser to `llvm::StringTable` (#123308)Chandler Carruth1-1/+2
Now that we have a dedicated abstraction for string tables, switch the option parser library's string table over to it rather than using a raw `const char*`. Also try to use the `StringTable::Offset` type rather than a raw `unsigned` where we can to avoid accidental increments or other issues. This is based on review feedback for the initial switch of options to a string table. Happy to tweak or adjust if desired here.
2024-12-23[llvm-objdump] Remove some unneeded headers. (#120541)Cabbaken1-5/+0
Co-authored-by: qiuruoyu <qiuruoyu@xiaomi.com>
2024-12-11Rework the `Option` library to reduce dynamic relocations (#119198)Chandler Carruth1-17/+22
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-12-03[llvm-objdump] Default to --mattr=+all for AArch64be and AArch64_32 (#118311)hstk30-hw1-1/+1
GNU objdump disassembles all unknown instructions by default. Complement for [D128030](https://reviews.llvm.org/D128030)。
2024-10-28[llvm-objdump] Handle -M for --machoFangrui Song1-1/+1
--macho -d uses the `parseInputMachO` code path, which does not handle -M. Add -M handling for --macho as well. Close #61019 Pull Request: https://github.com/llvm/llvm-project/pull/113795
2024-09-25[llvm-objdump] Print ... even if a data mapping symbol is activeFangrui Song1-17/+18
Swap `!DisassembleZeroes` and `if (DumpARMELFData)` conditions so that in the false DisassembleZeroes case (default), `...` will be printed for long consecutive zeroes, even when a data mapping symbol is active. This is especially useful for certain lld tests that insert a huge padding within a code section. Without `...` the output will be huge. Pull Request: https://github.com/llvm/llvm-project/pull/109553
2024-08-15llvm-objdump: ensure a MachO symbol isn't STAB before looking up secion (#86667)Tim Northover1-10/+10
The section field has been repurposed for some STAB symbol types, and if we blindly look it up we'll produce an error and terminate. Logic already existed Existing stabs test had a section that was in range. Unfortunately I don't know of an easy way to produce stabs entries in LLVM (I thought they died in the 90s until this came up) so I just binary-edited it to cause a failure on existing llvm-objdump.
2024-07-31[llvm-objdump][BPF] --symbolize-operands: infer local labels for BPF (#100550)eddyz871-2/+4
Enable local labels computation for BPF disassembly when `--symbolize-operands` option is specified. This relies on `MCInstrAnalysis::evaluateBranch()` method, which is already defined in `BPFMCInstrAnalysis::evaluateBranch`. After this change the assembly code below: if r1 > 42 goto +1 r1 -= 10 ... Would be printed as: if r1 > 42 goto +1 <L0> r1 -= 10 <L0>: ... (when `--symbolize-operands` option is set). See https://reviews.llvm.org/D84191 for the main part of the `--symbolize-operands` implementation logic.
2024-07-08[llvm-objdump] -r: support CRELFangrui Song1-0/+10
Extract the llvm-readelf decoder to `decodeCrel` (#91280) and reuse it for llvm-objdump. Because the section representation of LLVMObject (`SectionRef`) is 64-bit, insufficient to hold all decoder states, `section_rel_begin` is modified to decode CREL eagerly and hold the decoded relocations inside ELFObjectFile<ELFT>. The test is adapted from llvm/test/tools/llvm-readobj/ELF/crel.test. Pull Request: https://github.com/llvm/llvm-project/pull/97382
2024-06-21[llvm-objdump] enable file-headers option of llvm-objdump for XCOFF object ↵zhijian lin1-1/+1
files (#96104) the patch enable file-headers option of llvm-objdump for XCOFF object files
2024-06-14[llvm] Use llvm::unique (NFC) (#95628)Kazu Hirata1-2/+1
2024-04-26[RISCV] Add an instruction PrettyPrinter to llvm-objdump (#90093)Craig Topper1-0/+52
This prints the opcode bytes in the same order as GNU objdump without a space between them.
2024-04-18 [AMDGPU] Add disassembler diagnostics for invalid kernel descriptors (#87400)Emma Pilkington1-30/+35
These mostly are checking for various reserved bits being set. The diagnostics for gpu-dependent reserved bits have a bit more context since they seem like the most likely ones to be observed in practice. This commit also improves the error handling mechanism for MCDisassembler::onSymbolStart(). Previously it had a comment stream parameter that was just being ignored by llvm-objdump, now it returns errors using Expected<T>.
2024-03-28[Support] Fix color handling in formatted_raw_ostream (#86700)Andrew Ng1-7/+0
The color methods in formatted_raw_ostream were forwarding directly to the underlying stream without considering existing buffered output. This would cause incorrect colored output for buffered uses of formatted_raw_ostream. Fix this issue by applying the color to the formatted_raw_ostream itself and temporarily disabling scanning of any color related output so as not to affect the position tracking. This fix means that workarounds that forced formatted_raw_ostream buffering to be disabled can be removed. In the case of llvm-objdump, this can improve disassembly performance when redirecting to a file by more than an order of magnitude on both Windows and Linux. This improvement restores the disassembly performance when redirecting to a file to a level similar to before color support was added.
2024-02-27[SHT_LLVM_BB_ADDR_MAP] Adds pretty printing of BFI and BPI for PGO Analysis ↵Micah Weston1-7/+22
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-09Fix 01706e7 on 32-bit platformsDerek Schuff1-1/+2
Make the type match the printf format.
2024-02-09[llvm-nm][WebAssembly] Print function symbol sizes (#81315)Derek Schuff1-0/+3
nm already prints sizes for data symbols. Do that for function symbols too, and update objdump to also print size information. Implements item 3 from https://github.com/llvm/llvm-project/issues/76107
2024-02-07[Object][Wasm] Use file offset for section addresses in linked wasm files ↵Derek Schuff1-3/+13
(#80529) Wasm has no unified virtual memory space as other object formats and architectures do, so previously WasmObjectFile reported 0 for all section addresses, and until 428cf71ff used section offsets for function symbols. Now we use file offsets for function symbols, and this change switches section addresses to do the same (in linked files). The main result of this is that objdump now reports VMAs in section listings, and also uses file offets rather than section offsets when disassembling linked binaries (matching the behavior of other disassemblers and stack traces produced by browwsers). To make this work, this PR also updates objdump's generation of synthetics fallback symbols to match lib/Object and also correctly plumbs symbol types for regular and dummy symbols through to the backend to avoid needing special knowledge of address 0. This also paves the way for generating symbols from name sections rather than symbol tables or imports (see #76107) by allowing the disassembler's synthetic fallback symbols match the name-section generated symbols (in a followup PR).
2024-02-01[SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used ↵Rahman Lavaee1-74/+132
together by decoupling the handling of the two features. (#74128) Today `-split-machine-functions` and `-fbasic-block-sections={all,list}` cannot be combined with `-basic-block-sections=labels` (the labels option will be ignored). The inconsistency comes from the way basic block address map -- the underlying mechanism for basic block labels -- encodes basic block addresses (https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html). Specifically, basic block offsets are computed relative to the function begin symbol. This relies on functions being contiguous which is not the case for MFS and basic block section binaries. This means Propeller cannot use binary profiles collected from these binaries, which limits the applicability of Propeller for iterative optimization. To make the `SHT_LLVM_BB_ADDR_MAP` feature work with basic block section binaries, we propose modifying the encoding of this section as follows. First let us review the current encoding which emits the address of each function and its number of basic blocks, followed by basic block entries for each basic block. | | | |--|--| | Address of the function | Function Address | | Number of basic blocks in this function | NumBlocks | | BB entry 1 | BB entry 2 | ... | BB entry #NumBlocks To make this work for basic block sections, we treat each basic block section similar to a function, except that basic block sections of the same function must be encapsulated in the same structure so we can map all of them to their single function. We modify the encoding to first emit the number of basic block sections (BB ranges) in the function. Then we emit the address map of each basic block section section as before: the base address of the section, its number of blocks, and BB entries for its basic block. The first section in the BB address map is always the function entry section. | | | |--|--| | Number of sections for this function | NumBBRanges | | Section 1 begin address | BaseAddress[1] | | Number of basic blocks in section 1 | NumBlocks[1] | | BB entries for Section 1 |..................| | Section #NumBBRanges begin address | BaseAddress[NumBBRanges] | | Number of basic blocks in section #NumBBRanges | NumBlocks[NumBBRanges] | | BB entries for Section #NumBBRanges The encoding of basic block entries remains as before with the minor change that each basic block offset is now computed relative to the begin symbol of its containing BB section. This patch adds a new boolean codegen option `-basic-block-address-map`. Correspondingly, the front-end flag `-fbasic-block-address-map` and LLD flag `--lto-basic-block-address-map` are introduced. Analogously, we add a new TargetOption field `BBAddrMap`. This means BB address maps are either generated for all functions in the compiling unit, or for none (depending on `TargetOptions::BBAddrMap`). This patch keeps the functionality of the old `-fbasic-block-sections=labels` option but does not remove it. A subsequent patch will remove the obsolete option. We refactor the `BasicBlockSections` pass by separating the BB address map and BB sections handing to their own functions (named `handleBBAddrMap` and `handleBBSections`). `handleBBSections` renumbers basic blocks and places them in their assigned sections. `handleBBAddrMap` is invoked after `handleBBSections` (if requested) and only renumbers the blocks. - New tests added: - Two tests basic-block-address-map-with-basic-block-sections.ll and basic-block-address-map-with-mfs.ll to exercise the combination of `-basic-block-address-map` with `-basic-block-sections=list` and '-split-machine-functions`. - A driver sanity test for the `-fbasic-block-address-map` option (basic-block-address-map.c). - An LLD test for testing the `--lto-basic-block-address-map` option. This reuses the LLVM IR from `lld/test/ELF/lto/basic-block-sections.ll`. - Renamed and modified the two existing codegen tests for basic block address map (`basic-block-sections-labels-functions-sections.ll` and `basic-block-sections-labels.ll`) - Removed `SHT_LLVM_BB_ADDR_MAP_V0` tests. Full deprecation of `SHT_LLVM_BB_ADDR_MAP_V0` and `SHT_LLVM_BB_ADDR_MAP` version less than 2 will happen in a separate PR in a few months.
2024-02-01[llvm-objdump][AMDGPU] Pass ELF ABIVersion through disassembler (#78907)Emma Pilkington1-0/+3
Admittedly, its a bit ugly to pass the ABIVersion through onSymbolStart but I'm not sure what a better place for it would be.
2024-01-25[llvm-objdump,SHT_LLVM_BB_ADDR_MAP,NFC] Use auto && instead of const auto & ↵Rahman Lavaee1-1/+1
to allow moving from BBAddrMap objects. (#79456) std::move on `const auto &` references is essentially a noop. Changing to `auto &&` to actually allow moving.
2024-01-19[llvm-objdump] Add support for symbolizing PGOBBAddrMap Info (#76386)Aiden Grossman1-17/+83
This patch adds in support for symbolizing PGO information contained within the SHT_LLVM_BB_ADDR_MAP section in llvm-objdump. The outputs are simply the raw values contained within the section.
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-12-21[XCOFF] Use RLDs to print branches even without -r (#74342)stephenpeckham1-50/+121
This presents misleading and confusing output. If you have a function defined at the beginning of an XCOFF object file, and you have a function call to an external function, the function call disassembles as a branch to the local function. That is, `void f() { f(); g();}` disassembles as >00000000 <.f>: 0: 7c 08 02 a6 mflr 0 4: 94 21 ff c0 stwu 1, -64(1) 8: 90 01 00 48 stw 0, 72(1) c: 4b ff ff f5 bl 0x0 <.f> 10: 4b ff ff f1 bl 0x0 <.f> With this PR, the second call will display: `10: 4b ff ff f1 bl 0x0 <.g> ` Using -r can help, but you still get the confusing output: >10: 4b ff ff f1 bl 0x0 <.f> 00000010: R_RBR .g
2023-12-19[llvm-objdump] Add -mllvm (#75892)Fangrui Song1-4/+7
When llvm-objdump switched from cl:: to OptTable (https://reviews.llvm.org/D100433), we dropped support for LLVM cl:: options. Some LLVM_DEBUG in `llvm/lib/Target/$target/MCDisassembler/` files might be useful. Add -mllvm to allow dumping the information. ``` # -debug is available in an LLVM_ENABLE_ASSERTIONS=on build llvm-objdump -d -mllvm -debug a.o > /dev/null ``` Link: https://discourse.llvm.org/t/how-to-enable-debug-logs-in-llvm-objdump/75758
2023-12-18[llvm-objdump] --disassemble-symbols: skip inline relocs from symbols that ↵Fangrui Song1-1/+8
are not dumped (#75724) When a section contains two functions x1 and x2, we incorrectly display x1's relocations when dumping x2 for `--disassemble-symbols=x2 -r`. Fix #75539 by ignoring these relocations.