Skip to content

Commit 11d5c7b

Browse files
author
Wael Yehia
committed
[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
1 parent 99e70cc commit 11d5c7b

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "llvm/Support/ErrorHandling.h"
6969
#include "llvm/Support/Process.h"
7070
#include "llvm/Support/raw_ostream.h"
71+
#include "llvm/Support/thread.h"
7172
#include "llvm/Target/TargetMachine.h"
7273
#include "llvm/TargetParser/Triple.h"
7374
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -2740,14 +2741,18 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
27402741
// and add a format indicator as a part of function name in case we
27412742
// will support more than one format.
27422743
FormatIndicatorAndUniqueModId = "clang_" + UniqueModuleId.substr(1);
2743-
else
2744-
// Use the Pid and current time as the unique module id when we cannot
2745-
// generate one based on a module's strong external symbols.
2746-
// FIXME: Adjust the comment accordingly after we use source file full
2747-
// path instead.
2744+
else {
2745+
// Use threadId, Pid, and current time as the unique module id when we
2746+
// cannot generate one based on a module's strong external symbols.
2747+
auto CurTime =
2748+
std::chrono::duration_cast<std::chrono::nanoseconds>(
2749+
std::chrono::steady_clock::now().time_since_epoch())
2750+
.count();
27482751
FormatIndicatorAndUniqueModId =
2749-
"clangPidTime_" + llvm::itostr(sys::Process::getProcessId()) +
2750-
"_" + llvm::itostr(time(nullptr));
2752+
"clangPidTidTime_" + llvm::itostr(sys::Process::getProcessId()) +
2753+
"_" + llvm::itostr(llvm::this_thread::get_id()) + "_" +
2754+
llvm::itostr(CurTime);
2755+
}
27512756
}
27522757

27532758
emitSpecialLLVMGlobal(&G);

llvm/test/CodeGen/PowerPC/aix-static-init-no-unique-module-id.ll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ define internal void @foo() {
77
ret void
88
}
99

10-
; FIXME: Adjust the comment after we use source file full path to generate unique
11-
; module id instead.
12-
; Use the Pid and timestamp to generate a unique module id when strong external
10+
; Use the Pid, threadId, and timestamp to generate a unique module id when strong external
1311
; symbols are not available in current module. The module id generated in this
1412
; way is not reproducible. A function name sample would be:
15-
; __sinit80000000_clangPidTime_119189_1597348415_0
13+
; __sinit80000000_clangPidTidTime_56689326_1_57027228417827568_0
1614

1715
; CHECK: .lglobl foo[DS]
1816
; CHECK: .lglobl .foo
1917
; CHECK: .csect foo[DS]
20-
; CHECK-NEXT: __sinit80000000_clangPidTime_[[PID:[0-9]+]]_[[TIMESTAMP:[0-9]+]]_0:
18+
; CHECK-NEXT: __sinit80000000_clangPidTidTime_[[PID:[0-9]+]]_[[TID:[0-9]+]]_[[TIMESTAMP:[0-9]+]]_0:
2119
; CHECK: .foo:
22-
; CHECK-NEXT: .__sinit80000000_clangPidTime_[[PID]]_[[TIMESTAMP]]_0:
23-
; CHECK: .globl __sinit80000000_clangPidTime_[[PID]]_[[TIMESTAMP]]_0
24-
; CHECK: .globl .__sinit80000000_clangPidTime_[[PID]]_[[TIMESTAMP]]_0
20+
; CHECK-NEXT: .__sinit80000000_clangPidTidTime_[[PID]]_[[TID]]_[[TIMESTAMP]]_0:
21+
; CHECK: .globl __sinit80000000_clangPidTidTime_[[PID]]_[[TID]]_[[TIMESTAMP]]_0
22+
; CHECK: .globl .__sinit80000000_clangPidTidTime_[[PID]]_[[TID]]_[[TIMESTAMP]]_0

0 commit comments

Comments
 (0)