[clang] [llvm] [Clang][PCH] Use metadata for embedding AST (PR #214135)

Alexis Engelke via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 01:35:29 PDT 2026


================
@@ -9623,6 +9623,35 @@ for an integer access:
 Multiple TBAA operands are allowed to support merging of modules that may use
 different TBAA hierarchies (e.g., when mixing C and C++).
 
+## '`llvm.raw.sections`' Named Metadata
+
+The module-level `!llvm.raw.sections` metadata allows embedding arbitrary
+binary data into named sections of the output object file. A
+`!llvm.raw.sections` metadata node is a list of metadata nodes with the
+following fields:
+
+```
+!0 = !{!"section_name", i32 alignment, i32 section_kind, !"raw data"}
+```
+
+- **section_name**: The name of the output section.
+- **alignment**: The byte alignment of the section data.
+- **section_kind**: An integer value corresponding to the `SectionKind` type
+  declared in the `<include/llvm/MC/SectionKind.h>` header file. This field
+  specifies the nature of the section (e.g. read-only, data, metadata). Each
+  target maps this to format-appropriate section flags.
----------------
aengelke wrote:

I don't like embedding the not-really-fixed enum values in the IR. This means that every change to that enum also requires implementing an auto-upgrade to maintain backwards compatibility. At the very least, this needs a large warning in SectionKind.h and tests to prevent accidental regressions. I'd prefer exploring other approaches, though (maybe something like r|w|x encoded as 4|2|1 (consistent with e.g. PF_* or PROT_\* is sufficient, with 0 being metadata/unmapped?).

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


More information about the cfe-commits mailing list