aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-12-02[llvm-objdump] Stop including llvm/ADT/IndexedMap.h (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-11-17[NFC][SHT_LLVM_BB_ADDR_MAP] Define and use constructor and accessors for ↵Rahman Lavaee1-2/+2
BBAddrMap fields. (#72689) The fields are still kept as public for now since our tooling accesses them. Will change them to private visibility in a later patch.
2023-11-15[NFC] Rename variable to better document usage. (#71973)stephenpeckham1-5/+5
Change variable DisassembleAsData to DisassembleAsELFData so that its name better matches its usage.
2023-11-14[llvm] Add missing include for std::set after 01702c3f7f1a (#72161)Mike Hommey1-0/+1
Cc: @kazutakahirata
2023-11-11[llvm] Stop including llvm/ADT/SmallSet.h (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-10-20[RISCV][MC] Implement evaluateBranch for auipc+jalr pairs (#65480)Job Noorman1-0/+4
This patch implements `MCInstrAnalysis` state in order to be able analyze auipc+jalr pairs inside `evaluateBranch`. This is implemented as follows: - State: array of currently known GPR values; - Whenever an auipc is detected in `updateState`, update the state value of RD with the immediate; - Whenever a jalr is detected in `evaluateBranch`, check if the state holds a value for RS1 and use that to compute its target. Note that this is similar to how binutils implements it and the output of llvm-objdump should now mostly match the one of GNU objdump. This patch also updates the relevant llvm-objdump patches and adds a new one testing the output for interleaved auipc+jalr pairs.
2023-10-20[MC][NFC] Allow MCInstrAnalysis to store state (#65479)Job Noorman1-5/+16
Currently, all the analysis functions provided by `MCInstrAnalysis` work on a single instruction. On some targets, this limits the kind of instructions that can be successfully analyzed as common constructs may need multiple instructions. For example, a typical call sequence on RISC-V uses a auipc+jalr pair. In order to analyse the jalr inside `evaluateBranch`, information about the corresponding auipc is needed. Similarly, AArch64 uses adrp+ldr pairs to access globals. This patch proposes to add state to `MCInstrAnalysis` to support these use cases. Two new virtual methods are added: - `updateState`: takes an instruction and its address. This methods should be called by clients on every instruction and allows targets to store whatever information they need to analyse future instructions. - `resetState`: clears the state whenever it becomes irrelevant. Clients could call this, for example, when starting to disassemble a new function. Note that the default implementations do nothing so this patch is NFC. No actual state is stored inside `MCInstrAnalysis`; deciding the structure of the state is left to the targets. This patch also modifies llvm-objdump to use the new interface. This patch is an alternative to [D116677](https://reviews.llvm.org/D116677) and the idea of storing state in `MCInstrAnalysis` was first discussed there.
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-3/+4
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces support::{big,little,native} with llvm::endianness::{big,little,native}.
2023-10-10Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-5/+5
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces llvm::support::{big,little,native} with llvm::endianness::{big,little,native}.
2023-10-10Use llvm::endianness (NFC)Kazu Hirata1-1/+1
Now that llvm::support::endianness has been renamed to llvm::endianness, we can use the shorter form. This patch replaces support::endianness with llvm::endianness.
2023-10-09Use llvm::endianness{,::little,::native} (NFC)Kazu Hirata1-2/+2
Now that llvm::support::endianness has been renamed to llvm::endianness, we can use the shorter form. This patch replaces llvm::support::endianness with llvm::endianness.
2023-09-21[BPF][DebugInfo] Show CO-RE relocations in llvm-objdumpEduard Zingerman1-0/+30
Extend llvm-objdump to show CO-RE relocations when `-r` option is passed and object file has .BTF and .BTF.ext sections. For example, the following C program: #define __pai __attribute__((preserve_access_index)) struct foo { int i; int j;} __pai; struct bar { struct foo f[7]; } __pai; extern void sink(void *); void root(struct bar *bar) { sink(&bar[2].f[3].j); } Should lead to the following objdump output: $ clang --target=bpf -O2 -g t.c -c -o - | \ llvm-objdump --no-addresses --no-show-raw-insn -dr - ... r2 = 0x94 CO-RE <byte_off> [2] struct bar::[2].f[3].j (2:0:3:1) r1 += r2 call -0x1 R_BPF_64_32 sink exit ... More examples could be found in unit tests, see BTFParserTest.cpp. To achieve this: - Move CO-RE relocation kinds definitions from BPFCORE.h to BTF.h. - Extend BTF.h with types derived from BTF::CommonType, e.g. BTF::IntType and BTF::StrutType, to allow dyn_cast() and access to type additional data. - Extend BTFParser to load BTF type and relocation data. - Modify llvm-objdump.cpp to create instance of BTFParser when disassembly of object file with BTF sections is processed and `-r` flag is supplied. Additional information about CO-RE is available at [1]. [1] https://docs.kernel.org/bpf/llvm_reloc.html Depends on D149058 Differential Revision: https://reviews.llvm.org/D150079
2023-09-11[llvm-objdump] --adjust-vma adjust symbol tableShivam Gupta1-0/+3
Add a shouldAdjustVA(Section) guard on top of address update. Update llvm-objdump file to update symbol table when --adjust-vma used. Fixes #63203 Patch by HamidrezaSK (Hamidreza Sanaee)
2023-09-01[llvm-objdump] Enable disassembly color highlightingJonas Devlieghere1-0/+38
Enable color highlighting of disassembly in llvm-objdump. This patch introduces a new flag --disassembler-color=<mode> that enables or disables highlighting disassembly with ANSI escape codes. The default mode is to enable color highlighting if outputting to a color-enabled terminal. Differential revision: https://reviews.llvm.org/D159224
2023-08-17[llvm-{debuginfod,ml,objdump,symbolizer}, dsymutil] Enable multicall driverAndrés Villegas1-1/+2
Differential Revision: https://reviews.llvm.org/D157670
2023-08-17Revert "[llvm-{debuginfod,ml,objdump,symbolizer}, dsymutil] Enable multicall ↵Petr Hosek1-2/+1
driver" This reverts commit 2628fa3351b021d2ab82dcd833a14d7b52840a01 since it broke the multicall driver build.
2023-08-17[llvm-{debuginfod,ml,objdump,symbolizer}, dsymutil] Enable multicall driverAndrés Villegas1-1/+2
Differential Revision: https://reviews.llvm.org/D157670
2023-08-15[llvm-objdump] Support CHPE code ranges in disassembler.Jacek Caban1-2/+61
Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D149095
2023-08-14[llvm-objdump] Add WarningHandler as a member variable. NFCFangrui Song1-2/+9
This can be used to avoid `auto WarningHandler = ...`. Similar to llvm-readobj.
2023-08-13[llvm-objdump,llvm-symbolizer] Remove unused ExitOnErr after D136702. NFCFangrui Song1-1/+0
2023-08-04[llvm] Extract common `OptTable` bits into macrosJan Svoboda1-15/+4
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-08-02Revert "[llvm-objdump] [NFC] Use a single vector to store all symbol mappings."Jacek Caban1-13/+17
Breaks CSKY tests. This reverts commit 948f205ae1a0135eda3eeff0e123d70732d271d5.
2023-08-01[llvm-objdump] [NFC] Use a single vector to store all symbol mappings.Jacek Caban1-17/+13
Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D156622
2023-07-28[llvm-objdump] [NFC] Use DisassemblerTarget for primary target in ↵Jacek Caban1-49/+39
disassembleObject. Further preparation for ARM64EC/ARM64X support. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D149094
2023-07-27[llvm-objdump] -d: don't display mapping symbols as labelsFangrui Song1-37/+64
Similar to D96617 for llvm-symbolizer. This patch matches the GNU objdump -d behavior to suppress printing labels for mapping symbols. Mapping symbol names don't convey much information. When --show-all-symbols (not in GNU) is specified, we still print mapping symbols. Note: the `for (size_t SI = 0, SE = Symbols.size(); SI != SE;)` loops needs to iterate all mapping symbols, even if they are not displayed. We use the new field `IsMappingSymbol` to recognize mapping symbols. This field also enables simplification after D139131. ELF/ARM/disassemble-all-mapping-symbols.s is enhanced to add `.space 2`. If `End = std::min(End, Symbols[SI].Addr);` is not correctly set, we would print a `.word`. Reviewed By: jhenderson, jobnoorman, peter.smith Differential Revision: https://reviews.llvm.org/D156190
2023-07-27[MCDisassembler] Reorder XCOFF specific constructor parameters. NFCFangrui Song1-2/+2
to prevent overload resolution confusion. In particular, if we add another parameter to the generic constructor, MCDisassemblerTest.cpp specified constructors will be resolve to the generic constructor, which is unintended.
2023-07-26[llvm-objdump] Remove bool MachOOnlyFirst from printPrivateHeaders after ↵Fangrui Song1-2/+2
D155045. NFC Mach-O can just use the global variable `FirstPrivateHeader`. If we ever manage to remove global variables, we can add a Config variable to Dumper. Either case, the parameter is not needed. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D156291
2023-07-25[llvm-objdump] [NFC] Factor out DisassemblerTarget class.Jacek Caban1-77/+121
This is a preparation for ARM64EC/ARM64X binaries, which may contain both ARM64 and x86_64 code in the same file. llvm-objdump already has partial support for mixing disassemblers for ARM thumb mode support. However, for ARM64EC we can't share MCContext, MCInstrAnalysis and PrettyPrinter instances. This patch provides additional abstraction which makes adding mixed code support later in the series easier. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D149093
2023-07-24Revert "[llvm-objdump] [NFC] Factor out DisassemblerTarget class."Jacek Caban1-121/+77
This reverts commit 6c48f57c14dcfe2410afcb4c6778dcbb40d294b5. Build broken on GCC.
2023-07-24[llvm-objdump] [NFC] Factor out DisassemblerTarget class.Jacek Caban1-77/+121
This is a preparation for ARM64EC/ARM64X binaries, which may contain both ARM64 and x86_64 code in the same file. llvm-objdump already has partial support for mixing disassemblers for ARM thumb mode support. However, for ARM64EC we can't share MCContext, MCInstrAnalysis and PrettyPrinter instances. This patch provides additional abstraction which makes adding mixed code support later in the series easier. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D149093
2023-07-21[llvm-objdump] Use BBEntry::BBID to represent basic block numbers.Rahman Lavaee1-3/+3
Reviewed By: aidengrossman, mtrofin, JestrTulip Differential Revision: https://reviews.llvm.org/D155464
2023-07-14[llvm-objdump] Move printDynamicRelocations into ELFDump.cpp. NFCFangrui Song1-38/+1
2023-07-14[llvm-objdump] Create ObjectFile specific dumpersFangrui Song1-20/+26
We pay the one-off boilerplate overhead to create `*Dumper` classes that derive from objdump::Dumper a la llvm-readobj. This has two primary advantages. First, a lot object file format specific code can be moved from llvm-objdump.cpp to *Dump.cpp files. Refactor `printPrivateHeaders` as an example. Second, with the introduction of ELFDumper<ELFT>, we can simplify a few dispatch functions in ELFDump.cpp. In addition, the ObjectFile specific dumpers contains a ObjectFile specific reference so that we can remove a lot of `cast<*ObjectFile>(Obj)`. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D155045
2023-07-11[llvm-objdump] Change errors to warnings for symbol section name dumpingFangrui Song1-24/+40
Port D69671 (llvm-readobj) to llvm-objdump. Add a class llvm::objdump::Dumper and move some free functions into Dumper so that they can call reportUniqueWarning. Warnings seems preferable in these cases as the issue is localized and we can continue dumping other information. Differential Revision: https://reviews.llvm.org/D154754
2023-07-06[AMDGPU] Improve assembler + disassembler handling of kernel descriptorsScott Linder1-2/+3
* Relax the AsmParser to accept `.amdhsa_wavefront_size32 0` when the `.amdhsa_shared_vgpr_count` directive is present. * Teach the KD disassembler to respect the setting of KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32 when calculating the value of `.amdhsa_next_free_vgpr`. * Teach the KD disassembler to disassemble COMPUTE_PGM_RSRC3 for gfx90a and gfx10+. * Include "pseudo directive" comments for gfx10 fields which are not controlled by any assembler directive. * Fix disassembleObject failure diagnostic in llvm-objdump to not hard-code a comment string, and to follow the convention of not capitalizing the first sentence. Reviewed By: rochauha Differential Revision: https://reviews.llvm.org/D128014
2023-07-06[AIX][XCOFF] print out the traceback infozhijian1-26/+47
Summary: Adding a new option -traceback-table to print out the traceback info of xcoff ojbect file. Reviewers: James Henderson, Fangrui Song, Stephen Peckham, Xing Xue Differential Revision: https://reviews.llvm.org/D89049
2023-06-06reland: [Demangle] make llvm::demangle take std::string_view rather than ↵Nick Desaulniers1-12/+6
const std::string& As suggested by @erichkeane in https://reviews.llvm.org/D141451#inline-1429549 There's potential for a lot more cleanups around these APIs. This is just a start. Callers need to be more careful about sub-expressions producing strings that don't outlast the expression using `llvm::demangle`. Add a release note. Differential Revision: https://reviews.llvm.org/D149104
2023-05-16[llvm-objdump][X86] Add @plt symbols for .plt.gotFangrui Song1-13/+9
If a symbol needs both JUMP_SLOT and GLOB_DAT relocations, there is a minor linker optimization to keep just GLOB_DAT. This optimization is only implemented by GNU ld's x86 port and mold. https://maskray.me/blog/2021-08-29-all-about-global-offset-table#combining-.got-and-.got.plt With the optimizing, the PLT entry is placed in .plt.got and the associated GOTPLT entry is placed in .got (ld.bfd -z now) or .got.plt (ld.bfd -z lazy). The relocation is in .rel[a].dyn. This patch synthesizes `symbol@plt` labels for these .plt.got entries. Example: ``` cat > a.s <<e .globl _start; _start: mov combined0@gotpcrel(%rip), %rax; mov combined1@gotpcrel(%rip), %rax call combined0@plt; call combined1@plt call foo0@plt; call foo1@plt e cat > b.s <<e .globl foo0, foo1, combined0, combined1 foo0: foo1: combined0: combined1: e gcc -fuse-ld=bfd -shared b.s -o b.so gcc -fuse-ld=bfd -pie -nostdlib a.s b.so -o a ``` ``` Disassembly of section .plt: 0000000000001000 <.plt>: 1000: ff 35 ea 1f 00 00 pushq 0x1fea(%rip) # 0x2ff0 <_GLOBAL_OFFSET_TABLE_+0x8> 1006: ff 25 ec 1f 00 00 jmpq *0x1fec(%rip) # 0x2ff8 <_GLOBAL_OFFSET_TABLE_+0x10> 100c: 0f 1f 40 00 nopl (%rax) 0000000000001010 <foo1@plt>: 1010: ff 25 ea 1f 00 00 jmpq *0x1fea(%rip) # 0x3000 <_GLOBAL_OFFSET_TABLE_+0x18> 1016: 68 00 00 00 00 pushq $0x0 101b: e9 e0 ff ff ff jmp 0x1000 <.plt> 0000000000001020 <foo0@plt>: 1020: ff 25 e2 1f 00 00 jmpq *0x1fe2(%rip) # 0x3008 <_GLOBAL_OFFSET_TABLE_+0x20> 1026: 68 01 00 00 00 pushq $0x1 102b: e9 d0 ff ff ff jmp 0x1000 <.plt> Disassembly of section .plt.got: 0000000000001030 <combined0@plt>: 1030: ff 25 a2 1f 00 00 jmpq *0x1fa2(%rip) # 0x2fd8 <foo1+0x2fd8> 1036: 66 90 nop 0000000000001038 <combined1@plt>: 1038: ff 25 a2 1f 00 00 jmpq *0x1fa2(%rip) # 0x2fe0 <foo1+0x2fe0> 103e: 66 90 nop ``` For x86-32, with -z now, if we remove `foo0` and `foo1`, the absence of regular PLT will cause GNU ld to omit .got.plt, and our code cannot synthesize @plt labels. This is an extreme corner case that almost never happens in practice (to trigger the case, ensure every PLT symbol has been taken address). To fix it, we can get the `_GLOBAL_OFFSET_TABLE_` symbol value, but the complexity is not worth it. Close https://github.com/llvm/llvm-project/issues/62537 Reviewed By: bd1976llvm Differential Revision: https://reviews.llvm.org/D149817
2023-05-03[llvm-objdump] addPltEntries: reduce indentation. NFCFangrui Song1-18/+19
2023-05-02Revert "[Demangle] make llvm::demangle take std::string_view rather than ↵Nick Desaulniers1-6/+12
const std::string&" This reverts commit c117c2c8ba4afd45a006043ec6dd858652b2ffcc. itaniumDemangle calls std::strlen with the results of std::string_view::data() which may not be NUL-terminated. This causes lld/test/wasm/why-extract.s to fail when "expensive checks" are enabled via -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON. See D149675 for further discussion. Back this out until the individual demanglers are converted to use std::string_view.
2023-05-02[Demangle] make llvm::demangle take std::string_view rather than const ↵Nick Desaulniers1-12/+6
std::string& As suggested by @erichkeane in https://reviews.llvm.org/D141451#inline-1429549 There's potential for a lot more cleanups around these APIs. This is just a start. Callers need to be more careful about sub-expressions producing strings that don't outlast the expression using ``llvm::demangle``. Add a release note. Reviewed By: MaskRay, #lld-macho Differential Revision: https://reviews.llvm.org/D149104
2023-04-05[Object] Refactor build ID parsing into Object lib.Daniel Thornburgh1-8/+6
This makes parsing for build IDs in the markup filter slightly more permissive, in line with fromHex. It also removes the distinction between missing build ID and empty build ID; empty build IDs aren't a useful concept, since their purpose is to uniquely identify a binary. This removes a layer of indirection wherever build IDs are obtained. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D147485
2023-03-13[Propeller] Make decoding BBAddrMaps trace through relocationsAiden Grossman1-1/+3
Currently when using the LLVM tools (eg llvm-readobj, llvm-objdump) to find information about basic block locations using the propeller tooling in relocatable object files function addresses are not mapped properly which causes problems. In llvm-readobj this means that incorrect function names will be pulled. In llvm-objdum this means that most BBs won't show up in the output if --symbolize-operands is used. This patch changes the behavior of decodeBBAddrMap to trace through relocations to get correct function addresses if it is going through a relocatable object file. This fixes the behavior in both tools and also other consumers of decodeBBAddrMap. Some helper functions have been added in/refactoring done to aid in grabbing BB address map sections now that in some cases both relocation and BB address map sections need to be obtained at the same time. Regression tests moved around/added. Differential Revision: https://reviews.llvm.org/D143841
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-26Reland: [llvm-cov] Look up object files using debuginfodDaniel Thornburgh1-3/+1
Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D136702
2023-01-25Revert "[llvm-cov] Look up object files using debuginfod"Douglas Yung1-1/+3
This reverts commit efbc8bb18eda63007216ad0cb5a8de04963eddd5. This change is causing failures when detecting curl on several build bots: - https://lab.llvm.org/buildbot/#/builders/247/builds/884 - https://lab.llvm.org/buildbot/#/builders/231/builds/7688 - https://lab.llvm.org/buildbot/#/builders/121/builds/27389 - https://lab.llvm.org/buildbot/#/builders/230/builds/8464 - https://lab.llvm.org/buildbot/#/builders/57/builds/24209 - https://lab.llvm.org/buildbot/#/builders/127/builds/42722
2023-01-25[llvm-cov] Look up object files using debuginfodDaniel Thornburgh1-3/+1
Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D136702
2023-01-18[llvm-objdump] Fix reporting error for processing target featuresElena Lepilkina1-1/+1
Differential Revision: https://reviews.llvm.org/D142003