99// CopyrightMetadataPass pass lowers module-level copyright metadata emitted by
1010// Clang:
1111//
12- // !loadtime.copyright.comment = !{!"Copyright ..."}
13- //
14- // into concrete, translation-unit–local globals to ensure that copyright
15- // strings:
16- // - survive all optimization and LTO pipelines,
17- // - are not removed by linker garbage collection, and
18- // - remain visible in the final XCOFF binary.
12+ // !comment_string.loadtime = !{!"Copyright ..."}
1913//
14+ // into concrete, translation-unit–local globals.
15+ // This Pass is enabled only for AIX.
2016// For each module (translation unit), the pass performs the following:
2117//
2218// 1. Creates a null-terminated, internal constant string global
3329// discarding it (as long as the referencing symbol is kept).
3430//
3531// Input IR:
36- // !loadtime.copyright.comment = !{!"Copyright"}
32+ // !comment_string.loadtime = !{!"Copyright"}
3733// Output IR:
3834// @__loadtime_copyright_str = internal constant [N x i8] c"Copyright\00",
3935// section "__copyright_comment"
4238// define i32 @func() !implicit.ref !5 { ... }
4339// !5 = !{ptr @__loadtime_copyright_str}
4440//
45- // The copyright string is placed in the "__copyright_comment" section (mapped to
46- // an XCOFF csect with [RO] storage class), making it easily identifiable in
47- // object files and executables. The R_REF relocation prevents the linker
48- // from discarding this section during garbage collection. Copyright string (if
49- // kept by the linker) is expected to be loaded at run time.
5041// ===----------------------------------------------------------------------===//
5142
5243#include " llvm/Transforms/Utils/CopyrightMetadataPass.h"
@@ -90,9 +81,9 @@ PreservedAnalyses CopyrightMetadataPass::run(Module &M,
9081
9182 LLVMContext &Ctx = M.getContext ();
9283
93- // Single-metadata: !loadtime.copyright.comment = !{!0}
84+ // Single-metadata: !comment_string.loadtime = !{!0}
9485 // Each operand node is expected to have one MDString operand.
95- NamedMDNode *MD = M.getNamedMetadata (" loadtime.copyright.comment " );
86+ NamedMDNode *MD = M.getNamedMetadata (" comment_string.loadtime " );
9687 if (!MD || MD->getNumOperands () == 0 )
9788 return PreservedAnalyses::all ();
9889
@@ -113,7 +104,7 @@ PreservedAnalyses CopyrightMetadataPass::run(Module &M,
113104 // 1. Create a single NULL-terminated string global
114105 Constant *StrInit = ConstantDataArray::getString (Ctx, Text, /* AddNull=*/ true );
115106
116- // Internal, constant, TU-local — avoids duplicate symbol issues across TUs.
107+ // Internal, constant, TU-local-- avoids duplicate symbol issues across TUs.
117108 auto *StrGV = new GlobalVariable (M, StrInit->getType (),
118109 /* isConstant=*/ true ,
119110 GlobalValue::InternalLinkage, StrInit,
@@ -122,9 +113,7 @@ PreservedAnalyses CopyrightMetadataPass::run(Module &M,
122113 StrGV->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
123114 StrGV->setAlignment (Align (1 ));
124115 // Place in the "__copyright_comment" section.
125- // Backend maps this to an appropriate XCOFF csect (typically [RO])
126- // The section will appear in assembly as:
127- // .csect __copyright_comment[RO],2
116+ // The GV is constant, so we expect a read-only section.
128117 StrGV->setSection (" __copyright_comment" );
129118
130119 // 2. Add the string to llvm.used to prevent LLVM optimization/LTO passes from
@@ -138,7 +127,6 @@ PreservedAnalyses CopyrightMetadataPass::run(Module &M,
138127 MDNode *ImplicitRefMD = MDNode::get (Ctx, Ops);
139128
140129 // Lambda to attach implicit.ref metadata to a function.
141- // The backend will translate this into .ref assembly directives.
142130 auto AddImplicitRef = [&](Function &F) {
143131 if (F.isDeclaration ())
144132 return ;
0 commit comments