aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/ELFDumper.cpp
AgeCommit message (Collapse)AuthorFilesLines
3 daysAdding Matching and Inference Functionality to Propeller (#160706)wdx7271-0/+2
We have optimized the implementation of introducing the "matching and inference" technique into Propeller. In this new implementation, we have made every effort to avoid introducing new compilation parameters while ensuring compatibility with Propeller's current usage. Instead of creating a new profile format, we reused the existing one employed by Propeller. This new implementation is fully compatible with Propeller's current usage patterns and reduces the amount of code changes. For detailed information, please refer to the following RFC: https://discourse.llvm.org/t/rfc-adding-matching-and-inference-functionality-to-propeller/86238. We plan to submit the relevant changes in several pull requests (PRs). The current one is the first PR, which adds the basic block hash to the SHT_LLVM_BB_ADDR_MAP section. co-authors: lifengxiang1025 <lifengxiang@kuaishou.com>; zcfh <wuminghui03@kuaishou.com> Co-authored-by: lifengxiang1025 <lifengxiang@kuaishou.com> Co-authored-by: zcfh <wuminghui03@kuaishou.com> Co-authored-by: Rahman Lavaee <rahmanl@google.com>
2025-09-30[llvm-readobj][NFC] Restore and disable clang-format for machine type list ↵Nick Sarnie1-172/+167
(#160122) The original code was more readable, just disable `clang-format` for this code. See https://github.com/llvm/llvm-project/pull/159793 Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-09-22[BinaryFormat][ELF] Rename machine type INTEL205 to INTELGT (#159791)Nick Sarnie1-0/+1
`EM_INTEL205` was renamed to `EM_INTELGT` (ref [here](https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=7b9f985957798ba4dacc454f22c9e426c6897cb8)) and is used for Intel GPU images. We will be using this type for offloading to Intel GPUs. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-09-19[llvm-readobj][NFC] Format ElfMachineType array definition (#159793)Nick Sarnie1-164/+171
Planning to add to the list in https://github.com/llvm/llvm-project/pull/159791, so format it. Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-09-17[AMDGPU] Add gfx1251 subtarget (#159430)Stanislav Mekhanoshin1-0/+1
2025-09-17[LLVM] Fix offload and update CUDA ABI for all SM values (#159354)Joseph Huber1-12/+54
Summary: Turns out the new CUDA ABI now applies retroactively to all the other SMs if you upgrade to CUDA 13.0. This patch changes the scheme, keeping all the SM flags consistent but using an offset. Fixes: https://github.com/llvm/llvm-project/issues/159088
2025-09-05[llvm-readobj][ELF] Prints hex format values in lower-case mode (#156683)Ádám Kallai1-12/+13
Previously, llvm-readelf dumped hex format values in different ways. Some of them were printed in upper-case, while the others were in lower-case format. This change switches the format to lower-case in all cases. Why is this useful? As an example, FileCheck comparisons are case-sensitive by default. This change means it's easier to compare those values, because they have the same format.
2025-08-25[SHT_LLVM_BB_ADDR_MAP] Change the callsite feature to emit end of callsites. ↵Rahman Lavaee1-2/+2
(#155041) This PR simply moves the callsite anchors from the beginning of callsites to their end. Emitting the end of callsites is more sensible as it allows breaking the basic block into subblocks which end with control transfer instructions.
2025-08-15Move function info word into its own data structure (#153627)Sterling-Augustine1-9/+12
The sframe generator needs to construct this word separately from FDEs themselves, so split them into a separate data structure.
2025-08-15[llvm-readobj] Dump SFrame relocations as well (#153161)Pavel Labath1-12/+76
If there is a relocation for a particular FDE, print it as well. This is mainly meant for human consumption (otherwise, there's no way to tell which function a given (relocatable) FDE refers to). For testing of relocation generation, I'd still recommend using the regular relocation dumper, as this code will not detect (e.g.) any superfluous relocations. I've considered handling relocations inside the SFrameParser class, but I couldn't find an elegant way to do that. Right now, I don't have a use case for resolving relocations there as lldb (my other use case for SFrameParser) will always operate on linked objects.
2025-08-12Reapply "[Object] Parsing and dumping of SFrame Frame Row Entries" (#152650) ↵Pavel Labath1-1/+28
(#152695) This reapplies #152650 with a build fix for clang-11 (need explicit template parameters for ArrayRef construction) and avoiding the default-in-a-switch-covering-enum warning. It also adds two new tests. The original commit message was: The trickiest part here is that the FREs have a variable size, in two (or three?) dimensions: - the size of the StartAddress field. This determined by the FDE they are in, so it is uniform across all FREs in one FDE. - the number and sizes of offsets following the FRE. This can be different for each FRE. While vending this information through a template API would be possible, I believe such an approach would be very unwieldy, and it would still require a sequential scan through the FRE list. This is why I'm implementing this by reading the data into a common data structure using the fallible iterator pattern. For more information about the SFrame unwind format, see the [specification](https://sourceware.org/binutils/wiki/sframe) and the related [RFC](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900).
2025-08-08Revert "[Object] Parsing and dumping of SFrame Frame Row Entries" (#152650)Pavel Labath1-28/+1
Reverts llvm/llvm-project#151301 - build breakage on multiple bots.
2025-08-08[Object] Parsing and dumping of SFrame Frame Row Entries (#151301)Pavel Labath1-1/+28
The trickiest part here is that the FREs have a variable size, in two (or three?) dimensions: - the size of the StartAddress field. This determined by the FDE they are in, so it is uniform across all FREs in one FDE. - the number and sizes of offsets following the FRE. This can be different for each FRE. While vending this information through a template API would be possible, I believe such an approach would be very unwieldy, and it would still require a sequential scan through the FRE list. This is why I'm implementing this by reading the data into a common data structure using the fallible iterator pattern. For more information about the SFrame unwind format, see the [specification](https://sourceware.org/binutils/wiki/sframe) and the related [RFC](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900).
2025-08-03[llvm-readobj] Remove an unnecessary cast (NFC) (#151851)Kazu Hirata1-1/+1
Addr is already of const uint8_t *.
2025-07-31[ELF] handle new NVIDIA GPU variants. (#151604)Artem Belevich1-3/+7
2025-07-30[Object] Parsing and dumping of SFrame FDEs (#149828)Pavel Labath1-28/+91
Also known as Function Description Entries. The entries occupy a contiguous piece of the section, so the code is mostly straight-forward. For more information about the SFrame unwind format, see the [specification](https://sourceware.org/binutils/wiki/sframe) and the related [RFC](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900).
2025-07-21[LLVM] Update CUDA ELF flags for their new ABI (#149534)Joseph Huber1-32/+38
Summary: We rely on these flags to do things in the runtime and print the contents of binaries correctly. CUDA updated their ABI encoding recently and we didn't handle that. it's a new ABI entirely so we just select on it when it shows up. Fixes: https://github.com/llvm/llvm-project/issues/148703
2025-07-21[Object] Beginnings of SFrame parser and dumper (#147294)Pavel Labath1-0/+59
This PR adds the SFrameParser class and uses it from llvm-readobj to dump the section contents. Currently, it only supports parsing the SFrame section header. Other parts of the section will be added in follow-up patches. llvm-readobj uses the same sframe flag syntax as GNU readelf, but I have not attempted match the output format of the tool. I'm starting with the "llvm" output format because it's easier to generate and lets us tweak the format to make it useful for testing the generation code. If needed, support for the GNU format could be added by overriding this functionality in the GNU ELF Dumper. For more information, see the [sframe specification](https://sourceware.org/binutils/wiki/sframe) and the related [RFC](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900).
2025-07-18Remove last few bits for Native Client support (#148983)Brad Smith1-1/+1
2025-07-16[elf] Add support for {SHT,PT}_GNU_SFRAME constants (#148803)Pavel Labath1-0/+1
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-06-23[SHT_LLVM_BB_ADDR_MAP] Encode and decode callsite offsets in a ↵Rahman Lavaee1-0/+2
newly-introduced SHT_LLVM_BB_ADDR_MAP version. (#144426) Recently, we have been looking at some optimizations targeting individual calls. In particular, we plan to extend the address mapping technique to map to individual callsites. For example, in this piece of code for a basic blocks: ``` <BB>: 1200: lea 0x1(%rcx), %rdx 1204: callq foo 1209: cmpq 0x10, %rdx 120d: ja L1 ``` We want to emit 0x9 as the call site offset for `callq foo` (the offset from the block entry to right after the call), so that we know if a sampled address is before the call or after. This PR implements the decode/encode/emit capability. The Codegen change will be implemented in a later PR.
2025-06-19[AMDGPU] Initial support for gfx1250 target. (#144965)Stanislav Mekhanoshin1-0/+1
This is just a stub for now.
2025-04-14[tools] Use llvm::append_range (NFC) (#135721)Kazu Hirata1-27/+12
2025-03-10[readobj][Arm][AArch64] Refactor Build Attributes parsing under ↵SivanShani-Arm1-0/+7
ELFAtributeParser and add support for AArch64 Build Attributes (#128727) Refactor readobj to integrate AArch64 Build Attributes under ELFAttributeParser. ELFAttributeParser now serves as a base class for: - ELFCompactAttrParser, handling Arm-style attributes with a single build attribute subsection. - ELFExtendedAttrParser, handling AArch64-style attributes with multiple build attribute subsections. This improves code organization and better aligns with the attribute parsing model. Add support for parsing AArch64 Build Attributes.
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-02-19[AMDGPU] Replace gfx940 and gfx941 with gfx942 in llvm (#126763)Fabian Ritter1-2/+0
gfx940 and gfx941 are no longer supported. This is one of a series of PRs to remove them from the code base. This PR removes all non-documentation occurrences of gfx940/gfx941 from the llvm directory, and the remaining occurrences in clang. Documentation changes will follow. For SWDEV-512631
2025-02-14[AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (1/3) (#125687)Csanád Hajdú1-1/+9
Add support for the new SHF_AARCH64_PURECODE ELF section flag: https://github.com/ARM-software/abi-aa/pull/304 The general implementation follows the existing one for ARM targets. Generating object files with the `SHF_AARCH64_PURECODE` flag set is enabled by the `+execute-only` target feature. Related PRs: * Clang: https://github.com/llvm/llvm-project/pull/125688 * LLD: https://github.com/llvm/llvm-project/pull/125689
2025-02-10[ELF] Add support for CREL to getSectionAndRelocationsAiden Grossman1-0/+10
This patch updates the getSectionAndRelocations function to also support CREL relocation sections. Unit tests have been added. This patch also updates consumers to say they explicitly do not support CREL format relocations. Subsequent patches will make the consumers work with CREL format relocations and also add in testing support. Reviewers: red1bluelost, MaskRay, rlavaee Reviewed By: MaskRay Pull Request: https://github.com/llvm/llvm-project/pull/126445
2025-02-07[llvm-readobj][ELF][RISCV] Dump .note.gnu.property section contents (#125642)Ming-Yi Lai1-13/+42
RISCV Zicfilp/Zicfiss extensions uses the `.note.gnu.property` section to store flags indicating the adoption of features based on these extensions. This patch enables the llvm-readobj/llvm-readelf tools to dump these flags with the `--note` flag.
2024-12-11[llvm][llvm-readobj] Add NT_ARM_GCS Linux core note type (#117545)David Spickett1-0/+1
The ARM Guarded Control Stack extension (GCS) is similar to existing shadow stack extensions for other architectures. The core note will include which features of GCS are enabled, which have been locked in their current state, and the stack pointer of the shadow stack. Note that 0x40f is NT_ARM_POE, FPMR is supported by LLDB and GCS will be soon, POE is not at this time. So NT_ARM_POE will be added when that work starts. See https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h.
2024-11-18AMDGPU: Add gfx950 subtarget definitions (#116307)Matt Arsenault1-0/+1
Mostly a stub, but adds some baseline tests and tests for removed instructions.
2024-11-12[AMDGPU] Introduce a new generic target `gfx9-4-generic` (#115190)Shilei Tian1-0/+1
This patch introduces a new generic target, `gfx9-4-generic`. Since it doesn’t support FP8 and XF32-related instructions, the patch includes several code reorganizations to accommodate these changes.
2024-10-23[AMDGPU] Add a new target for gfx1153 (#113138)Carl Ritson1-0/+1
2024-09-13[llvm][tools] Strip unneeded uses of raw_string_ostream::str() (NFC)JOE19941-21/+21
Remove excess layer of indirection.
2024-08-19[PAC][ELF][AArch64] Encode several ptrauth features in PAuth core info (#102508)Daniil Kovalev1-1/+6
For llvm_linux platform, define the following meaning for bits 9, 10, 11: - bit 9: set if indirect gotos signing is enabled; - bit 10: set if type info vtable pointer discrimination is enabled; - bit 11: set if function pointer type discrimination is enabled.
2024-08-15[SPARC][Utilities] Add names for SPARC ELF flags in LLVM binary utilities ↵Koakuma1-0/+16
(#102843) This allows us to use and print readable names in LLVM binary utilities.
2024-08-12[llvm][llvm-readobj] Add NT_ARM_FPMR corefile note type (#102594)David Spickett1-0/+1
This contains the fpmr register which was added in Armv9.5-a. This register mainly contains controls for fp8 formats. It was added to the Linux Kernel in https://github.com/torvalds/linux/commit/4035c22ef7d43a6c00d6a6584c60e902b95b46af.
2024-08-06[PAC][ELF][AArch64] Encode signed GOT flag in PAuth core info (#96159)Daniil Kovalev1-1/+2
Treat 8th bit of version value for llvm_linux platform as signed GOT flag. - clang: define `PointerAuthELFGOT` LangOption and set 8th bit of `aarch64-elf-pauthabi-version` LLVM module flag correspondingly; - llvm-readobj: print `PointerAuthELFGOT` or `!PointerAuthELFGOT` in version description of llvm_linux platform depending on whether the flag is set.
2024-08-06[PAC][AArch64] Support init/fini array signing (#96478)Daniil Kovalev1-1/+3
If both `-fptrauth-init-fini` and `-fptrauth-calls` are passed, sign function pointers in `llvm.global_ctors` and `llvm.global_dtors` with constant discriminator 0xD9D4 (`ptrauth_string_discriminator("init_fini")`). Additionally, if `-fptrauth-init-fini-address-discrimination` is passed, address discrimination is used for signing (otherwise, just constant discriminator is used). For address discrimination, we use it's special form since uses of `llvm.global_{c|d}tors` are disallowed (see `Verifier::visitGlobalVariable`) and we can't emit `getelementptr` expressions referencing these special arrays. A signed ctor/dtor pointer with special address discrimination applied looks like the following: ``` ptr ptrauth (ptr @foo, i32 0, i64 55764, ptr inttoptr (i64 1 to ptr)) ```
2024-07-03[llvm-readobj][ELF] Alter JSON/LLVM output on note sections to allow for ↵Fred Grim1-5/+10
multiple notes per section in JSON (#96813) It turns out that the notes section for corefiles (or really any elf file with multiple notes) is set up in such a way for LLVM formatted output that the JSON equivalent only has the last note since the notes are held in a dictionary with every key being Note. This pr alters the layout for the notes to a list of dictionaries to sidestep this issue for JSON output. Prior to this pr a note section in the output looked like (for LLVM output): ``` Notes [ NoteSection { Name: <?> Offset: 0x2148 Size: 0x1F864 Note { Owner: CORE Data size: 0x150 Type: NT_PRSTATUS (prstatus structure) Description data ( 0000: 06000000 00000000 00000000 06000000 |................| ... ) } Note { Owner: CORE Data size: 0x88 Type: NT_PRPSINFO (prpsinfo structure) Description data ( 0000: 02440000 00000000 04054040 00000000 |.D........@@....| .... ``` But is now: ``` NoteSections [ NoteSection { Name: <?> Offset: 0x2148 Size: 0x1F864 Notes [ { Owner: CORE Data size: 0x150 Type: NT_PRSTATUS (prstatus structure) Description data ( 0000: 06000000 00000000 00000000 06000000 |................| ... ) } { Owner: CORE Data size: 0x88 Type: NT_PRPSINFO (prpsinfo structure) Description data ( 0000: 02440000 00000000 04054040 00000000 |.D........@@....| ... ```
2024-07-03Revert "[llvm-readobj][ELF] Test multivalued rpath entries and alter the ↵serge-sans-paille1-8/+9
output for readobj to emphasize the single valued nature of NEEDED, SONAME, USED etc. (#96562)" Reverted due to output change that breaks downstream project, see https://github.com/llvm/llvm-project/pull/96562#issuecomment-2204938038 This reverts commit 161e1689ba98fabba71cac21f536708c78e9d7b0.
2024-07-01[MC,llvm-readobj,yaml2obj] Support CREL relocation formatFangrui Song1-7/+82
CREL is a compact relocation format for the ELF object file format. This patch adds integrated assembler support (using the RELA form) available with `llvm-mc -filetype=obj -crel a.s -o a.o`. A dependent patch will add `clang -c -Wa,--crel,--allow-experimental-crel`. Also add llvm-readobj support (for both REL and RELA forms) to facilitate testing the assembler. Additionally, yaml2obj gains support for the RELA form to aid testing with llvm-readobj. We temporarily assign the section type code 0x40000020 from the generic range to `SHT_CREL`. We avoided using `SHT_LLVM_` or `SHT_GNU_` to avoid code churn and maintain broader applicability for interested psABIs. Similarly, `DT_CREL` is temporarily 0x40000026. LLVM will change the code and break compatibility. This is not an issue if all relocatable files using CREL are regenerated (aka no prebuilt relocatable files). Link: https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600 Pull Request: https://github.com/llvm/llvm-project/pull/91280
2024-06-26[llvm-readobj][ELF] Test multivalued rpath entries and alter the output for ↵Fred Grim1-9/+8
readobj to emphasize the single valued nature of NEEDED, SONAME, USED etc. (#96562) In the context of #95976 it became clear that the output for readobj implied multi valued entries in several cases in the elf headers that the documentation only allowed for a single value. DT_NEEDED is the example here where the value is an offset into the string table without any sort of separator that could give you multiple entries. This patch alters the LLVM output so that the single valued nature is emphasized. For example the output was: ``` DynamicSection [ (35 entries) Tag Type Name/Value 0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:] 0x0000000000000001 NEEDED Shared library: [libm.so.6] 0x0000000000000001 NEEDED Shared library: [libz.so.1] 0x0000000000000001 NEEDED Shared library: [libzstd.so.1] ``` and is now ``` Tag Type Name/Value 0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:] 0x0000000000000001 NEEDED Shared library: libm.so.6 0x0000000000000001 NEEDED Shared library: libz.so.1 0x0000000000000001 NEEDED Shared library: libzstd.so.1 ``` This pr also tests that multi-valued rpaths are handled correctly in the JSON case (i.e. they become proper lists) like: ``` { "Tag": 15, "Type": "RPATH", "Value": 9, "Path": [ "x", "w", "U" ] }, ``` when separated by :
2024-06-24[llvm-readobj][ELF] Implement JSON output for --dynamic-table (#95976)Fred Grim1-0/+61
When printing JSON output with --dynamic-table I noticed that the output is invalid JSON. This patch overrides the printDynamicTable() function in the JSONELFDumper to return a list of dictionaries for the DynamicSection value. Before the output was: ``` { "FileSummary": { "File": "bin/llvm-readelf", "Format": "elf64-x86-64", "Arch": "x86_64", "AddressSize": "64bit", "LoadName": "<Not found>" }DynamicSection [ (35 entries) Tag Type Name/Value 0x000000000000001D RUNPATH Library runpath: [$ORIGIN/../lib:] 0x0000000000000001 NEEDED Shared library: [libm.so.6] 0x0000000000000001 NEEDED Shared library: [libz.so.1] 0x0000000000000001 NEEDED Shared library: [libzstd.so.1] ``` Now the output looks like: ``` "DynamicSection": [ { "Tag": 29, "Type": "RUNPATH", "Value": 6322, "Path": [ "$ORIGIN/../lib" ] }, { "Tag": 1, "Type": "NEEDED", "Value": 6109, "Library": "libm.so.6" }, ```
2024-06-06[AMDGPU] Add a new target gfx1152 (#94534)Shilei Tian1-0/+1
2024-05-31AMDGPU: Add gfx12-generic target (#93875)Konstantin Zhuravlyov1-1/+2
2024-05-23[llvm-readobj] Fixes malformed json on JSON printed corefiles (#92835)Fred Grim1-1/+2
This patch fixes an issue where, when printing corefile notes with llvm-readobj as json, the dumper generated llvm formatted output which isn't valid json. This alters the dumper to, in the NT_FILE, note, dump properly formatted json data. Prior to this patch the JSON output was formatted like: ``` "Mapping": [ "Start": 4096, "End": 8192, "Offset": 12288, "Filename": "/path/to/a.out" ], ``` Whereas now it is formatted as: ``` "Mappings": [ { "Start": 4096, "End": 8192, "Offset": 12288, "Filename": "/path/to/a.out" }, ``` Which is valid. Additionally the LLVM output has changed to match the structure of the JSON output (i.e. instead of lists of keys it is a list of dictionaries)
2024-04-22[llvm-readobj] Remove --raw-relrFangrui Song1-53/+15
https://reviews.llvm.org/D47919 dumped RELR relocations as `R_*_RELATIVE` and added --raw-relr (not in GNU) for testing purposes (more readable than `llvm-readelf -x .relr.dyn`). The option is obsolete after `llvm-readelf -r` output gets improved (#89162). Since --raw-relr never seems to get more adoption. Let's remove it to avoid some complexity. Pull Request: https://github.com/llvm/llvm-project/pull/89426
2024-04-19[llvm-readelf] Print more information for RELRFangrui Song1-20/+110
llvm-readelf/llvm-readobj print RELR as REL relocations with a fixed type (e.g. `R_*_RELATIVE`). GNU readelf printed only addresses and have recently switched to a more descritive style that includes a symbolic address column (symbolized using .symtab/.strtab) (milestone: binutils 2.43). This patch implements the new GNU style, which seems superior to the current REL style and essentially obsoletes LLVM-specific --raw-relr (`printRelrReloc`). Pull Request: https://github.com/llvm/llvm-project/pull/89162
2024-04-15llvm-readobj/ARM: activate big-endian attribute printing (#87806)Ramkumar Ramachandra1-7/+3
Activate attribute printing for big-endian encoding for ARM. The supporting code already exists, and the patch is trivial. Fixes #62400.