[PATCH] D85527: [AIX] Generate unique module id based on PID and timestamp

Xiangling Liao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 08:03:45 PDT 2020


Xiangling_L created this revision.
Xiangling_L added reviewers: jasonliu, hubert.reinterpretcast, daltenty, yusra.syeda.
Herald added subscribers: llvm-commits, kbarton, hiraditya, nemanjai.
Herald added a project: LLVM.
Xiangling_L requested review of this revision.
Herald added a subscriber: wuzish.

A unique module id, which is a part of sinit and sterm function names, is necessary to be unique. However,  `getUniqueModuleId` will fail if there is no strong external symbol within a module.
We will turn to use PID and timestamp when this happens.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85527

Files:
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll


Index: llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
+++ llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
@@ -1,7 +1,22 @@
-; RUN: not llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
-; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
 
 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
- at llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @bar, i8* null }]
 
-; CHECK: LLVM ERROR: cannot produce a unique identifier for this module based on strong external symbols
+define internal void @foo() {
+  ret void
+}
+
+; 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_1006931596810495_0.
+
+; CHECK:         .lglobl        foo[DS]
+; CHECK:         .lglobl        .foo
+; CHECK:         .csect foo[DS]
+; CHECK: __sinit80000000_clang_[[MODULEID:[0-9]+]]_0:
+; CHECK: .foo:
+; CHECK: .__sinit80000000_clang_[[MODULEID]]_0:
+; CHECK: .globl	__sinit80000000_clang_[[MODULEID]]_0
+; CHECK: .globl	.__sinit80000000_clang_[[MODULEID]]_0
Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ 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"
@@ -1835,6 +1836,13 @@
   }
 }
 
+static std::time_t getTime() {
+  std::time_t Now = time(nullptr);
+  if (Now < 0 || !isUInt<64>(Now))
+    return UINT64_MAX;
+  return Now;
+}
+
 bool PPCAIXAsmPrinter::doInitialization(Module &M) {
   const bool Result = PPCAsmPrinter::doInitialization(M);
 
@@ -1864,13 +1872,13 @@
       // 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)
+          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.
+          GlobalUniqueModuleId = llvm::utostr(sys::Process::getProcessId()) +
+                                 llvm::utostr(getTime());
       }
 
       emitSpecialLLVMGlobal(&G);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85527.283907.patch
Type: text/x-patch
Size: 3376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200807/2155823a/attachment.bin>


More information about the llvm-commits mailing list