[PATCH] D159137: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect
Qiongsi Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 29 13:48:36 PDT 2023
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: w2yehia, MaskRay.
qiongsiwu1 added a project: clang.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added a subscriber: cfe-commits.
https://reviews.llvm.org/D157280 enabled `-fprofile-update` for `-fprofile-generate`, but omitted adding `-latomic` to the linker command on AIX. This omission causes linking to fail due to an undefined symbol. This patch fixes the link error.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159137
Files:
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/fprofile-update.c
Index: clang/test/Driver/fprofile-update.c
===================================================================
--- clang/test/Driver/fprofile-update.c
+++ clang/test/Driver/fprofile-update.c
@@ -12,3 +12,8 @@
// RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s --check-prefix=ERROR
// ERROR: error: unsupported argument 'unknown' to option '-fprofile-update='
+
+// AIX specific tests
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate -fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// RUN: %if system-aix %{ %clang -### %s -fprofile-generate -fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX %}
+// AIX: "-latomic"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -429,11 +429,19 @@
void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const {
- // Add linker option -u__llvm_profile_runtime to cause runtime
- // initialization to occur.
- if (needsProfileRT(Args))
+ if (needsProfileRT(Args)) {
+ // Add linker option -u__llvm_profile_runtime to cause runtime
+ // initialization to occur.
CmdArgs.push_back(Args.MakeArgString(
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
+
+ if (const auto *A = Args.getLastArg(options::OPT_fprofile_update_EQ)) {
+ StringRef Val = A->getValue();
+ if (Val == "atomic" || Val == "prefer-atomic")
+ CmdArgs.push_back("-latomic");
+ }
+ }
+
ToolChain::addProfileRTLibs(Args, CmdArgs);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159137.554480.patch
Type: text/x-patch
Size: 1676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230829/12d696b5/attachment-0001.bin>
More information about the cfe-commits
mailing list