2269 Commits

Author SHA1 Message Date
Jasmine Tang
e3e4b8481d
[WebAssembly] Add support for shared tags (#188367)
Mostly following the structure of other Shared* constructs

Fixes: #188120
2026-04-05 05:53:20 +00:00
Shivam Gupta
fa136df3e7
[llvm-dwarfdump] Support R_AARCH64_TLS_DTPREL64 in Object/RelocationResolver.cpp (#187649)
In patch https://github.com/llvm/llvm-project/pull/146572 we have plan
to emit R_AARCH64_TLS_DTPREL64. This give us the warning while using
llvm-dwarfdump for the object file which has tls variables -

warning: failed to compute relocation: R_AARCH64_TLS_DTPREL64, Invalid
data was encountered while parsing the file

To fix this warning we have mark the relocation as supported however
final absolute address of a TLS variable is determined at runtime,
resolving to the symbol's section-relative offset in the object file is
mitigate the warning.
2026-03-31 13:14:08 +05:30
Haohai Wen
79ae4c7419
[Object] Normalize BBAddrMap decode address types in ELF (#187962)
This is part of patches to port BBAddrMap to COFF.

DataExtractor::getAddress reads 4 or 8 bytes according to AddressSize and
returns a uint64_t container value. This code path already sets AddressSize
from ELFT::Is64Bits and stores range/function addresses as uint64_t.

Replace temporary uintX_t/unsigned values in this decoder path with uint64_t
and remove the redundant cast from getAddress(). This preserves behavior for
ELF32/ELF64 inputs.

This is a preparatory step for extracting a format-agnostic BBAddrMap decoder.
2026-03-24 09:08:41 +08:00
Jay Foad
99b8be8fb2
[AMDGPU] Use an X-macro to define ELF machine types and names. NFCI. (#185882)
This reduces the number of files that need to be touched when adding a
new CPU type.
2026-03-12 10:13:41 +00:00
Will
e9657a12b2
COFF: Allow hex literals in .def files: BASE/HEAPSIZE/STACKSIZE (#184764)
For a Win32 DLL, a .def file can have a custom executable base:
```
LIBRARY "stub.dll" BASE=0x10000000
```

Currently the parser enforces Base 10, but [Microsoft's
documentation](https://learn.microsoft.com/en-us/cpp/build/reference/rules-for-module-definition-statements?view=msvc-170)
states "Numeric arguments are specified in base 10 or hexadecimal".

This fixes that, and also HEAPSIZE and STACKSIZE (which use the same
function).

There are a few more instances of `getAsInteger` that expect base10 -
for ordinals and the VERSION directive. Since I don't have an
in-the-wild example of a .def file using hexadecimal for these, I am
wary about changing those too.
2026-03-05 18:01:58 +02:00
Jan Svoboda
ed524ba0d4
[llvm] Avoid resolving .incbin during symbol collection (#172920)
With IO sandboxing enabled, Clang requires all FS accesses happen
through the one "true" VFS instance. That instance is currently not
being propagated into the assembly parser, and doing so would be super
involved. This triggers sandbox violations whenever an `.incbin`
directive is encountered, since the parser needs the VFS to open the
file.

However, it seems that `asm()` directives are only parsed to get the
symbols of an LLVM module, which cannot be affected by `.incbin`
directives. This PR adds an option to the asm parser to avoid resolving
`.incbin` directives when collecting module symbols, avoiding the
sandbox violation.
2026-03-02 11:59:17 -08:00
Stanislav Mekhanoshin
33fd75f55d
[AMDGPU] Add gfx12-5-generic subtarget (#183381)
This is functionally equivalent to gfx1250.
2026-02-25 13:34:48 -08:00
Sy Brand
f94ad564f5
[WebAssembly] Take symbol flags for exports from the dylink section for shared objects (#183079)
Currently, WASM symbols taken from the export section of shared objects
lose their flags. This can result in link failures. For example, if a
TLS symbol is exported from a shared object, relocation fails because
`wasm-ld` thinks that the symbol is not flagged as a TLS symbol.

This PR populates symbol flags for symbols in the export section from
the flags stored in the dylink0 section.

The export info section was also not serialized by the WASM emitter for
YAML, which this PR fixes
2026-02-25 11:16:28 -08:00
Yury Plyakhin
81f445b7df
[clang-sycl-linker][offload] Set TheImageKind based on IsAOTCompileNeeded flag (#180269)
Previously, TheImageKind was set to IMG_None and relied on a runtime
heuristic to determine the correct image type. This commit sets it
explicitly to IMG_Object for AOT-compiled images and IMG_SPIRV for
SPIR-V images based on the IsAOTCompileNeeded flag.

Also it adds test for this change, which required minor changes in
OffloadBinary and OffloadDump.
2026-02-11 10:21:22 -08:00
Sam Clegg
11c2613342
[WebAssembly] Add initial support for compact imports proposal (#176617)
This change adds initial support to libObject for reading compact
imports and support for writing compact imports in the linker.

There is minimal testing here since to tools like lllvm-readobj, and
obj2yaml don't currently report compact imports any differently.

See https://github.com/WebAssembly/compact-import-section
2026-02-10 10:57:45 -08:00
Mirko Brkušanin
20b5849e17
[AMDGPU] Define new target gfx1170 (#180185) 2026-02-06 14:38:50 +01:00
Yury Plyakhin
c43d1c5292
[Object][Offload] Fix OffloadBinary::create to explicitly move return value (#180011)
On older compilers (GCC 7), implicit move on return is not guaranteed,
causing the compiler to attempt copying the SmallVector of unique_ptr's,
which fails because unique_ptr has a deleted copy constructor.
Added explicit std::move() on both return paths to ensure move semantics
are used instead of copy, fixing compilation by GCC 7.
2026-02-05 13:30:09 -08:00
Yury Plyakhin
4d27530c69
[Offloading] Offload Binary Format V2: Support Multiple Entries (#169425)
This PR updates the OffloadBinary format from version 1 to version 2,
enabling support for multiple offloading entries in a single binary.
This allows combining multiple device images into a single binary with
common global metadata while maintaining backwards compatibility with
version 1 binaries.

# Key Changes
## Binary Format Enhancements
  **Version 2 Format Changes:**
  - Changed from single-entry to multi-entry design
  - Updated `Header` structure:
    - Renamed `EntryOffset` → `EntriesOffset` (offset to entries array)
    - Renamed `EntrySize` → `EntriesCount` (number of entries)
- Added `StringEntry::ValueSize` field to support explicit string value
sizes (enables non-null-terminated strings)
- Introduced `OffloadEntryFlags` enum with `OIF_Metadata` flag for
metadata-only entries (entries without binary images)

  **API Changes:**
- `OffloadBinary::create()` now returns
`Expected<SmallVector<std::unique_ptr<OffloadBinary>>>` instead of
single binary
- Added optional `Index` parameter to extract specific entry:
`create(Buffer, std::optional<uint64_t> Index)`
- `OffloadBinary::write()` now accepts `ArrayRef<OffloadingImage>`
instead of single image
  - Added `OffloadBinary::extractHeader()` for header extraction

  **Memory Management:**
- Implemented `SharedMemoryBuffer` class to enable memory sharing across
multiple `OffloadBinary` instances from the same file
- Multiple entries from a single serialized binary share the underlying
buffer

## Testing
  **Unit Tests (`unittests/Object/OffloadingTest.cpp`):**
- `checkMultiEntryBinaryExtraction`: Tests extracting all entries from a
multi-entry binary
- `checkIndexBasedExtraction`: Tests extracting specific entries by
index, including out-of-bounds validation
  - `checkEdgeCases`: Tests edge cases including:
    - Empty string metadata
    - Empty image data
    - Large string values (4KB)

  **Other Tests:**
- Updated `test/ObjectYAML/Offload/multiple_members.yaml` to include
metadata-only entry

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2026-02-05 07:46:57 -08:00
Sam Clegg
d6ca3d085e
[WebAssembly] Dump more info when printing symbols. NFC (#178328) 2026-01-28 12:17:13 -08:00
serge-sans-paille
cc04746802
[perf] Replace copy-assign by move-assign in llvm/lib/Object(YAML)/* (#178177) 2026-01-27 16:28:29 +00:00
Francesco Petrogalli
460c9b2db1
[RISC-V][Mach-O] Add assembler support for Mach-O relocations. (#177446)
This patch adds comprehensive assembler (MC layer) support for the
Mach-O object file format on RISC-V targets, enabling assembly and
disassembly of RISC-V code targeting Apple platforms.

Key changes:

- Define RISC-V-specific Mach-O relocation types in BinaryFormat/MachO.h
- Implement RISCVMachObjectWriter with full relocation handling for:
  - PCREL_HI/LO pairs for PC-relative addressing
  - GOT relocations for external symbols
  - Branch relocations (CALL, unconditional/conditional branches)
  - Data section relocations

Test files include llvm-otool dumps to verify the generated relocations.

This code is based on code originally written by Tim Northover.
2026-01-26 14:06:30 -08:00
Jameson Nash
d10b2b566a
[NFCI] replace getValueType with new getGlobalSize query (#177186)
Returns uint64_t to simplify callers. The goal is eventually replace
getValueType with this query, which should return the known minimum
reference-able size, as provided (instead of a Type) during create.
Additionally the common isSized query would be replaced with an
isExactKnownSize query to test if that size is an exact definition.
2026-01-22 13:55:53 -05:00
Mariusz Sikora
6de6f7b46b
[AMDGPU] Define gfx1310 target with ELF number 0x50 (#177355)
For now this is identical to gfx1250.

---------

Co-authored-by: Jay Foad <jay.foad@amd.com>
2026-01-22 17:08:38 +01:00
Daniel Thornburgh
567fe2bbca
[NFC][LTO] Move isPreservedName out of IRSymtab into LTO's Symbol as isLibcall (#177046)
This resolves the FIXME in IRSymtab and cleans up the semantics of the
IRSymtab. The list of preserved symbols really shouldn't be seen as a
property of the IR symbol table, since it's an LTO-specific concern, and
it's very tenuous to claim that this information is actually present in
the bitcode file to be exposed through its symbol table.

Instead, this PR moves this logic into LTO's view of the symbol, which
allows consumers to determine preserved-ness themselves. This was broken
out of #164916; this prevents that PR from introducing a circular
dependency, but it still seems like an independently good idea by virtue
of the above.
2026-01-21 11:32:33 -08:00
Joseph Huber
8a963dd58b
[Binary] Check size of string entries when creating Offload Binaries (#177029)
Summary:
Verify this just in case the input lists more strings than actually
exist.
2026-01-21 09:02:16 -06:00
Nikita Popov
7abe5b73b5
[llvm-readobj][offload] Fix llvm-readobj --all on MachO (#175912)
Currently running llvm-readobj --all on any MachO object asserts,
because it implies --offload, and the --offload extraction includes an
assert on the object format. Instead, we should be silently ignoring.

This regressed in https://github.com/llvm/llvm-project/pull/143342.
2026-01-15 11:55:51 +01:00
Rahul Joshi
d20f617ab8
[NFCI][LLVM] Remove raw_string_ostream::flush calls (#164086)
Remove calls to `flush()` on `raw_string_ostream` objects as they are not needed.
2026-01-13 08:44:48 -08:00
Francesco Petrogalli
75d025124a
[RISCV] Add basic Mach-O triple support. (#141682)
Based on a patch written by Tim Northover (https://github.com/TNorthover).
2026-01-05 23:18:48 +00:00
John Holdsworth
36bed4d0cd
[lld][MachO] Follow-up to use madvise() for threaded file page-in. (#157917)
Further to
https://github.com/llvm/llvm-project/pull/147134#discussion_r2337246489,
switch to use the madvise() api to page in mmap'd files and

1) All new code compiled in #if LLVM_ENABLE_THREADS is set so it can be
seen where the changes were from this PR.
2) The new PR moves to use madvise() instead of the ad-hoc page
referencing code I wrote which should avoid SIGSEGVs if the buffer is
deallocated.
3) A new property SerialBackgroundQueue().stopAllWork to be used to stop
background workers when there is no further call for them. Usually the
background "page-in" threads have completed first but it seems with this
troublesome test this is not always the case and buffers stored in the
static input file cache are being deallocated while being referenced.

---------

Co-authored-by: James Henderson <James.Henderson@sony.com>
2025-11-26 15:14:15 -08:00
Kazu Hirata
30e5f76d73
[llvm] Construct iterator_range with the conversion constructor (NFC) (#168674)
This patch simplifies iterator_range construction with the conversion
constructor.
2025-11-19 07:29:49 -08:00
Owen Anderson
cce852ff03
[Object] Add getRISCVVendorRelocationTypeName to render RISCV vendor-specific relocations to strings. (#168293)
This will be used in places like LLD to render them for error messages.
2025-11-16 16:21:46 -08:00
Kazu Hirata
7a8237bbb6
[llvm] Use llvm::copy (NFC) (#168182)
Identified with llvm-use-ranges.
2025-11-15 08:06:00 -08:00
quic-areg
682c8e22e6
[Hexagon] Add missing build attributes (#166992)
Attributes for v79 and 81 were recorded but ignored.
2025-11-07 15:09:25 -06:00
Greg Clayton
6601c384d3
Fix getting section info in large mach-o files. (#165940)
Mach-o has 32 bit file offsets in the MachO::section_64 structs. dSYM
files can contain sections whose start offset exceeds UINT32_MAX, which
means the MachO::section_64.offset will get truncated. We can calculate
when this happens and properly adjust the section offset to be 64 bit
safe. This means tools can get the correct section contents for large
dSYM files and allows tools that parse DWARF, like llvm-gsymutil, to be
able to load and convert these files correctly.
2025-11-04 09:36:54 -08:00
Jakub Kuderski
4c21d0cb14
[ADT] Prepare to deprecate variadic StringSwitch::Cases. NFC. (#166020)
Update all uses of variadic `.Cases` to use the initializer list
overload instead. I plan to mark variadic `.Cases` as deprecated in a
followup PR.

For more context, see https://github.com/llvm/llvm-project/pull/163117.
2025-11-02 00:12:33 +00:00
Rahman Lavaee
e9368a056d
[SHT_LLVM_BB_ADDR] Implement ELF and YAML support for Propeller CFG data in PGO analysis map. (#164914)
This PR implements the ELF support for PostLink CFG in PGO analysis map
as discussed in
[RFC](https://discourse.llvm.org/t/rfc-extending-the-pgo-analysis-map-with-propeller-cfg-frequencies/88617/2).

A later PR will implement the Codegen Support.
2025-10-30 13:12:06 -07:00
Prabhu Rajasekaran
b7c7083c1f
[llvm] Update call graph ELF section type. (#164461)
Make call graph section to have a dedicated type instead of the generic
progbits type.
2025-10-22 15:08:36 -07:00
wdx727
5eeae08f7e
Adding Matching and Inference Functionality to Propeller (#160706)
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-10-14 10:34:14 -07:00
小钟
e6358ab75c
Fix typo: IsGlobaLinkage -> IsGlobalLinkage in XCOFF (#161960)
Corrects the spelling of 'IsGlobaLinkage' to 'IsGlobalLinkage' in
XCOFF-related code, comments, and tests across the codebase.
2025-10-12 12:03:40 -07:00
小钟
10021c737a
Fix typo in comment: 'unit64_t' to 'uint64_t' (#162869)
Corrects a typo in comments within XCOFFObjectFile.cpp, changing
'unit64_t' to the correct type 'uint64_t' for clarity.
2025-10-10 17:50:33 +01:00
David Salinas
efda523188
Fix compress/decompress in LLVM Offloading API (#150064)
Co-authored-by: dsalinas_amdeng <david.salinas@amd.com>
2025-10-06 16:34:02 -04:00
Lang Hames
c06aa2e813 Revert "Reapply [MachO] Move getArchTriple impl... with fixes. (#161949)"
This reverts commit 54012102c4a8e8bba9b3b27291dab126e3521544 while I further
investigate bot failures. Apparently adding a dependence on BinaryFormat to
Object was insufficient to fix the original linker issues.
2025-10-04 19:15:08 +10:00
Lang Hames
54012102c4
Reapply [MachO] Move getArchTriple implementation..." with fixes. (#161949)
This reapplies cd32b9b6c3b, which was reverted in 25e02a43fe6 due to bot
failures.

The failures all appear to be link errors due to the Object library not
depending on BinaryFormat. This commit adds the missing dependence.
2025-10-04 18:46:35 +10:00
Lang Hames
25e02a43fe Revert "[MachO] Move getArchTriple implementation into BinaryFormat. (#161468)"
Reverts commit cd32b9b6c3b while I investigate some bot failures, e.g.
https://lab.llvm.org/buildbot/#/builders/10/builds/14784.
2025-10-04 16:59:55 +10:00
Lang Hames
cd32b9b6c3
[MachO] Move getArchTriple implementation into BinaryFormat. (#161468)
There's nothing ObjectFile specific about getArchTriple, so move it into
the BinaryFormat library so that clients can use it without taking a
dependence on libObject.

MachOObjectFile::getArchTriple is updated to call through to the moved
implementation.
2025-10-04 16:33:17 +10:00
Ruoyu Qiu
5cd3db3bed
[llvm][ELF]Add Shdr check for getBuildID (#126537)
Add Section Header check for getBuildID, fix crash with invalid Program
Header.

Fixes: #126418

---------

Signed-off-by: Ruoyu Qiu <cabbaken@outlook.com>
Signed-off-by: Ruoyu Qiu <qiuruoyu@xiaomi.com>
Co-authored-by: Ruoyu Qiu <qiuruoyu@xiaomi.com>
Co-authored-by: James Henderson <James.Henderson@sony.com>
2025-10-03 10:02:36 +01:00
David Salinas
bdea159093
Revert "Revert "Fix memory leak in Offloading API" (#161465)" (#161573)
This reverts commit d392563433316e310edacf35a40fb2f9aa477acc.
2025-10-01 20:47:47 -04:00
ronlieb
d392563433
Revert "Fix memory leak in Offloading API" (#161465)
Reverts llvm/llvm-project#161430
2025-09-30 21:16:08 -04:00
David Salinas
b80b48d3e8
Fix memory leak in Offloading API (#161430)
Fix or the failing Sanitizer buildbots from PR:
https://github.com/llvm/llvm-project/pull/143342
2025-09-30 18:23:11 -04:00
David Salinas
07f8f088b4
Add --offoading option to llvm-readobj (#143342)
Utilize new extensions to LLVM Offloading API to
handle offloading fatbin Bundles.

The tool will output a list of available offload bundles
using URI syntax.

---------

Co-authored-by: dsalinas_amdeng <david.salinas@amd.com>
2025-09-29 17:16:29 -04:00
Jacek Caban
48a6f2f85c
[Object][Archive] Recompute headers and symbol map when switching from COFF to GNU64 (#160606)
COFF format has no 64-bit version, so we use GNU64 instead. Since this
changes the headers, we need to recalculate everything.

Fixes #160112.
2025-09-28 20:17:01 +02:00
joaosaffran
4ff986af63
[DirectX] Updating DXContainer logic to read version 1.2 of static samplers (#160184)
This PR is updating `Object/DXContainer.h` so that we can read data from
root signature version 1.2, which adds flags into static samplers.
2025-09-26 17:07:45 +00:00
Nico Weber
f847c2a0fa
[Object] Add a missing space to a diagnostic (#159826)
Follow-up to https://reviews.llvm.org/D46527
2025-09-20 13:49:40 -04:00
Joseph Huber
0fa3061c4e
Revert "[ELF][LLDB] Add an nvsass triple (#159459)" (#159879)
Summary:
This patch has broken the `libc` build bot. I could work around that but
the changes seem unnecessary.

This reverts commit 9ba844eb3a21d461c3adc7add7691a076c6992fc.
2025-09-19 20:13:48 -05:00
Walter Erquinigo
9ba844eb3a
[ELF][LLDB] Add an nvsass triple (#159459)
When handling CUDA ELF files via objdump or LLDB, the ELF parser in LLVM
needs to distinguish if an ELF file is sass or not, which requires a
triple for sass to exist in llvm. This patch includes all the necessary
changes for LLDB and objdump to correctly identify these files with the
correct triple.
2025-09-19 14:14:20 -04:00