[Clang][AIX] Add -mloadtime-comment-vars flag to preserve identifying variables#187986
[Clang][AIX] Add -mloadtime-comment-vars flag to preserve identifying variables#187986tonykuttai wants to merge 2 commits into
Conversation
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions h,c,cpp -- clang/test/CodeGen/loadtime-comment-vars.c clang/include/clang/Basic/CodeGenOptions.h clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.h clang/lib/Driver/ToolChains/Clang.cpp llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp b/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp
index 9a805ff7a..bbcb5a24e 100644
--- a/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp
+++ b/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp
@@ -170,7 +170,7 @@ PreservedAnalyses LowerCommentStringPass::run(Module &M,
auto *StrGV = new GlobalVariable(M, StrInit->getType(),
/*isConstant=*/true,
GlobalValue::WeakODRLinkage, StrInit,
- /*Name=*/ GlobalName);
+ /*Name=*/GlobalName);
StrGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
StrGV->setAlignment(Align(1));
// Backend recognizes this section and emits it to .loadtime_comment.
|
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.LTO/PowerPC/pragma-comment-copyright-thinlto.llLLVM.Other/new-pm-thinlto-prelink-defaults.llLLVM.Other/new-pm-thinlto-prelink-pgo-defaults.llLLVM.Other/new-pm-thinlto-prelink-samplepgo-defaults.llClangClang.CodeGen/PowerPC/pragma-comment-copyright-modules.cppIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
46d4ce4 to
aaf3e32
Compare
a31b969 to
268182a
Compare
in the final object file.
268182a to
38146ce
Compare
…a-comment-copyright-cli
🪟 Windows x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.LTO/PowerPC/pragma-comment-copyright-thinlto.llLLVM.Other/new-pm-thinlto-prelink-defaults.llLLVM.Other/new-pm-thinlto-prelink-pgo-defaults.llLLVM.Other/new-pm-thinlto-prelink-samplepgo-defaults.llClangClang.CodeGen/PowerPC/pragma-comment-copyright-modules.cppIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
This patch introduces a new Clang command-line option,
-mloadtime-comment-vars=, which accepts a comma-separated list of variable names to preserve as loadtime identifying strings in the final binary object file.It ensures that these specific string variables (such as strings that embed 'sccsid' or 'version' info in source variables) are preserved in the object file and not stripped during aggressive garbage collection. This complements the
#pragma comment(copyright, ...)feature by supporting codebases that use this older pattern.This is a stacked pr on top of [Analysis][AIX] Add !implicit.ref globals as ThinLTO summary ref edges to support pragma comment(copyright) LTO interaction which in turn depends on [PowerPC][AIX] Support #pragma comment copyright for AIX.