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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to