diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -68,6 +68,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/thread.h" #include "llvm/Target/TargetMachine.h" #include "llvm/TargetParser/Triple.h" #include "llvm/Transforms/Utils/ModuleUtils.h" @@ -2740,14 +2741,18 @@ // and add a format indicator as a part of function name in case we // will support more than one format. FormatIndicatorAndUniqueModId = "clang_" + UniqueModuleId.substr(1); - else - // Use the Pid and current time as the unique module id when we cannot - // generate one based on a module's strong external symbols. - // FIXME: Adjust the comment accordingly after we use source file full - // path instead. + else { + // Use threadId, Pid, and current time as the unique module id when we + // cannot generate one based on a module's strong external symbols. + auto CurTime = + std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()) + .count(); FormatIndicatorAndUniqueModId = - "clangPidTime_" + llvm::itostr(sys::Process::getProcessId()) + - "_" + llvm::itostr(time(nullptr)); + "clangPidTidTime_" + llvm::itostr(sys::Process::getProcessId()) + + "_" + llvm::itostr(llvm::this_thread::get_id()) + "_" + + llvm::itostr(CurTime); + } } emitSpecialLLVMGlobal(&G); diff --git a/llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll b/llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll --- a/llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll +++ b/llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll @@ -7,18 +7,16 @@ ret void } -; FIXME: Adjust the comment after we use source file full path to generate unique -; module id instead. -; Use the Pid and timestamp to generate a unique module id when strong external +; Use the Pid, threadId, and timestamp to generate a unique module id when strong external ; symbols are not available in current module. The module id generated in this ; way is not reproducible. A function name sample would be: -; __sinit80000000_clangPidTime_119189_1597348415_0 +; __sinit80000000_clangPidTidTime_56689326_1_57027228417827568_0 ; CHECK: .lglobl foo[DS] ; CHECK: .lglobl .foo ; CHECK: .csect foo[DS] -; CHECK-NEXT: __sinit80000000_clangPidTime_[[PID:[0-9]+]]_[[TIMESTAMP:[0-9]+]]_0: +; CHECK-NEXT: __sinit80000000_clangPidTidTime_[[PID:[0-9]+]]_[[TID:[0-9]+]]_[[TIMESTAMP:[0-9]+]]_0: ; CHECK: .foo: -; CHECK-NEXT: .__sinit80000000_clangPidTime_[[PID]]_[[TIMESTAMP]]_0: -; CHECK: .globl __sinit80000000_clangPidTime_[[PID]]_[[TIMESTAMP]]_0 -; CHECK: .globl .__sinit80000000_clangPidTime_[[PID]]_[[TIMESTAMP]]_0 +; CHECK-NEXT: .__sinit80000000_clangPidTidTime_[[PID]]_[[TID]]_[[TIMESTAMP]]_0: +; CHECK: .globl __sinit80000000_clangPidTidTime_[[PID]]_[[TID]]_[[TIMESTAMP]]_0 +; CHECK: .globl .__sinit80000000_clangPidTidTime_[[PID]]_[[TID]]_[[TIMESTAMP]]_0