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 @@ -64,6 +64,7 @@ #include "llvm/Support/CodeGen.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Process.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" @@ -1863,13 +1864,16 @@ // names. if (GlobalUniqueModuleId.empty()) { GlobalUniqueModuleId = getUniqueModuleId(&M); - // FIXME: We need to figure out what to hash on or encode into the - // unique ID we need. - if (GlobalUniqueModuleId.compare("") == 0) - llvm::report_fatal_error( - "cannot produce a unique identifier for this module based on" - " strong external symbols"); - GlobalUniqueModuleId = GlobalUniqueModuleId.substr(1); + if (GlobalUniqueModuleId.compare("") != 0) + // TODO: Use source file full path to generate the unique id. + GlobalUniqueModuleId = GlobalUniqueModuleId.substr(1); + else + // Use PID and current time as 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. + GlobalUniqueModuleId = llvm::itostr(sys::Process::getProcessId()) + + "_" + llvm::itostr(time(nullptr)); } 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 @@ -1,5 +1,5 @@ -; RUN: not --crash llc -mtriple powerpc-ibm-aix-xcoff -o - %s 2>&1 | FileCheck %s -; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff -o - %s 2>&1 | FileCheck %s +; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s +; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }] @@ -7,4 +7,18 @@ ret void } -; CHECK: LLVM ERROR: cannot produce a unique identifier for this module based on strong external symbols +; FIXME: Adjust the comment after we use source file full path to generate unique +; module id instead. +; Use PID 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_clang_119189_1597348415_0 + +; CHECK: .lglobl foo[DS] +; CHECK: .lglobl .foo +; CHECK: .csect foo[DS] +; CHECK: __sinit80000000_clang_[[PID:[0-9]+]]_[[TIMESTAMP:[0-9]+]]_0: +; CHECK: .foo: +; CHECK: .__sinit80000000_clang_[[PID]]_[[TIMESTAMP]]_0: +; CHECK: .globl __sinit80000000_clang_[[PID]]_[[TIMESTAMP]]_0 +; CHECK: .globl .__sinit80000000_clang_[[PID]]_[[TIMESTAMP]]_0