[llvm] 11d5c7b - [AIX] Add threadId and use nanosecond timestamp in sinit/sterm symbols
Wael Yehia via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 10:46:47 PDT 2023
Author: Wael Yehia
Date: 2023-09-07T17:46:41Z
New Revision: 11d5c7bd289cb3a3bb326871ae8f37dafa49ed43
URL: https://github.com/llvm/llvm-project/commit/11d5c7bd289cb3a3bb326871ae8f37dafa49ed43
DIFF: https://github.com/llvm/llvm-project/commit/11d5c7bd289cb3a3bb326871ae8f37dafa49ed43.diff
LOG: [AIX] Add threadId and use nanosecond timestamp in sinit/sterm symbols
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 nanoseconds.
Because the race can be between threads, embed the thread ID as well.
Reviewed By: xingxue, daltenty
Differential Revision: https://reviews.llvm.org/D159319
Added:
Modified:
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 1ecccdebe036f0..373be8ea7f5805 100644
--- 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 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
// 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::nanoseconds>(
+ 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
index 5b6c83c1212b74..823fd556deec01 100644
--- 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 @@ define internal void @foo() {
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
More information about the llvm-commits
mailing list