[PATCH] D159319: [AIX] Use microseconds for timestamp in sinit/sterm symbols

wael yehia via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 31 17:18:28 PDT 2023


w2yehia created this revision.
Herald added subscribers: kbarton, hiraditya, nemanjai.
Herald added a project: All.
w2yehia requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

With ThinLTO, when compiling SPEC 2017 omnetpp_r with `-threads=4`, two small modules can end up with the same timestamp in their sinit symbols when calculating time in seconds, creating duplicate definitions.
This patch uses a timestamp in microseconds (timeval::tv_usec) instead.


https://reviews.llvm.org/D159319

Files:
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp


Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -76,6 +76,7 @@
 #include <cstdint>
 #include <memory>
 #include <new>
+#include <sys/time.h>
 
 using namespace llvm;
 using namespace llvm::XCOFF;
@@ -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
+        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.
+          struct timeval tp;
+          int stat = gettimeofday(&tp, nullptr);
+          uint64_t Time = stat ? time(nullptr) : tp.tv_usec;
           FormatIndicatorAndUniqueModId =
               "clangPidTime_" + llvm::itostr(sys::Process::getProcessId()) +
-              "_" + llvm::itostr(time(nullptr));
+              "_" + llvm::itostr(Time);
+        }
       }
 
       emitSpecialLLVMGlobal(&G);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159319.555199.patch
Type: text/x-patch
Size: 1296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230901/c4039844/attachment.bin>


More information about the llvm-commits mailing list