aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-01-26[llvm-objdump] Use append_range (NFC)Kazu Hirata1-2/+1
2021-01-07[llvm-objdump] Pass Twine by const reference instead of by value. NFCI.Simon Pilgrim1-4/+5
2020-12-17Make LLVM build in C++20 modeBarry Revzin1-7/+7
Part of the <=> changes in C++20 make certain patterns of writing equality operators ambiguous with themselves (sorry!). This patch goes through and adjusts all the comparison operators such that they should work in both C++17 and C++20 modes. It also makes two other small C++20-specific changes (adding a constructor to a type that cases to be an aggregate, and adding casts from u8 literals which no longer have type const char*). There were four categories of errors that this review fixes. Here are canonical examples of them, ordered from most to least common: // 1) Missing const namespace missing_const { struct A { #ifndef FIXED bool operator==(A const&); #else bool operator==(A const&) const; #endif }; bool a = A{} == A{}; // error } // 2) Type mismatch on CRTP namespace crtp_mismatch { template <typename Derived> struct Base { #ifndef FIXED bool operator==(Derived const&) const; #else // in one case changed to taking Base const& friend bool operator==(Derived const&, Derived const&); #endif }; struct D : Base<D> { }; bool b = D{} == D{}; // error } // 3) iterator/const_iterator with only mixed comparison namespace iter_const_iter { template <bool Const> struct iterator { using const_iterator = iterator<true>; iterator(); template <bool B, std::enable_if_t<(Const && !B), int> = 0> iterator(iterator<B> const&); #ifndef FIXED bool operator==(const_iterator const&) const; #else friend bool operator==(iterator const&, iterator const&); #endif }; bool c = iterator<false>{} == iterator<false>{} // error || iterator<false>{} == iterator<true>{} || iterator<true>{} == iterator<false>{} || iterator<true>{} == iterator<true>{}; } // 4) Same-type comparison but only have mixed-type operator namespace ambiguous_choice { enum Color { Red }; struct C { C(); C(Color); operator Color() const; bool operator==(Color) const; friend bool operator==(C, C); }; bool c = C{} == C{}; // error bool d = C{} == Red; } Differential revision: https://reviews.llvm.org/D78938
2020-12-16[lib/Object] - Make ELFObjectFile::getSymbol() return Expected<>.Georgii Rymar1-5/+15
This was requested in comments for D93209: https://reviews.llvm.org/D93209#inline-871192 D93209 fixes an issue with `ELFFile<ELFT>::getEntry`, after what `getSymbol` starts calling `report_fatal_error` for previously missed invalid cases. This patch makes it return `Expected<>` and updates callers. For few of them I had to add new `report_fatal_error` calls. But I see no way to avoid it currently. The change would affects too many places, e.g: `getSymbolBinding` and other methods are used from `ELFSymbolRef` which is used in too many places across LLVM. Differential revision: https://reviews.llvm.org/D93297
2020-12-14[llvm-objdump] Use "--" for long options in --help textDavid Spickett1-8/+8
Single dash for these options is not recognised. Changes found by running this on the --help output and the user guide: grep -e ' -[a-zA-Z]\{2,\}' The user guide was updated in https://reviews.llvm.org/D92305 so no change there. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D92310
2020-11-30[llvm-objdump] Document --mattr=help in --help outputDavid Spickett1-5/+5
This does the same as `--mcpu=help` but was only documented in the user guide. * Added a test for both options. * Corrected the single dash in `-mcpu=help` text. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D92305
2020-10-16[llvm-objdump] Implement --prefix optionVinicius Tinti1-0/+15
The prefix given to --prefix will be added to GNU absolute paths when used with --source option (source interleaved with the disassembly). This matches GNU's objdump behavior. GNU and C++17 rules for absolute paths are different. Differential Revision: https://reviews.llvm.org/D85024 Fixes PR46368. Differential Revision: https://reviews.llvm.org/D85024
2020-10-08[llvm-objdump] Ensure we consistently use the llvm::stable_sort wrappers.Simon Pilgrim1-2/+2
We use this everywhere else in this file, these were just missed.
2020-10-07[AMDGPU] Support disassembly for AMDGPU kernel descriptorsRonak Chauhan1-17/+0
Decode AMDGPU Kernel descriptors as assembler directives. Reviewed By: scott.linder, jhenderson, kzhuravl Differential Revision: https://reviews.llvm.org/D80713
2020-09-09Revert "[AMDGPU] Support disassembly for AMDGPU kernel descriptors"Ronak Chauhan1-0/+17
This reverts commit 487a80531006add8102d50dbcce4b6fd729ab1f6. Tests fail on big endian machines.
2020-09-08[AMDGPU] Support disassembly for AMDGPU kernel descriptorsRonak Chauhan1-17/+0
Decode AMDGPU Kernel descriptors as assembler directives. Reviewed By: scott.linder, jhenderson, kzhuravl Differential Revision: https://reviews.llvm.org/D80713
2020-09-04[objdump][macho] Emit segment names along with section namesDaniel Sanders1-11/+20
I recently came across a MachO with multiple sections of the same name but different segments. We should emit the segment name alongside the section name for MachO's. Differential Revision: https://reviews.llvm.org/D87119
2020-08-19Revert "[AMDGPU] Support disassembly for AMDGPU kernel descriptors"Ronak Chauhan1-0/+17
This reverts commit cacfb02d28a3cabd4e45d2535cb0686cef48a2c9. Reverting due to buildbot failures.
2020-08-19[AMDGPU] Support disassembly for AMDGPU kernel descriptorsRonak Chauhan1-17/+0
Decode AMDGPU Kernel descriptors as assembler directives. Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D80713
2020-08-18[llvm-objdump][AMDGPU] Detect CPU stringRonak Chauhan1-0/+4
AMDGPU ISA isn't backwards compatible and hence -mcpu must always be specified during disassembly. However, the AMDGPU target CPU is stored in e_flags in the ELF object. This patch allows targets to implement CPU string detection, and also implements it for AMDGPU by looking at e_flags. Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D84519
2020-08-17[llvm-objdump] Symbolize binary addresses for low-noisy asm diff.Hongtao Yu1-6/+75
When diffing disassembly dump of two binaries, I see lots of noises from mismatched jump target addresses and global data references, which unnecessarily causes diffs on every function, making it impractical. I'm trying to symbolize the raw binary addresses to minimize the diff noise. In this change, a local branch target is modeled as a label and the branch target operand will simply be printed as a label. Local labels are collected by a separate pre-decoding pass beforehand. A global data memory operand will be printed as a global symbol instead of the raw data address. Unfortunately, due to the way the disassembler is set up and to be less intrusive, a global symbol is always printed as the last operand of a memory access instruction. This is less than ideal but is probably acceptable from checking code quality point of view since on most targets an instruction can have at most one memory operand. So far only the X86 disassemblers are supported. Test Plan: llvm-objdump -d --x86-asm-syntax=intel --no-show-raw-insn --no-leading-addr : ``` Disassembly of section .text: <_start>: push rax mov dword ptr [rsp + 4], 0 mov dword ptr [rsp], 0 mov eax, dword ptr [rsp] cmp eax, dword ptr [rip + 4112] # 202182 <g> jge 0x20117e <_start+0x25> call 0x201158 <foo> inc dword ptr [rsp] jmp 0x201169 <_start+0x10> xor eax, eax pop rcx ret ``` llvm-objdump -d **--symbolize-operands** --x86-asm-syntax=intel --no-show-raw-insn --no-leading-addr : ``` Disassembly of section .text: <_start>: push rax mov dword ptr [rsp + 4], 0 mov dword ptr [rsp], 0 <L1>: mov eax, dword ptr [rsp] cmp eax, dword ptr <g> jge <L0> call <foo> inc dword ptr [rsp] jmp <L1> <L0>: xor eax, eax pop rcx ret ``` Note that the jump instructions like `jge 0x20117e <_start+0x25>` without this work is printed as a real target address and an offset from the leading symbol. With a change in the optimizer that adds/deletes an instruction, the address and offset may shift for targets placed after the instruction. This will be a problem when diffing the disassembly from two optimizers where there are unnecessary false positives due to such branch target address changes. With `--symbolize-operand`, a label is printed for a branch target instead to reduce the false positives. Similarly, the disassemble of PC-relative global variable references is also prone to instruction insertion/deletion. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D84191
2020-08-13[llvm-objdump] Change symbol name/PLT decoding errors to warningsFangrui Song1-9/+23
If the referenced symbol of a J[U]MP_SLOT is invalid (e.g. symbol index 0), llvm-objdump -d will bail out: ``` error: 'a': st_name (0x326600) is past the end of the string table of size 0x7 ``` where 0x326600 is the st_name field of the first entry past the end of .symtab Change it to a warning to continue dumping. `X86/plt.test` uses a prebuilt executable, so I pick `ELF/AArch64/plt.test` which has a YAML input and can be easily modified. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D85623
2020-07-09Fix MSVC "not all control paths return a value" warning. NFC.Simon Pilgrim1-0/+1
2020-07-09[llvm-objdump] Display locations of variables alongside disassemblyOliver Stannard1-66/+470
This adds the --debug-vars option to llvm-objdump, which prints locations (registers/memory) of source-level variables alongside the disassembly based on DWARF info. A vertical line is printed for each live-range, with a label at the top giving the variable name and location, and the position and length of the line indicating the program counter range in which it is valid. Differential revision: https://reviews.llvm.org/D70720
2020-06-19[MC] Pass the symbol rather than its name to onSymbolStart()Ronak Chauhan1-1/+1
Summary: This allows targets to also consider the symbol's type and/or address if needed. Reviewers: scott.linder, jhenderson, MaskRay, aardappel Reviewed By: scott.linder, MaskRay Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, aheejin, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82090
2020-06-12[MC] Changes to help improve target specific symbol disassemblyRonak Chauhan1-4/+31
Summary: This commit slightly modifies the MCDisassembler, and llvm-objdump to allow targets to also decode entire symbols. WebAssembly uses the onSymbolStart hook it to decode preludes. WebAssembly partially disassembles the symbol in its target specific way; and then falls back to the normal flow of llvm-objdump. AMDGPU needs it to decode kernel descriptors entirely, and move to the next symbol. This commit is to split the above task into 2. - Changes to llvm-objdump and MC-layer without breaking WebAssembly code [ this commit ] - AMDGPU's implementation of onSymbolStart that decodes kernel descriptors. [ https://reviews.llvm.org/D80713 ] Reviewers: scott.linder, t-tye, sunfish, arsenm, jhenderson, MaskRay, aardappel Reviewed By: scott.linder, jhenderson, aardappel Subscribers: bcain, dschuff, wdng, tpr, sbc100, jgravelle-google, hiraditya, aheejin, MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80512
2020-06-11Re-land "Migrate the rest of COFFObjectFile to Error"Reid Kleckner1-4/+4
This reverts commit 101fbc01382edd89ea7b671104c68b30b2446cc0. Remove leftover debugging attribute. Update LLDB as well, which was missed before.
2020-06-11[llvm-objdump] Decrease instruction indentation for non-x86Fangrui Song1-3/+5
Place the instruction at the 24th column (0-based indexing), matching GNU objdump ARM/AArch64/powerpc/etc when the address is low. This is beneficial for non-x86 targets which have short instruction lengths. ``` // GNU objdump AArch64 0: 91001062 add x2, x3, #0x4 400078: 91001062 add x2, x3, #0x4 // llvm-objdump, with this patch 0: 62 10 00 91 add x2, x3, #4 400078: 62 10 00 91 add x2, x3, #4 // llvm-objdump, if we change to print a word instead of bytes in the future 0: 91001062 add x2, x3, #4 400078: 91001062 add x2, x3, #4 // GNU objdump Thumb 0: bf00 nop // GNU objdump Power ISA 3.1 64-bit instruction // 0: 00 00 10 04 plwa r3,0 // 4: 00 00 60 a4 ``` Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D81590
2020-06-05Revert "Migrate the rest of COFFObjectFile to Error"Nico Weber1-4/+4
This reverts commit b5289656b865d2a73cf90819e20a96fb8414ab0b. __attribute__((optnone)) doesn't build with msvc, see http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/16326
2020-06-05Migrate the rest of COFFObjectFile to ErrorReid Kleckner1-4/+4
2020-05-30[llvm-objdump] Delete unneeeded namespace llvm {}Fangrui Song1-3/+0
2020-05-30[llvm-objdump] Move llvm:: to llvm::objdump:: and qualifying definitions ↵Fangrui Song1-22/+26
with objdump:: Or adding `static`. Qualifying definitions with `objdump::` comforms to the coding standards https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
2020-05-30[llvm-objdump] Simplify reportError() and prepend outs().flush()Fangrui Song1-6/+4
As noticed by dblaikie. I don't know what code paths using reportError can cause stdout output to be interleaved with stderr, so no test is added now. Also drop an unneeded use of errs().fflush() in reportWarning(). I requested this in D64165.
2020-05-04[llvm-objdump][ARM] Print inline relocations when dumping ARM dataFangrui Song1-143/+141
Fixes PR44357 For ARM ELF, regions covered by data mapping symbols `$d` are dumped as `.byte`, `.short` or `.word` but inline relocations are not printed. This patch merges its loop into the normal instruction printing loop so that inline relocations are printed. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D79284
2020-04-27[llvm-objdump] Print target address with evaluateMemoryOperandAddress()Fangrui Song1-6/+15
D63847 added `MCInstrAnalysis::evaluateMemoryOperandAddress()`. This patch leverages the feature to print the target addresses for evaluable instructions. ``` -400a: movl 4080(%rip), %eax +400a: movl 4080(%rip), %eax # 5000 <data1> ``` This patch also deletes `MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || MIA->isConditionalBranch(Inst)` which is used to guard `MCInstrAnalysis::evaluateBranch()` Reviewed By: jhenderson, skan Differential Revision: https://reviews.llvm.org/D78776
2020-04-23[llvm-objdump][ELF][NFC] Create ELFDump.hHubert Tong1-0/+1
Summary: Continuing from D77285, the external interfaces implemented by `ELFDump.cpp` are now declared in `ELFDump.h` and moved into the `llvm::objdump` namespace. Externs defined in `ELFDump.cpp` that are unreferenced externally are also made static. Reviewers: jhenderson, MaskRay, DiggerLin, jasonliu, daltenty Reviewed By: jhenderson, MaskRay Subscribers: RKSimon, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78695
2020-04-22[llvm-objdump][XCOFF] Print more symbol info in relocationjasonliu1-7/+6
Summary: Print more symbol info in relocation printing when --symbol-description is specified. Differential Revision: https://reviews.llvm.org/D78499
2020-04-22[llvm-objdump] Look in all viable sections for call/branch targetsJames Henderson1-27/+39
Prior to this patch, llvm-objdump would only look in the last section (according to the section header table order) that matched an address for a symbol when identifying the target symbol of a call or branch operation. If there are multiple sections with the same address, due to some of them being empty, it did not look in those, even if the symbol couldn't be found in the first section looked in. This patch causes llvm-objdump to look in all sections for possible candidate symbols. If there are multiple possible symbols, it picks one from a non-empty section, if possible (as that is more likely to be the "real" symbol since functions can't really be in emptiy sections), before falling back to those in empty sections. If all else fails, it falls back to absolute symbols as it did before. Differential Revision: https://reviews.llvm.org/D78549 Reviewed by: grimar, Higuoxing
2020-04-18[llvm-objdump] Demangle C++ Symbols in branch and call targetsMarkus Böck1-1/+4
Currently C++ symbols are demangled in the symbol table as well as in the disassembly and relocations. This patch adds demangling of C++ symbols in targets of calls and branches making it easier to decipher control flow in disassembly. This also matches up with GNUobjdump's behavior Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D77957
2020-04-18[Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> ↵vgxbj1-1/+2
getSymbolFlags(). This change enables getSymbolFlags() to return errors which benefit error reporting in clients. Differential Revision: https://reviews.llvm.org/D77860
2020-04-14[llvm-objdump][Wasm][NFC] Create WasmDump.hHubert Tong1-0/+1
Summary: Continuing from D77285, the external interfaces implemented by `WasmDump.cpp` are now declared in `WasmDump.h` and moved into the `llvm::objdump` namespace. Reviewers: jhenderson, MaskRay, DiggerLin, jasonliu, daltenty Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D77990
2020-04-13[llvm-objdump] Fix incomplete relocation output for -D -r modejasonliu1-14/+12
This patch intends to fix incomplete relocation printing for XCOFF (potentially for other targets). Differential Revision: https://reviews.llvm.org/D77580
2020-04-09[llvm-objdump][NFC] MachODump.cpp interface cleanupHubert Tong1-3/+3
Continuing from D77388, this patch moves interface declarations associated with `MachODump.cpp` into the headers corresponding to the file that defines the variable. At the same time, these externs are moved into the `llvm::objdump` namespace. The externs defined in `MachODump.cpp` that are not referenced outside of it are given internal linkage. This patch does not rename the external functions defined by `MachODump.cpp` that are not clearly named as being specific to Mach-O. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D77730
2020-04-08[llvm-objdump] Fix unstable disassembly output for sections with same addressJames Henderson1-1/+1
When two sections shared the same address, the disassembly code was using pointer values when sorting (see the SectionRef less than operator). Since those values aren't guaranteed to have a specific order, this meant the disassembly code would sometimes change which section to pick when finding symbols targeted by calls in fully linked objects. This change fixes the non-determinism, so that the same section is always picked. This might have a negative impact in that now a section without any symbol might be picked over a section with symbols, but this will be addressed in a later commit. Fixes https://bugs.llvm.org/show_bug.cgi?id=45411. Reviewed by: grimar, MaskRay Differential Revision: https://reviews.llvm.org/D77640
2020-04-06[llvm-objdump][NFC] Declare command-line externs in headers with namespaceHubert Tong1-73/+65
Summary: This patch moves the forward declarations of command-line `cl::*` externs in `MachODump.cpp` and `llvm-objdump.cpp` into the headers corresponding to the file that defines the variable. At the same time, these externs are moved into the `llvm::objdump` namespace. The externs that are not referenced outside their defining translation unit are made static. This does not factor out uses of the Mach-O options from `llvm-objdump.cpp`. Reviewers: jhenderson, MaskRay, DiggerLin, jasonliu, daltenty Reviewed By: jhenderson, MaskRay Subscribers: rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77388
2020-04-06[llvm-objdump][XCOFF] Use symbol index+symbol name + storage mapping class ↵diggerlin1-19/+51
as label for -D SUMMARY: For the llvm-objdump -D, the symbol name is used as a label in the disassembly for the specific address (when a symbol address is equal to the virtual address in the dump). In XCOFF, multiple symbols may have the same name, being differentiated by their storage mapping class. It is helpful to print the QualName and not just the name when forming the output label for a csect symbol. The symbol index further removes any ambiguity caused by duplicate names. To maintain compatibility with the binutils objdump, the XCOFF-specific --symbol-description option is added to enable the enhanced format. Reviewers: hubert.reinterpretcast, James Henderson, Jason Liu ,daltenty Subscribers: wuzish, nemanjai, hiraditya Differential Revision: https://reviews.llvm.org/D72973
2020-04-05[llvm-objdump] Simplify conditional statements (isa<...>(Obj) => ↵vgxbj1-8/+8
Obj->isSomeFile()) Summary: Simplify some conditional statements. Reviewers: jhenderson, MaskRay, rupprecht Reviewed By: MaskRay, rupprecht Subscribers: rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75899
2020-04-05[llvm-objdump] Teach `llvm-objdump` dump dynamic symbols.vgxbj1-124/+160
Summary: This patch is to teach `llvm-objdump` dump dynamic symbols (`-T` and `--dynamic-syms`). Currently, this patch is not fully compatible with `gnu-objdump`, but I would like to continue working on this in next few patches. It has two issues. 1. Some symbols shouldn't be marked as global(g). (`-t/--syms` has same issue as well) (Fixed by D75659) 2. `gnu-objdump` can dump version information and *dynamically* insert before symbol name field. `objdump -T a.out` gives: ``` DYNAMIC SYMBOL TABLE: 0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 printf 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __libc_start_main 0000000000000000 w D *UND* 0000000000000000 __gmon_start__ 0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable 0000000000000000 w DF *UND* 0000000000000000 GLIBC_2.2.5 __cxa_finalize ``` `llvm-objdump -T a.out` gives: ``` DYNAMIC SYMBOL TABLE: 0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable 0000000000000000 g DF *UND* 0000000000000000 printf 0000000000000000 g DF *UND* 0000000000000000 __libc_start_main 0000000000000000 w D *UND* 0000000000000000 __gmon_start__ 0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable 0000000000000000 w DF *UND* 0000000000000000 __cxa_finalize ``` Reviewers: jhenderson, grimar, MaskRay, espindola Reviewed By: jhenderson, grimar Subscribers: emaste, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75756
2020-04-02[llvm-objdump][COFF][NFC] Split format-specific interfaces; add namespaceHubert Tong1-0/+2
Summary: This patch addresses, for the interfaces implemented by `COFFDump.cpp`, multiple issues identified with the current structure of `llvm-objdump.h` in the review of D72973. This patch moves implementation details of the tool into an `llvm::objdump` namespace for external linkage names, splits the implementation details into separate headers for each implementation file, and uses qualified names when declaring members of the `llvm::objdump` namespace in place of leaving the namespace definition open. Reviewers: jhenderson, DiggerLin, jasonliu, daltenty, MaskRay Reviewed By: jhenderson, MaskRay Subscribers: MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77285
2020-03-27[llvm-objdump][XCOFF][AIX] Implement -r optionjasonliu1-0/+3
Summary: Implement several XCOFF hooks to get '-r' option working for llvm-objdump -r. Reviewer: DiggerLin, hubert.reinterpretcast, jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D75131
2020-03-26[llvm-objdump] Fix typo. NFCFangrui Song1-3/+3
2020-03-26[X86InstPrinter] Change printPCRelImm to print the target address in ↵Fangrui Song1-3/+9
hexadecimal form ``` // llvm-objdump -d output (before) 400000: e8 0b 00 00 00 callq 11 400005: e8 0b 00 00 00 callq 11 // llvm-objdump -d output (after) 400000: e8 0b 00 00 00 callq 0x400010 400005: e8 0b 00 00 00 callq 0x400015 // GNU objdump -d. The lack of 0x is not ideal because the result cannot be re-assembled 400000: e8 0b 00 00 00 callq 400010 400005: e8 0b 00 00 00 callq 400015 ``` In llvm-objdump, we pass the address of the next MCInst. Ideally we should just thread the address of the current address, unfortunately we cannot call X86MCCodeEmitter::encodeInstruction (X86MCCodeEmitter requires MCInstrInfo and MCContext) to get the length of the MCInst. MCInstPrinter::printInst has other callers (e.g llvm-mc -filetype=asm, llvm-mca) which set Address to 0. They leave MCInstPrinter::PrintBranchImmAsAddress as false and this change is a no-op for them. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D76580
2020-03-26[MCInstPrinter] Pass `Address` parameter to MCOI::OPERAND_PCREL typed ↵Fangrui Song1-0/+1
operands. NFC Follow-up of D72172 and D72180 This patch passes `uint64_t Address` to print methods of PC-relative operands so that subsequent target specific patches can change `*InstPrinter::print{Operand,PCRelImm,...}` to customize the output. Add MCInstPrinter::PrintBranchImmAsAddress which is set to true by llvm-objdump. ``` // Current llvm-objdump -d output aarch64: 20000: bl #0 ppc: 20000: bl .+4 x86: 20000: callq 0 // Ideal output aarch64: 20000: bl 0x20000 ppc: 20000: bl 0x20004 x86: 20000: callq 0x20005 // GNU objdump -d. The lack of 0x is not ideal because the result cannot be re-assembled aarch64: 20000: bl 20000 ppc: 20000: bl 0x20004 x86: 20000: callq 20005 ``` In `lib/Target/X86/X86GenAsmWriter1.inc` (generated by `llvm-tblgen -gen-asm-writer`): ``` case 12: // CALL64pcrel32, CALLpcrel16, CALLpcrel32, EH_SjLj_Setup, JCXZ, JECXZ, J... - printPCRelImm(MI, 0, O); + printPCRelImm(MI, Address, 0, O); return; ``` Some targets have 2 `printOperand` overloads, one without `Address` and one with `Address`. They should annotate derived `Operand` properly with `let OperandType = "OPERAND_PCREL"`. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D76574
2020-03-25[llvm-objdump] Replace array_pod_sort with llvm::stable_sortFangrui Song1-5/+8
llvm-objdump.cpp has 3 array_pod_sort() calls used for symbolization. array_pod_start() calls qsort() internally and can have different behaviors across different libcs. Use llvm::stable_sort instead. Reviewed By: davidb, thopre Differential Revision: https://reviews.llvm.org/D76739
2020-03-16Revert "[llvm-objdump] Display locations of variables alongside disassembly"Nico Weber1-472/+66
Makes tests fail on Windows, see https://reviews.llvm.org/D70720#1924542 This reverts commit 3a5ddedadb671e485ce5c638142817879ac14a8c, and follow-ups: f4cb9c919e28276222873453cf85de9e5a3c7be5 042eb0482aa758057c4f77616a4696cdb21b4fcc c0cf5f5da9a7bf1bdf43ed53287b0f634fc53045 18649f48139932377c2a2909f1fb600bf5cf6e57 f62b898c1f5dd77e68b53570dc2679877bcbe4c2