aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/ELFDump.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-16[elf] Add support for {SHT,PT}_GNU_SFRAME constants (#148803)Pavel Labath1-0/+3
Reference: https://sourceware.org/git/?p=gnu-gabi.git;a=blob;f=program-loading-and-dynamic-linking.txt;h=3357d865720285df2d29c4e8f92de49ddf1beb40;hb=refs/heads/master
2025-03-18[llvm-objdump] Delete unused variables after #128434Fangrui Song1-6/+0
2025-03-09[llvm-objdump][ELF]Fix crash when reading strings from .dynstr (#125679)Ruoyu Qiu1-2/+19
This change introduces a check for the strtab offset to prevent llvm-objdump from crashing when processing malformed ELF files. It provide a minimal reproduce test for https://github.com/llvm/llvm-project/issues/86612#issuecomment-2035694455. Additionally, it modifies how llvm-objdump handles and outputs malformed ELF files with invalid string offsets.(More info: https://discourse.llvm.org/t/should-llvm-objdump-objdump-display-actual-corrupted-values-in-malformed-elf-files/84391) Fixes: #86612 Co-authored-by: James Henderson <James.Henderson@sony.com>
2025-02-28[llvm-objdump] Rework .gnu.version_d dumpingFangrui Song1-35/+19
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-02-24[llvm-objdump]Correct .dynstr finding of getDynamicStrTab() (#127975)Ruoyu Qiu1-2/+2
The dynamic string table used by the dynamic section is referenced by the sh_link field of that section, so we should use that directly, rather than going via the dynamic symbol table. More info: https://github.com/llvm/llvm-project/pull/125679#discussion_r1961333454 Signed-off-by: Ruoyu Qiu <cabbaken@outlook.com>
2025-01-13[llvm-objdump] Remove leading whitespace for PT_GNU_PROPERTY. (#121591)Ryan Mansfield1-1/+1
This fixes the misaligned display of addresses for this p_type. Previous: ``` STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**64 filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw- PROPERTY off 0x0000000000000358 vaddr 0x0000000000000358 paddr 0x0000000000000358 align 2**3 filesz 0x0000000000000020 memsz 0x0000000000000020 flags r-- NOTE off 0x0000000000000334 vaddr 0x0000000000000334 paddr 0x0000000000000334 align 2**2 filesz 0x0000000000000020 memsz 0x0000000000000020 flags r-- ``` After: ``` STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**64 filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw- PROPERTY off 0x0000000000000358 vaddr 0x0000000000000358 paddr 0x0000000000000358 align 2**3 filesz 0x0000000000000020 memsz 0x0000000000000020 flags r-- NOTE off 0x0000000000000334 vaddr 0x0000000000000334 paddr 0x0000000000000334 align 2**2 filesz 0x0000000000000020 memsz 0x0000000000000020 flags r-- ```
2024-12-23[llvm-objdump] Remove some unneeded headers. (#120541)Cabbaken1-1/+0
Co-authored-by: qiuruoyu <qiuruoyu@xiaomi.com>
2024-07-08[llvm-objdump] -r: support CRELFangrui Song1-1/+5
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-04-06llvm-objdump/ELF: fix crash when reading dyn str table (#87519)Ramkumar Ramachandra1-5/+6
When reading the dynamic string table, llvm-objdump used to crash if the ELF was malformed, due to an erroneous consumption of error status. Instead, propogate the error status to the caller, fixing the crash, and printing a warning.
2024-02-20[llvm-objdump] Add support for the PT_OPENBSD_SYSCALLS segment type. (#82121)Frederic Cambus1-0/+3
Reference: https://github.com/openbsd/src/blob/master/sys/sys/exec_elf.h
2023-11-27[llvm-objdump] Fix lma display issue for non-bss sections (#72141)Jason Liu1-2/+4
llvm-readobj and llvm-objdump have inconsistent handling of display lma for sections. This patch tries to common code up and adapt the same approach for both tools.
2023-09-22[llvm-objdump] Add support for the PT_OPENBSD_NOBTCFI segment type. (#67127)Frederic Cambus1-0/+3
Reference: https://github.com/openbsd/src/blob/master/sys/sys/exec_elf.h
2023-08-14[llvm-objdump] Add WarningHandler as a member variable. NFCFangrui Song1-11/+6
This can be used to avoid `auto WarningHandler = ...`. Similar to llvm-readobj.
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] Move printDynamicRelocations into ELFDump.cpp. NFCFangrui Song1-0/+34
2023-07-14[llvm-objdump] Create ObjectFile specific dumpersFangrui Song1-42/+46
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-06reland: [Demangle] make llvm::demangle take std::string_view rather than ↵Nick Desaulniers1-4/+1
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-02Revert "[Demangle] make llvm::demangle take std::string_view rather than ↵Nick Desaulniers1-1/+4
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-4/+1
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-01-28Use llvm::count{lr}_{zero,one} (NFC)Kazu Hirata1-2/+1
2022-11-19[llvm-objdump] Left justify display of OpenBSD headersBrad Smith1-4/+4
This looks the same as OpenBSD's GNU objdump.
2022-11-18[llvm] - Recognizing 'PT_OPENBSD_MUTABLE' segment type.Brad Smith1-0/+3
Recognizing 'PT_OPENBSD_MUTABLE' segment type. https://github.com/openbsd/src/commit/bd249b5664da50f0178adea78250a7a0d8ea6566 Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D137903
2022-09-14[llvm-objdump] Change printSymbolVersionDependency to use ELFFile APIFangrui Song1-19/+20
When .gnu.version_r is empty (allowed by readelf but warned by objdump), llvm-objdump -p may decode the next section as .gnu.version_r and may crash due to out-of-bounds C string reference. ELFFile<ELFT>::getVersionDependencies handles 0-entry .gnu.version_r gracefully. Just use it. Fix https://github.com/llvm/llvm-project/issues/57707 Differential Revision: https://reviews.llvm.org/D133751
2022-03-28[llvm-objdump] --private-headers: change errors to warnings for dynamic ↵Fangrui Song1-2/+6
section dumping Fix #54456: `objcopy --only-keep-debug` produces a linked image with invalid empty dynamic section. llvm-objdump -p currently reports an error which seems excessive. ``` % llvm-readelf -l a.out llvm-readelf: warning: 'a.out': no valid dynamic table was found ... ``` Follow the spirit of llvm-readelf -l (D64472) and report a warning instead. This allows later files to be dumped despite warnings for an input file, and improves objdump compatibility in that the exit code is now 0 instead of 1. ``` % llvm-objdump -p a.out # new behavior ... Program Header: llvm-objdump: warning: 'a.out': invalid empty dynamic section % objdump -p a.out ... Dynamic Section: ``` Reviewed By: jhenderson, raj.khem Differential Revision: https://reviews.llvm.org/D122505
2021-10-06[llvm] Replace report_fatal_error(std::string) uses with ↵Simon Pilgrim1-1/+1
report_fatal_error(Twine) As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared.
2021-05-04[llvm-objdump] Improve newline consistency between different pieces of ↵Fangrui Song1-5/+4
information When dumping multiple pieces of information (e.g. --all-headers), there is sometimes no separator between two pieces. This patch uses the "\nheader:\n" style, which generally improves compatibility with GNU objdump. Note: objdump -t/-T does not add a newline before "SYMBOL TABLE:" and "DYNAMIC SYMBOL TABLE:". We add a newline to be consistent with other information. `objdump -d` prints two empty lines before the first 'Disassembly of section'. We print just one with this patch. Differential Revision: https://reviews.llvm.org/D101796
2021-04-28[llvm-objdump] Fix dumping dynamic relative relocations for SHT_RELAlex Richardson1-1/+4
Previously printing R_386_RELATIVE relocations would trigger `error: can't read an entry at 0x40: it goes past the end of the section (0x40)` I found this while writing a test case for LLD (D100490). This also includes some minor cleanup in the elf-dynamic-relcos.test llvm-objdump test based on the newly added test. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D100489
2020-12-16[lib/Object] - Make ELFObjectFile::getSymbol() return Expected<>.Georgii Rymar1-2/+7
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-04[lib/Object, tools] - Make ELFObjectFile::getELFFile return reference.Georgii Rymar1-19/+19
We always have an object, so we don't have to return a pointer. Differential revision: https://reviews.llvm.org/D92560
2020-09-15[lib/Object] - Refine interface of ELFFile<ELFT>. NFCI.Georgii Rymar1-3/+3
`ELFFile<ELFT>` has many methods that take pointers, though they assume that arguments are never null and hence could take references instead. This patch performs such clean-up. Differential revision: https://reviews.llvm.org/D87385
2020-07-14[test/Object][llvm-objdump] - llvm-objdump: don't abort() when the e_phoff ↵Georgii Rymar1-8/+14
field is invalid and refine testing. llvm-objdump currently calls report_fatal_error() when the e_phoff field is invalid. This is tested by elf-invalid-phdr.test which has the following issues: 1) It uses a precompiled object. 2) it could be a part of invalid.test. 3) It tests the Object lib, but we have no separate test for llvm-objdump. This patch addresses issues mentioned. Differential revision: https://reviews.llvm.org/D83559
2020-04-23[llvm-objdump][ELF][NFC] Create ELFDump.hHubert Tong1-17/+19
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-06[llvm-objdump][NFC] Declare command-line externs in headers with namespaceHubert Tong1-0/+1
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-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-20[llvm-objdump] - Fix the indentation when printing dynamic tags.Georgii Rymar1-1/+8
We have a bug currently: printed tag names might overlap the value column. It happens for MIPS now. This patch adds a logic to calculate the size of indentation on fly to fix such issues. Differential revision: https://reviews.llvm.org/D72838
2019-12-04[ELF] Support for PT_GNU_PROPERTY in header and toolsPeter Smith1-0/+3
The PT_GNU_PROPERTY is generated by a linker to describe the .note.gnu.property section. The Linux kernel uses this program header to locate the .note.gnu.property section. It is described in "The Linux gABI extension" Include support for llvm-readelf, llvm-readobj and the yaml reader and writers. Differential Revision: https://reviews.llvm.org/D70959
2019-11-19[llvm-objdump] Print relocation addends in hexadecimalDavid Bozier1-3/+6
Summary: Matches GNU objdump. Makes debugging easier for me as I'm working out addresses from symbol+addend, so it would be good to be calculating in a single format. Reviewers: MaskRay, grimar, jhenderson, bd1976llvm Reviewed By: jhenderson Subscribers: sdardis, jrtc27, atanasyan, rupprecht, seiya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69997
2019-08-21[llvm-objdump] - Cleanup the error reporting.George Rimar1-1/+1
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-04-25[llvm-objdump] errorToErrorCode+message -> toStringFangrui Song1-4/+3
For test/Object/elf-invalid-phdr.test, the intended error message got lost due to errorToErrorCode(). llvm-svn: 359166
2019-04-24Revert "[llvm-objdump] errorToErrorCode+message -> toString"JF Bastien1-3/+4
Revert r359100 It breaks llvm/test/Object/elf-invalid-phdr.test llvm-svn: 359110
2019-04-24[llvm-objdump] errorToErrorCode+message -> toStringFangrui Song1-4/+3
llvm-svn: 359100
2019-04-15[llvm-objdump] Wrap things in namespace llvmFangrui Song1-9/+10
llvm-svn: 358417
2019-04-08[llvm-objdump] Migrate relocation handling functions from error_code to ErrorFangrui Song1-13/+12
llvm-svn: 357920
2019-04-07[llvm-objdump] Simplify some ELF typename: ELFFile<ELFT>::Elf_xxx -> ELFT::xxxFangrui Song1-11/+4
llvm-svn: 357857
2019-04-07.Fangrui Song1-17/+8
llvm-svn: 357856
2019-04-07[llvm-objdump] Simplify Expected<T> handling with unwrapOrErrorFangrui Song1-30/+13
llvm-svn: 357855
2019-03-02[llvm-objdump] Should print unknown d_tag in hex formatXing GUO1-9/+2
Summary: Currently, `llvm-objdump` prints "unknown" instead of d_tag value in hex format. Because getDynamicTagAsString returns "unknown" rather than empty string. Reviewers: grimar, jhenderson Reviewed By: jhenderson Subscribers: rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58763 llvm-svn: 355262
2019-02-27[llvm-objdump] Should print strings when dumping DT_RPATH, DT_RUNPATH, ↵Xing GUO1-1/+3
DT_SONAME, DT_AUXILIARY and DT_FILTER tags in dynamic section. Summary: Before: ``` Dynamic Section: NEEDED libpthread.so.0 ... NEEDED ld-linux-x86-64.so.2 RPATH 0x00000000001c2e61 ``` After: ``` Dynamic Section: NEEDED libpthread.so.0 ... NEEDED ld-linux-x86-64.so.2 RPATH $ORIGIN/../lib ``` Only a small problem here, I have no idea on choosing test case. I see there's a test file(test/tools/llvm-objdump/private-headers-dynamic-section.test). But it has no DT_RPATH and DT_RUNPATH tags. Shall I replace the ELF file in the Inputs dir by a new one? Reviewers: jhenderson, grimar Reviewed By: jhenderson Subscribers: srhines, rupprecht, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58707 llvm-svn: 355001
2019-02-26[llvm-objdump] Add `Version Definitions` dumperXing GUO1-3/+44
Summary: `llvm-objdump` needs a `Version Definitions` dumper. Reviewers: grimar, jhenderson Reviewed By: grimar, jhenderson Subscribers: rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58615 llvm-svn: 354871
2019-02-25[llvm-objdump] Add `Version References` dumperXing GUO1-0/+70
Summary: Add symbol version dumper for [#30241](https://bugs.llvm.org/show_bug.cgi?id=30241) Reviewers: jhenderson, MaskRay, kristina, emaste, grimar Reviewed By: jhenderson, grimar Subscribers: grimar, rupprecht, jakehehrlich, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D54697 llvm-svn: 354782