Skip to content

Commit a6e6abd

Browse files
author
Qiongsi Wu
committed
[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
1 parent 9f72e3f commit a6e6abd

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,20 @@ void AIX::addClangTargetOptions(
429429

430430
void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
431431
llvm::opt::ArgStringList &CmdArgs) const {
432-
// Add linker option -u__llvm_profile_runtime to cause runtime
433-
// initialization to occur.
434-
if (needsProfileRT(Args))
432+
if (needsProfileRT(Args)) {
433+
// Add linker option -u__llvm_profile_runtime to cause runtime
434+
// initialization to occur.
435435
CmdArgs.push_back(Args.MakeArgString(
436436
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
437+
438+
if (const auto *A =
439+
Args.getLastArgNoClaim(options::OPT_fprofile_update_EQ)) {
440+
StringRef Val = A->getValue();
441+
if (Val == "atomic" || Val == "prefer-atomic")
442+
CmdArgs.push_back("-latomic");
443+
}
444+
}
445+
437446
ToolChain::addProfileRTLibs(Args, CmdArgs);
438447
}
439448

clang/test/Driver/fprofile-update.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@
1212
// RUN: not %clang %s -c -fprofile-update=unknown 2>&1 | FileCheck %s --check-prefix=ERROR
1313

1414
// ERROR: error: unsupported argument 'unknown' to option '-fprofile-update='
15+
16+
// AIX specific tests
17+
// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=atomic 2>&1 | FileCheck %s --check-prefix=AIX
18+
// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=prefer-atomic 2>&1 | FileCheck %s --check-prefix=AIX
19+
// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate 2>&1 | FileCheck %s --check-prefix=AIX-NOATOMIC
20+
// RUN: %clang -### %s --target=powerpc-unknown-aix -fprofile-generate -fprofile-update=single 2>&1 | FileCheck %s --check-prefix=AIX-NOATOMIC
21+
// AIX: "-latomic"
22+
// AIX-NOATOMIC-NOT: "-latomic"

0 commit comments

Comments
 (0)