1528 Commits

Author SHA1 Message Date
Sterling-Augustine
5b0619e79b
Move function info word into its own data structure (#153627)
The sframe generator needs to construct this word separately from FDEs
themselves, so split them into a separate data structure.
2025-08-15 13:16:34 -07:00
Pavel Labath
dab971ed23
[llvm-readobj] Dump SFrame relocations as well (#153161)
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-15 10:30:41 +00:00
Pavel Labath
66aa46da6c
Reapply "[Object] Parsing and dumping of SFrame Frame Row Entries" (#152650) (#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-12 10:10:45 +02:00
Pavel Labath
7e8a251f75
Revert "[Object] Parsing and dumping of SFrame Frame Row Entries" (#152650)
Reverts llvm/llvm-project#151301 - build breakage on multiple bots.
2025-08-08 08:29:58 +02:00
Pavel Labath
a82ca1b560
[Object] Parsing and dumping of SFrame Frame Row Entries (#151301)
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-08 08:22:08 +02:00
Kazu Hirata
3412735d29
[llvm-readobj] Remove an unnecessary cast (NFC) (#151851)
Addr is already of const uint8_t *.
2025-08-03 08:44:57 -07:00
Artem Belevich
4e596fc285
[ELF] handle new NVIDIA GPU variants. (#151604) 2025-07-31 17:21:40 -07:00
Pavel Labath
ded255e56e
[Object] Parsing and dumping of SFrame FDEs (#149828)
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-30 11:23:35 +02:00
kkent030315
32127045c8
[llvm-readobj][COFF] Add support for more CET and hotpatch flags (#150967)
- Added `IMAGE_DLL_CHARACTERISTICS_EX_CET_COMPAT_STRICT_MODE`
- Added
`IMAGE_DLL_CHARACTERISTICS_EX_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE`
- Added
`IMAGE_DLL_CHARACTERISTICS_EX_CET_DYNAMIC_APIS_ALLOW_IN_PROC_ONLY`
- Added `IMAGE_DLL_CHARACTERISTICS_EX_CET_RESERVED_1`
- Added `IMAGE_DLL_CHARACTERISTICS_EX_CET_RESERVED_2`
- Added `IMAGE_DLL_CHARACTERISTICS_EX_FORWARD_CFI_COMPAT`
- Added `IMAGE_DLL_CHARACTERISTICS_EX_HOTPATCH_COMPATIBLE`
2025-07-30 00:51:57 +03:00
Joseph Huber
b53be5f4b2
[LLVM] Update CUDA ELF flags for their new ABI (#149534)
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 14:38:03 -05:00
Pavel Labath
aa7ada1dfb
[Object] Beginnings of SFrame parser and dumper (#147294)
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-21 08:46:21 +02:00
Brad Smith
5f001294b1
Remove last few bits for Native Client support (#148983) 2025-07-18 11:26:36 -04:00
Pavel Labath
d4a8a01cef
[elf] Add support for {SHT,PT}_GNU_SFRAME constants (#148803)
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-07-16 09:12:15 +02:00
Kazu Hirata
a265829c90
[llvm-readobj] Remove an unnecessary cast (NFC) (#148118)
TmpSecPtr is already of const uint8_t *.
2025-07-11 09:52:57 -07:00
Rahman Lavaee
8d7a8fcc3a
[SHT_LLVM_BB_ADDR_MAP] Encode and decode callsite offsets in a 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-23 09:25:14 -07:00
Stanislav Mekhanoshin
69974658f0
[AMDGPU] Initial support for gfx1250 target. (#144965)
This is just a stub for now.
2025-06-19 22:52:51 -07:00
Sterling-Augustine
628274dadf
[NFC] Extract Printing portions of DWARFCFIProgram to new files (#143762)
CFIPrograms' most common uses are within debug frames, but it is not
their only use. For example, some assembly writers encode them by hand
into .cfi_escape directives. This PR extracts printing code for them
into its own files, which avoids the need for the main class to depend
on DWARFUnit, sections, and similar.

One in a series of NFC DebugInfo/DWARF refactoring changes to layer it
more cleanly, so that binary CFI parsing can be used from low-level
code, (such as byte strings created via .cfi_escape) without circular
dependencies. The final goal is to make a more limited dwarf library
usable from lower-level code.

More information can be found at
https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665
2025-06-17 16:35:47 -07:00
Haohai Wen
b6f9800eae
[llvm-readobj] Support --string-table for COFF (#141552) 2025-06-03 08:47:15 +08:00
Matt Arsenault
ccb55713db
llvm-readobj: Use reportFatalUsageError (#142039) 2025-05-30 08:09:43 +02:00
Kazu Hirata
b23c1865c0
[tools] Remove unused local variables (NFC) (#138384) 2025-05-03 07:04:48 -07:00
Eli Friedman
312d6b488e
[AArch64] Implement assembler support for new SVE SEH unwind opcodes. (#137895)
In order to support the AArch64 ABI, Microsoft has extended the unwinder
to support additional opcodes. (Updated documentation at
https://learn.microsoft.com/en-us/cpp/build/arm64-exception-handling .)

First in a series of patches to support SVE on Windows.
2025-05-02 15:14:25 -07:00
Kazu Hirata
ab58bcfac4
[tools] Use llvm::append_range (NFC) (#135721) 2025-04-14 22:21:40 -07:00
SivanShani-Arm
b1ebfac185
[readobj][Arm][AArch64] Refactor Build Attributes parsing under 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-03-10 09:48:40 +00:00
Kazu Hirata
65330e20b1
[llvm-readobj] Avoid repeated hash lookups (NFC) (#129657) 2025-03-04 01:50:50 -08:00
Fangrui Song
7c26356703
[llvm-objdump] Rework .gnu.version_d dumping
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-28 09:38:48 -08:00
Fabian Ritter
8615f9aaff
[AMDGPU] Replace gfx940 and gfx941 with gfx942 in llvm (#126763)
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-19 10:20:48 +01:00
Csanád Hajdú
a190f15d2b
[AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (1/3) (#125687)
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-14 08:56:07 +00:00
Aiden Grossman
808b1c11a2
[ELF] Add support for CREL to getSectionAndRelocations
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-10 10:57:19 -08:00
zhijian lin
ec60e1d8e2
[XCOFF][llvm-readobj] Print symbol value kind when dumping symbols (#125861)
llvm-readobj print out symbol value name for xcoff symbol table.

reference doc:
https://www.ibm.com/docs/en/aix/7.2?topic=formats-xcoff-object-file-format#XCOFF__yaa3i18fjbau
2025-02-10 09:37:04 -05:00
Ming-Yi Lai
a1984ec5ea
[llvm-readobj][ELF][RISCV] Dump .note.gnu.property section contents (#125642)
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.
2025-02-07 13:55:16 +08:00
Daniel Paoliello
2201164477
[llvm] Win x64 Unwind V2 2/n: Support dumping UOP_Epilog (#110338)
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.
2025-01-13 16:53:42 -08:00
Chandler Carruth
dd647e3e60
Rework the Option library to reduce dynamic relocations (#119198)
Apologies for the large change, I looked for ways to break this up and
all of the ones I saw added real complexity. This change focuses on the
option's prefixed names and the array of prefixes. These are present in
every option and the dominant source of dynamic relocations for PIE or
PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of
them for the Clang driver which has a huge number of options.

This PR addresses this by building a string table and a prefixes table
that can be referenced with indices rather than pointers that require
dynamic relocations. This removes almost 7k dynmaic relocations from the
`clang` binary, roughly 8% of the remaining dynmaic relocations outside
of vtables. For busy-boxing use cases where many different option tables
are linked into the same binary, the savings add up a bit more.

The string table is a straightforward mechanism, but the prefixes
required some subtlety. They are encoded in a Pascal-string fashion with
a size followed by a sequence of offsets. This works relatively well for
the small realistic prefixes arrays in use.

Lots of code has to change in order to land this though: both all the
option library code has to be updated to use the string table and
prefixes table, and all the users of the options library have to be
updated to correctly instantiate the objects.

Some follow-up patches in the works to provide an abstraction for this
style of code, and to start using the same technique for some of the
other strings here now that the infrastructure is in place.
2024-12-11 15:44:44 -08:00
David Spickett
088e74cf73
[llvm][llvm-readobj] Add NT_ARM_GCS Linux core note type (#117545)
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-12-11 11:19:48 +00:00
Amy Kwan
f31099ce58
[PowerPC][AIX] Emit PowerPC version for XCOFF (#113214)
This PR emits implements the ability to emit the PPC version for both
assembly and object files on AIX.
2024-12-10 11:11:50 -05:00
Matt Arsenault
a6fc489bb7
AMDGPU: Add gfx950 subtarget definitions (#116307)
Mostly a stub, but adds some baseline tests and
tests for removed instructions.
2024-11-18 10:41:14 -08:00
Shilei Tian
de0fd64bed
[AMDGPU] Introduce a new generic target gfx9-4-generic (#115190)
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-11-12 23:11:05 -05:00
Kazu Hirata
3297858c19
[llvm-readobj] Use heterogenous lookups with std::map (NFC) (#114929)
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
2024-11-05 09:38:11 -08:00
Carl Ritson
076aac59ac
[AMDGPU] Add a new target for gfx1153 (#113138) 2024-10-23 12:56:58 +09:00
Jacek Caban
5a68ac8ba7
[llvm-readobj][COFF] Add support for version 2 of CHPE metadata (#109545) 2024-09-22 22:36:39 +02:00
JOE1994
eb11f576a4 [llvm][tools] Strip unneeded uses of raw_string_ostream::str() (NFC)
Remove excess layer of indirection.
2024-09-13 07:12:15 -04:00
JOE1994
6c0b1e75e3 [llvm][tools] Strip unneeded uses of raw_string_ostream::str() (NFC)
Remove unnecessary layer of indirection.
2024-09-13 06:23:54 -04:00
Daniil Kovalev
de5deb7b07
[PAC][ELF][AArch64] Encode several ptrauth features in PAuth core info (#102508)
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-19 12:53:43 +03:00
Koakuma
e61776a0ed
[SPARC][Utilities] Add names for SPARC ELF flags in LLVM binary utilities (#102843)
This allows us to use and print readable names in LLVM binary utilities.
2024-08-15 23:49:01 +07:00
David Spickett
a07c6d9e34
[llvm][llvm-readobj] Add NT_ARM_FPMR corefile note type (#102594)
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

4035c22ef7.
2024-08-12 09:22:06 +01:00
Jacek Caban
1d77dd50f1
[llvm-readobj][COFF] Dump hybrid objects for ARM64X files. (#102245) 2024-08-09 15:55:28 +02:00
Jacek Caban
94d5398400
[Object][COFF][llvm-readobj] Add support for ARM64X dynamic relocations. (#97229) 2024-08-06 22:06:08 +02:00
Jacek Caban
f949b03661
[llvm-readobj][NFC] Don't use startLine in a middle of a line in ObjDumper. (#102071) 2024-08-06 18:04:23 +02:00
Daniil Kovalev
15d4a84e79
[PAC][ELF][AArch64] Encode signed GOT flag in PAuth core info (#96159)
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 18:24:01 +03:00
Daniil Kovalev
6e45fa95be
[PAC][AArch64] Support init/fini array signing (#96478)
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-08-06 08:02:13 +03:00
Kazu Hirata
75bc20ff89
[llvm] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#97914) 2024-07-07 08:23:41 +09:00