Files
a64928f267 [PowerPC][AIX] Support #pragma comment copyright for AIX (#178184)
This change supports **pragma comment copyright**.
Signature: `#pragma comment (copyright, "token_sequence")`

- The token_sequence is included in the generated executable and loaded
into memory when the program is run.
- copyright `comment` directive can appear only once in a translation
unit.

Implementation :

- 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 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.
- This change builds on top of [XCOFF associated
metadata](https://github.com/llvm/llvm-project/pull/159096)

---------

Co-authored-by: Tony Varghese <tony.varghese@ibm.com>
Co-authored-by: Hubert Tong <hubert.reinterpretcast@gmail.com>
2026-06-19 06:13:33 +05:30
..