tonykuttai wrote:

Updated the design with the latest changes. 

- Frontend (Clang): Parses `#pragma comment (copyright, "string")` for AIX 
targets and emits :
    - Emit weak_odr hidden hash-named global variables (e.g., 
`__loadtime_comment_str_<hash>`)
    - Place strings in `__loadtime_comment` section and mark with 
`!loadtime_comment` metadata
    - Add to `llvm.compiler.used` to prevent early elimination
- Middle-end: 
    - `LowerCommentStringPass` Attaches `!implicit.ref` metadata from all 
defined functions to the copyright string globals (that have 
`!loadtime_comment` metadata). 
    - `ModuleSummaryAnalysis` (ThinLTO support) : `findImplicitRefEdges()` 
collects globals referenced via `!implicit.ref` metadata and adds them as 
explicit reference edges in the module summary. This ensures ThinLTO import 
analysis treats copyright strings as live when their referencing functions are 
live.
    - `FunctionImport` (ThinLTO support):`protectImplicitRefGlobals()` finds 
imported functions with `!implicit.ref` metadata pointing to 
`available_externally` globals and adds those globals to `llvm.compiler.used` 
to prevent DCE.
    - `SCCPSolver` (optimization support):`propagateImplicitRefFromCall()` 
preserves `!implicit.ref` metadata when calls are optimized away. When a call 
is removed, propagates the callee's !implicit.ref metadata to the caller and 
ensures copyright strings remain reachable even after aggressive 
inlining/constant propagation.
- Backend: recognizes `!implicit.ref` metadata on functions and emits `.ref` 
directives creating relocations from functions to copyright strings. Linker 
keeps copyright strings as long as any referencing function is kept.

Note:

- Emitting weak_odr, hidden, hash-named strings helps identical strings from 
different TUs to be merged during ThinLTO import.
- Copyright strings are placed in a dedicated `__loadtime_comment` section. In 
full LTO builds, multiple strings may be grouped into a single csect, 
preventing individual linker GC. However, this groups copyright strings "out of 
the way" from other data, which is beneficial for memory layout. ThinLTO is not 
affected by this grouping.

https://github.com/llvm/llvm-project/pull/178184
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to