<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 19, 2013 at 3:35 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: samsonov<br>
Date: Tue Feb 19 05:35:39 2013<br>
New Revision: 175509<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=175509&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=175509&view=rev</a><br>
Log:<br>
Fix initialization-order bug in llvm::Support::TimeValue. TimeValue::now() is explicitly called during module initialization of lib/Support/Process.cpp. It reads the field of global object PosixZeroTime, which is not guaranteed to be initialized at this point. Found by AddressSanitizer with -fsanitize=init-order option.<br>
</blockquote><div><br></div><div style>Do we have a public bot with this configuration on it?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
llvm/trunk/include/llvm/Support/TimeValue.h<br>
llvm/trunk/lib/Support/TimeValue.cpp<br>
llvm/trunk/lib/Support/Unix/TimeValue.inc<br>
<br>
Modified: llvm/trunk/include/llvm/Support/TimeValue.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TimeValue.h?rev=175509&r1=175508&r2=175509&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TimeValue.h?rev=175509&r1=175508&r2=175509&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/TimeValue.h (original)<br>
+++ llvm/trunk/include/llvm/Support/TimeValue.h Tue Feb 19 05:35:39 2013<br>
@@ -240,7 +240,7 @@ namespace sys {<br>
/// Posix, correcting for the difference in Posix zero time.<br>
/// @brief Convert to unix time (100 nanoseconds since 12:00:00a Jan 1,1970)<br>
uint64_t toPosixTime() const {<br>
- uint64_t result = seconds_ - PosixZeroTime.seconds_;<br>
+ uint64_t result = seconds_ - PosixZeroTimeSeconds;<br>
result += nanos_ / NANOSECONDS_PER_POSIX_TICK;<br>
return result;<br>
}<br>
@@ -248,14 +248,14 @@ namespace sys {<br>
/// Converts the TimeValue into the corresponding number of seconds<br>
/// since the epoch (00:00:00 Jan 1,1970).<br>
uint64_t toEpochTime() const {<br>
- return seconds_ - PosixZeroTime.seconds_;<br>
+ return seconds_ - PosixZeroTimeSeconds;<br>
}<br>
<br>
/// Converts the TimeValue into the corresponding number of "ticks" for<br>
/// Win32 platforms, correcting for the difference in Win32 zero time.<br>
/// @brief Convert to windows time (seconds since 12:00:00a Jan 1, 1601)<br>
uint64_t toWin32Time() const {<br>
- uint64_t result = seconds_ - Win32ZeroTime.seconds_;<br>
+ uint64_t result = seconds_ - Win32ZeroTimeSeconds;<br>
result += nanos_ / NANOSECONDS_PER_WIN32_TICK;<br>
return result;<br>
}<br>
@@ -264,7 +264,7 @@ namespace sys {<br>
/// correction for the Posix zero time.<br>
/// @brief Convert to timespec time (ala POSIX.1b)<br>
void getTimespecTime( uint64_t& seconds, uint32_t& nanos ) const {<br>
- seconds = seconds_ - PosixZeroTime.seconds_;<br>
+ seconds = seconds_ - PosixZeroTimeSeconds;<br>
nanos = nanos_;<br>
}<br>
<br>
@@ -331,7 +331,7 @@ namespace sys {<br>
/// TimeValue and assigns that value to \p this.<br>
/// @brief Convert seconds form PosixTime to TimeValue<br>
void fromEpochTime( SecondsType seconds ) {<br>
- seconds_ = seconds + PosixZeroTime.seconds_;<br>
+ seconds_ = seconds + PosixZeroTimeSeconds;<br>
nanos_ = 0;<br>
this->normalize();<br>
}<br>
@@ -340,7 +340,7 @@ namespace sys {<br>
/// corresponding TimeValue and assigns that value to \p this.<br>
/// @brief Convert seconds form Windows FILETIME to TimeValue<br>
void fromWin32Time( uint64_t win32Time ) {<br>
- this->seconds_ = win32Time / 10000000 + Win32ZeroTime.seconds_;<br>
+ this->seconds_ = win32Time / 10000000 + Win32ZeroTimeSeconds;<br>
this->nanos_ = NanoSecondsType(win32Time % 10000000) * 100;<br>
}<br>
<br>
@@ -360,6 +360,9 @@ namespace sys {<br>
/// Store the values as a <timeval>.<br>
SecondsType seconds_;///< Stores the seconds part of the TimeVal<br>
NanoSecondsType nanos_; ///< Stores the nanoseconds part of the TimeVal<br>
+<br>
+ static const SecondsType PosixZeroTimeSeconds;<br>
+ static const SecondsType Win32ZeroTimeSeconds;<br>
/// @}<br>
<br>
};<br>
<br>
Modified: llvm/trunk/lib/Support/TimeValue.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TimeValue.cpp?rev=175509&r1=175508&r2=175509&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TimeValue.cpp?rev=175509&r1=175508&r2=175509&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/TimeValue.cpp (original)<br>
+++ llvm/trunk/lib/Support/TimeValue.cpp Tue Feb 19 05:35:39 2013<br>
@@ -17,11 +17,16 @@<br>
namespace llvm {<br>
using namespace sys;<br>
<br>
+const TimeValue::SecondsType<br>
+ TimeValue::PosixZeroTimeSeconds = -946684800;<br>
+const TimeValue::SecondsType<br>
+ TimeValue::Win32ZeroTimeSeconds = -12591158400ULL;<br>
+<br>
const TimeValue TimeValue::MinTime = TimeValue ( INT64_MIN,0 );<br>
const TimeValue TimeValue::MaxTime = TimeValue ( INT64_MAX,0 );<br>
const TimeValue TimeValue::ZeroTime = TimeValue ( 0,0 );<br>
-const TimeValue TimeValue::PosixZeroTime = TimeValue ( -946684800,0 );<br>
-const TimeValue TimeValue::Win32ZeroTime = TimeValue ( -12591158400ULL,0 );<br>
+const TimeValue TimeValue::PosixZeroTime = TimeValue ( PosixZeroTimeSeconds,0 );<br>
+const TimeValue TimeValue::Win32ZeroTime = TimeValue ( Win32ZeroTimeSeconds,0 );<br>
<br>
void<br>
TimeValue::normalize( void ) {<br>
<br>
Modified: llvm/trunk/lib/Support/Unix/TimeValue.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/TimeValue.inc?rev=175509&r1=175508&r2=175509&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/TimeValue.inc?rev=175509&r1=175508&r2=175509&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Unix/TimeValue.inc (original)<br>
+++ llvm/trunk/lib/Support/Unix/TimeValue.inc Tue Feb 19 05:35:39 2013<br>
@@ -48,7 +48,8 @@ TimeValue TimeValue::now() {<br>
}<br>
<br>
return TimeValue(<br>
- static_cast<TimeValue::SecondsType>( the_time.tv_sec + PosixZeroTime.seconds_ ),<br>
+ static_cast<TimeValue::SecondsType>( the_time.tv_sec +<br>
+ PosixZeroTimeSeconds ),<br>
static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec *<br>
NANOSECONDS_PER_MICROSECOND ) );<br>
}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>