[llvm] [IR] Add llvm.raw.sections named metadata (PR #226954)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 03:50:54 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Steffen Larsen (steffenlarsen)

<details>
<summary>Changes</summary>

Add a module-level `!llvm.raw.sections` named metadata node for embedding arbitrary binary data into named sections of the output object file. Each entry is a tuple of {section name, alignment, flags, data}. The flags are a target-independent bitmask (Alloc, Write, Exec, Exclude) that each object file format maps onto its own section flags.

The AsmPrinter lowers the entries directly at the MC layer through a new TargetLoweringObjectFile::getNamedSection hook, implemented for ELF, Mach-O, COFF and Wasm. Formats without the hook skip the entries. Unlike a GlobalVariable, the data is not subject to the size limits of the target's address spaces.

The verifier checks the shape of each entry and rejects invalid flag combinations.

Splitting #<!-- -->214135, this is the first half.

Assisted-by: Claude Opus 4.6

---
Full diff: https://github.com/llvm/llvm-project/pull/226954.diff


14 Files Affected:

- (modified) llvm/docs/LangRef.md (+56) 
- (modified) llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (+8) 
- (modified) llvm/include/llvm/IR/Module.h (+24) 
- (modified) llvm/include/llvm/Target/TargetLoweringObjectFile.h (+7) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+40) 
- (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+27) 
- (modified) llvm/lib/IR/Module.cpp (+21) 
- (modified) llvm/lib/IR/Verifier.cpp (+38) 
- (added) llvm/test/CodeGen/WebAssembly/raw-sections-wasm.ll (+7) 
- (added) llvm/test/CodeGen/X86/raw-sections-coff.ll (+12) 
- (added) llvm/test/CodeGen/X86/raw-sections-elf.ll (+7) 
- (added) llvm/test/CodeGen/X86/raw-sections-macho.ll (+9) 
- (added) llvm/test/Verifier/raw-sections-flags.ll (+31) 
- (added) llvm/test/Verifier/raw-sections.ll (+9) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


https://github.com/llvm/llvm-project/pull/226954


More information about the llvm-commits mailing list