[clang] a6e6abd - [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect
Qiongsi Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 30 16:21:31 PDT 2023
Author: Qiongsi Wu
Date: 2023-08-30T19:20:17-04:00
New Revision: a6e6abd76cd31011f7685bda2c95ac6468df4f65
URL: https://github.com/llvm/llvm-project/commit/a6e6abd76cd31011f7685bda2c95ac6468df4f65
DIFF: https://github.com/llvm/llvm-project/commit/a6e6abd76cd31011f7685bda2c95ac6468df4f65.diff
LOG: [AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect
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.
Reviewed By: w2yehia
Differential Revision: https://reviews.llvm.org/D159137
Added:
Modified:
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/fprofile-update.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 97217eba9ca01a..6cc92238aa9abf 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -429,11 +429,20 @@ void AIX::addClangTargetOptions(
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.getLastArgNoClaim(options::OPT_fprofile_update_EQ)) {
+ StringRef Val = A->getValue();
+ if (Val == "atomic" || Val == "prefer-atomic")
+ CmdArgs.push_back("-latomic");
+ }
+ }
+
ToolChain::addProfileRTLibs(Args, CmdArgs);
}
diff --git a/clang/test/Driver/fprofile-update.c b/clang/test/Driver/fprofile-update.c
index 2cad883cd81717..3313a2c1cb9af4 100644
--- a/clang/test/Driver/fprofile-update.c
+++ b/clang/test/Driver/fprofile-update.c
@@ -12,3 +12,11 @@
// 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: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate 2>&1 | FileCheck %s --check-prefix=AIX-NOATOMIC
+// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=single 2>&1 | FileCheck %s --check-prefix=AIX-NOATOMIC
+// AIX: "-latomic"
+// AIX-NOATOMIC-NOT: "-latomic"
More information about the cfe-commits
mailing list