================
@@ -6873,6 +6873,100 @@ When ``#pragma comment(copyright, ...)`` appears in a
C++20 module interface
unit, the copyright string is embedded only in the object file compiled from
that interface unit. Importing TUs do not re-emit the string.
+Preserving Identifying Variables with -mloadtime-comment-vars
+--------------------------------------------------------------
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature; on other
+targets the compiler emits a warning and the flag is not forwarded to
+``-cc1``.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables rather than via a pragma.
+
+Syntax:
+
+.. code-block:: console
+
+ -mloadtime-comment-vars=<var1>[,<var2>,...]
+
+Name matching:
+
+Names are matched against the variable's **mangled IR symbol name** — the
+name as it appears in the object file.
+
+- In C, file-scope static variables are not mangled, so the mangled name is
+ identical to the source identifier (for example, ``sccsid``).
+- In C++, variables are mangled using the Itanium ABI. To find the mangled
+ name, compile with ``clang -S -emit-llvm`` and look for the global in the
+ ``.ll`` output, or run ``nm`` on the object file.
+
+.. code-block:: console
+
+ # Find the mangled name of a C++ variable
+ $ clang++ -S -emit-llvm -o - source.cpp | grep '@.*sccsid'
+ @_ZN1N6sccsidE = ...
+
+ # Or use nm on the object file
+ $ nm source.o | grep sccsid
+ 0000000000000000 b _ZN1N6sccsidE
+
+ # Then pass the mangled name to the flag
+ -mloadtime-comment-vars=_ZN1N6sccsidE
+
+Mangled names are unique, so each entry in the list selects exactly one
+variable. Unrecognised names are silently ignored.
+
+Valid variable types:
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+ character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+Example:
+
+.. code-block:: c
+
+ static char *sccsid = "@(#) MyApp Version 1.0";
+ static char version[] = "@(#) Built 2026-05-24";
+
+ void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+ clang -target powerpc64-ibm-aix \
+ -mloadtime-comment-vars=sccsid,version \
+ -c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and are retained in the
+object file.
----------------
hubert-reinterpretcast wrote:
Strike "survive optimization". It's questionable what counts as optimization
here.
https://github.com/llvm/llvm-project/pull/187986
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits