[clang] [llvm] [Clang][AIX] Add -mloadtime-comment-vars flag to preserve identifying variables (PR #187986)
Tony Varghese via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 19 03:45:14 PDT 2026
tonykuttai wrote:
The updated implementation uses a two-phase approach in Clang CodeGen, followed by LLVM backend processing:
Frontend (Clang side)
Phase 1: Queue for Emission (`QueueLoadTimeCommentVarEmission`)
- Called before `EmitDeferred()`:
- Scans the translation unit for variables matching the requested names
- Validates each variable (must be char* or char[] with an initializer)
- Moves matching variables from `DeferredDecls → DeferredDeclsToEmit`. This ensures the normal deferred emission machinery handles them, including any globals their initializers reference (e.g., static const char *p = a;)
Phase 2: Annotate `ProcessLoadTimeCommentVars`
- Called after `EmitDeferred()`:
- Looks up the now-defined LLVM globals.
- Attaches `!loadtime_comment` metadata to each.
- Adds them to llvm.compiler.used to prevent optimizer removal.
Backend Processing (`LowerCommentStringPass` changes made in #178184
- Processes all globals with `!loadtime_comment` metadata uniformly (both pragma-generated and flag-specified variables)
- Attaches `!implicit.ref` metadata to every function, referencing these globals.
- Backend emits .ref directives, creating relocations that prevent linker garbage collection
https://github.com/llvm/llvm-project/pull/187986
More information about the cfe-commits
mailing list