aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/COFFDump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-02[llvm-objdump] Remove an unnecessary cast (NFC) (#151799)Kazu Hirata1-1/+1
Size is already of uint32_t.
2025-01-13[llvm] Win x64 Unwind V2 2/n: Support dumping UOP_Epilog (#110338)Daniel Paoliello1-3/+21
Adds support to objdump and readobj for reading the `UOP_Epilog` entries of Windows x64 unwind v2. `UOP_Epilog` has a weird format: The first `UOP_Epilog` in the unwind data is the "header": * The least-significant bit of `OpInfo` is the "At End" flag, which signifies that there is an epilog at the very end of the associated function. * `CodeOffset` is the length each epilog described by the current unwind information (all epilogs have the same length). Any subsequent `UOP_Epilog` represents another epilog for the current function, where `OpInfo` and `CodeOffset` are combined to a 12-bit value which is the offset of the beginning of the epilog from the end of the current function. If the offset is 0, then this entry is actually padding and can be ignored.
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-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-14[llvm-objdump] Create ObjectFile specific dumpersFangrui Song1-3/+10
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-06-05[Demangle] convert microsoftDemangle to take a std::string_viewNick Desaulniers1-1/+1
This should be last of the "bottom-up conversions" of various demanglers to accept std::string_view. After this, D149104 may be revisited. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D152176
2023-05-04[llvm-objdump][COFF] Skip empty export entries when dumping the export tableAlexandre Ganea1-6/+9
Before this patch, export entries with empy RVA were displayed in the output. In some cases, when the module had exports with sparse ordinals, `llvm-objdump` used to print a lot of `0 0` lines. We now skip over these empty entries in the output, just as `dumpbin` or binutils `objdump` does. Differential Revision: https://reviews.llvm.org/D149610
2023-05-03[llvm-objdump][COFF] Keep columns aligned in the console output when exports ↵Alexandre Ganea1-2/+2
ordinals are large.
2023-04-21[Demangle] remove unused params of microsoftDemangleNick Desaulniers1-2/+1
No call sites use these parameters, so drop them. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148940
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-4/+4
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-09-08[llvm] Use std::size instead of llvm::array_lengthofJoe Loser1-1/+1
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133429
2022-09-01[llvm-objdump][COFF] Correctly decode `UOP_Epilog` opcodesArpad Borsos1-1/+5
At least `ntdll` is using the undocumented version 2 unwind info, and opcode 6, which is already defined as `UOP_Epilog`. Using `llvm-objdump --unwind` with `ntdll` would previously result in unreachable assertions because this code was missing from `getNumUsedSlots` and `getUnwindCodeTypeName`. The slots of these codes comes from https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/coreclr/inc/win64unwind.h#L51-L52 which I would assume is a good authoritative source. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D107655
2022-07-07[llvm-objdump] Change some nonnull pointers to references. NFCFangrui Song1-16/+16
2022-06-03[COFF] Check table ptr more thoroughly and ignore empty sectionsAlvin Wong1-25/+7
When loading split debug files for PE/COFF executables (produced with `objcopy --only-keep-debug`), the tables or directories in such files may point to data inside sections that may have been stripped. COFFObjectFile shall detect and gracefully handle this, to allow the object file be loaded without considering these tables or directories. This is required for LLDB to load these files for use as debug symbols. COFFObjectFile shall also check these pointers more carefully to account for cases in which the section contains less raw data than the size given by VirtualSize, to prevent going out of bounds. This commit also changes COFFDump in llvm-objdump to reuse the pointers that are already range-checked in COFFObjectFile. This fixes a crash when trying to dump the TLS directory from a stripped file. Fixes https://github.com/mstorsjo/llvm-mingw/issues/284 Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D126898
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-1/+1
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-1/+1
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2021-11-10[llvm-objdump] Remove a trailing semicolon, fixing GCC warnings. NFC.Martin Storsjö1-1/+1
2021-11-09[llvm-objdump] -p: Dump PE header for PE/COFFFangrui Song1-6/+194
For a trivial DLL built with `clang --target=x86_64-windows -O2 -c a.c; lld-link -subsystem:console -dll a.o -out:a.dll`, `objdump -p` vs `llvm-objdump -p`: ``` -a.dll: file format pei-x86-64 - +a.dll: file format coff-x86-64 Characteristics 0x2022 executable large address aware @@ -57,4 +56,4 @@ Entry d 0000000000000000 00000000 Delay Import Directory Entry e 0000000000000000 00000000 CLR Runtime Header Entry f 0000000000000000 00000000 Reserved - +Export Table: ``` For a Linux image (`vmlinuz-5.10.76-gentoo-r1`) built with `CONFIG_EFI_STUB=y` ``` -vmlinuz-5.10.76-gentoo-r1: file format pei-x86-64 - -Characteristics 0x20e +vmlinuz-5.10.76-gentoo-r1: file format coff-x86-64 +Characteristics 0x206 executable line numbers stripped - symbols stripped debugging information removed Time/Date Wed Dec 31 16:00:00 1969 @@ -55,10 +53,4 @@ Entry d 0000000000000000 00000000 Delay Import Directory Entry e 0000000000000000 00000000 CLR Runtime Header Entry f 0000000000000000 00000000 Reserved - - -PE File Base Relocations (interpreted .reloc section contents) - -Virtual Address: 000037ca Chunk size 10 (0xa) Number of fixups 1 - reloc 0 offset 0 [37ca] ABSOLUTE - +Export Table: ``` `symbols stripped` looks like a GNU objdump problem. Reviewed By: jhenderson, alexander-shaposhnikov Differential Revision: https://reviews.llvm.org/D113356
2021-11-06[llvm-objdump] Remove untested diagnostic "missing data dir for TLS table"Fangrui Song1-4/+1
2021-01-26[llvm-objdump] Use append_range (NFC)Kazu Hirata1-2/+1
2020-06-11Re-land "Migrate the rest of COFFObjectFile to Error"Reid Kleckner1-21/+18
This reverts commit 101fbc01382edd89ea7b671104c68b30b2446cc0. Remove leftover debugging attribute. Update LLDB as well, which was missed before.
2020-06-05Revert "Migrate the rest of COFFObjectFile to Error"Nico Weber1-18/+21
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-21/+18
2020-05-30[llvm-objdump] Move llvm:: to llvm::objdump:: and qualifying definitions ↵Fangrui Song1-0/+1
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-20Give microsoftDemangle() an outparam for how many input bytes were consumed.Nico Weber1-4/+2
Demangling Itanium symbols either consumes the whole input or fails, but Microsoft symbols can be successfully demangled with just some of the input. Add an outparam that enables clients to know how much of the input was consumed, and use this flag to give llvm-undname an opt-in warning on partially consumed symbols. Differential Revision: https://reviews.llvm.org/D80173
2020-05-08[COFF] Migrate COFFObjectFile to Expected<T>Reid Kleckner1-3/+4
I noticed that std::error_code() does one-time initialization. Avoid that overhead with Expected<T> and llvm::Error. Also, it is consistent with the virtual interface and ELF, and generally cleaner. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D79643
2020-04-02[llvm-objdump][COFF][NFC] Split format-specific interfaces; add namespaceHubert Tong1-9/+10
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
2019-08-21[llvm-objdump] - Cleanup the error reporting.George Rimar1-18/+43
The error reporting function are not consistent. Before this change: * They had inconsistent naming (e.g. 'error' vs 'report_error'). * Some of them reported the object name, others - dont. * Some of them accepted the case when there was no error. (i.e. error code or Error had a success value). This patch tries to cleanup it a bit. It also renames report_error -> reportError, report_warning -> reportWarning and removes a full stop from messages. Differential revision: https://reviews.llvm.org/D66418 llvm-svn: 369515
2019-08-19[llvm-objdump] - Restore lost comment.George Rimar1-0/+1
It was removed by mistake in r369263 (D66417). llvm-svn: 369265
2019-08-19[Object/COFF.h] - Stop returning std::error_code in a few methods. NFCI.George Rimar1-12/+4
There are 4 methods that return std::error_code now, though they do not have to because they are always succeed. I refactored them. This allows to simplify the code in tools a bit. llvm-svn: 369263
2019-08-14Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-2/+1
Expected<>" Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368826
2019-08-14Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-1/+2
Expected<>" It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 llvm-svn: 368813
2019-08-14[llvm/Object] - Convert SectionRef::getName() to return Expected<>George Rimar1-2/+1
SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368812
2019-05-14[Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song1-3/+1
Expected<ArrayRef<uint8_t>> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected<ArrayRef<uint8_t>> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef<uint8_t> as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648
2019-05-10[Object] Change SymbolicFile::printSymbolName to use ErrorFangrui Song1-1/+1
llvm-svn: 360414
2019-04-15[llvm-objdump] Wrap things in namespace llvmFangrui Song1-8/+9
llvm-svn: 358417
2019-04-09[llvm-objdump] Migrate some functions from std::error_code to ErrorFangrui Song1-23/+23
llvm-svn: 357965
2019-04-08[llvm-objdump] Migrate relocation handling functions from error_code to ErrorFangrui Song1-6/+5
llvm-svn: 357920
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-18[llvm-objdump] - Move getRelocationValueString and dependenices out of the ↵George Rimar1-0/+13
llvm-objdump.cpp getRelocationValueString is a dispatcher function that calls the corresponding ELF/COFF/Wasm/MachO implementations that currently live in the llvm-objdump.cpp file. These implementations better be moved to ELFDump.cpp, COFFDump.cpp and other corresponding files, to move platform specific implementation out from the common logic. The patch does that. Also, I had to move ToolSectionFilter helper and SectionFilterIterator, SectionFilter to a header to make them available across the objdump code. Differential revision: https://reviews.llvm.org/D56842 llvm-svn: 351545
2019-01-15[llvm-objdump] - Cleanup the code. NFCI.George Rimar1-1/+1
This is a cosmetic cleanup for the llvm-objdump code. This patch: * Renames things to match the official LLVM code style (lower case -> upper case). * Removes few obviously excessive variables. * Moves a few lines closer to the place of use, reorders the code a bit to simplify it, to avoid doing excessive returns and to avoid using 'else` after returns. I focused only on a llvm-objdump.h/llvm-objdump.cpp files. Few changes in the MachODump.cpp and COFFDump.cpp are a result of llvm-objdump.h modification. Differential revision: https://reviews.llvm.org/D56637 llvm-svn: 351171
2018-11-11[llvm-objdump] Use WithColor for error reportingJonas Devlieghere1-2/+4
Use helpers from Support/WithError.h to print errors. llvm-svn: 346623
2018-09-27llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song1-1/+1
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits Differential Revision: https://reviews.llvm.org/D52573 llvm-svn: 343163
2018-08-21Print "invalid mangled name" when we can't demangle something.Zachary Turner1-0/+2
llvm-svn: 340340
2018-08-20[llvm-objdump] Add ability to demangle COFF symbols.Zachary Turner1-2/+17
llvm-svn: 340221
2018-05-01Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46290 llvm-svn: 331272
2018-04-01[tools] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang1-1/+1
Summary: r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. Reviewers: JDevlieghere, zturner, echristo, dberris, friss Reviewed By: echristo Subscribers: gbedwell, llvm-commits Differential Revision: https://reviews.llvm.org/D45141 llvm-svn: 328943
2017-12-13Remove redundant includes from tools.Michael Zolotukhin1-4/+0
llvm-svn: 320631
2017-10-11Convert a few ErrorOr to Expected.Rafael Espindola1-2/+2
llvm-svn: 315477
2016-09-30[llvm-objdump] Switch to a range loop. NFCI.Davide Italiano1-5/+3
llvm-svn: 282982