Index: clang/lib/Driver/ToolChains/AIX.h =================================================================== --- clang/lib/Driver/ToolChains/AIX.h +++ clang/lib/Driver/ToolChains/AIX.h @@ -82,6 +82,9 @@ void AddMASSLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; + void addProfileRTLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; + CXXStdlibType GetDefaultCXXStdlibType() const override; RuntimeLibType GetDefaultRuntimeLibType() const override; Index: clang/lib/Driver/ToolChains/AIX.cpp =================================================================== --- clang/lib/Driver/ToolChains/AIX.cpp +++ clang/lib/Driver/ToolChains/AIX.cpp @@ -417,6 +417,17 @@ CmdArgs.push_back(Args.MakeArgString(XLOptPath)); } +void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + // Add linker option -u__llvm_register_runtime to cause runtime + // initialization module to be linked in. + // On AIX, we need to keep the exact global who's constructor does the + // initialization in order for linking with -bcdtors:csect to work. + if (needsProfileRT(Args)) + CmdArgs.push_back(Args.MakeArgString(Twine("-u__llvm_register_runtime"))); + ToolChain::addProfileRTLibs(Args, CmdArgs); +} + ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const { return ToolChain::CST_Libcxx; } Index: compiler-rt/lib/profile/InstrProfilingRuntime.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingRuntime.cpp +++ compiler-rt/lib/profile/InstrProfilingRuntime.cpp @@ -5,7 +5,6 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// - extern "C" { #include "InstrProfiling.h" @@ -14,8 +13,6 @@ COMPILER_RT_VISIBILITY int INSTR_PROF_PROFILE_RUNTIME_VAR; } -namespace { - class RegisterRuntime { public: RegisterRuntime() { @@ -23,6 +20,9 @@ } }; -RegisterRuntime Registration; - -} +#ifdef _AIX +COMPILER_RT_VISIBILITY +#else +static +#endif +RegisterRuntime __llvm_register_runtime; Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -1192,7 +1192,7 @@ bool InstrProfiling::emitRuntimeHook() { // We expect the linker to be invoked with -u flag for Linux // in which case there is no need to emit the external variable. - if (TT.isOSLinux()) + if (TT.isOSLinux() || TT.isOSAIX()) return false; // If the module's provided its own runtime, we don't need to do anything.