Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
glog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
glog
Commits
6adf6d7a
Commit
6adf6d7a
authored
Dec 12, 2018
by
Roman Gershman
Committed by
Sergiu Deitsch
Dec 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix debug build using gcc -fsanitize=undefined (#374)
parent
125d6b3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
3 deletions
+29
-3
CMakeLists.txt
CMakeLists.txt
+6
-0
config.h.cmake.in
src/config.h.cmake.in
+3
-0
logging.cc
src/logging.cc
+20
-3
No files found.
CMakeLists.txt
View file @
6adf6d7a
...
...
@@ -206,6 +206,12 @@ thread_local int tls;
int main() { }
"
HAVE_CXX11_TLS
)
check_cxx_source_compiles
(
"
#include <type_traits>
std::aligned_storage<sizeof(char), alignof(char)>::type data;
int main() { }
"
HAVE_ALIGNED_STORAGE
)
if
(
WITH_TLS
)
# Cygwin does not support the thread attribute. Don't bother.
if
(
HAVE_GCC_TLS
)
...
...
src/config.h.cmake.in
View file @
6adf6d7a
...
...
@@ -189,6 +189,9 @@
/* Define to necessary thread-local storage attribute. */
#cmakedefine GLOG_THREAD_LOCAL_STORAGE ${GLOG_THREAD_LOCAL_STORAGE}
/* Check whether aligned_storage and alignof present */
#cmakedefine HAVE_ALIGNED_STORAGE ${HAVE_ALIGNED_STORAGE}
/* Version number of package */
#cmakedefine VERSION
...
...
src/logging.cc
View file @
6adf6d7a
...
...
@@ -1153,8 +1153,16 @@ static LogMessage::LogMessageData fatal_msg_data_shared;
// LogMessageData object exists (in this case glog makes zero heap memory
// allocations).
static
GLOG_THREAD_LOCAL_STORAGE
bool
thread_data_available
=
true
;
static
GLOG_THREAD_LOCAL_STORAGE
char
thread_msg_data
[
sizeof
(
LogMessage
::
LogMessageData
)];
#endif // defined(GLOG_THREAD_LOCAL_STORAGE)
#ifdef HAVE_ALIGNED_STORAGE
static
GLOG_THREAD_LOCAL_STORAGE
std
::
aligned_storage
<
sizeof
(
LogMessage
::
LogMessageData
),
alignof
(
LogMessage
::
LogMessageData
)
>::
type
thread_msg_data
;
#else
static
GLOG_THREAD_LOCAL_STORAGE
char
thread_msg_data
[
sizeof
(
void
*
)
+
sizeof
(
LogMessage
::
LogMessageData
)];
#endif // HAVE_ALIGNED_STORAGE
#endif // defined(GLOG_THREAD_LOCAL_STORAGE)
LogMessage
::
LogMessageData
::
LogMessageData
()
:
stream_
(
message_text_
,
LogMessage
::
kMaxLogMessageLen
,
0
)
{
...
...
@@ -1213,10 +1221,19 @@ void LogMessage::Init(const char* file,
allocated_
=
NULL
;
if
(
severity
!=
GLOG_FATAL
||
!
exit_on_dfatal
)
{
#ifdef GLOG_THREAD_LOCAL_STORAGE
const
uintptr_t
kAlign
=
sizeof
(
void
*
)
-
1
;
// No need for locking, because this is thread local.
if
(
thread_data_available
)
{
thread_data_available
=
false
;
#ifdef HAVE_ALIGNED_STORAGE
data_
=
new
(
&
thread_msg_data
)
LogMessageData
;
#else
char
*
align_ptr
=
reinterpret_cast
<
char
*>
(
reinterpret_cast
<
uintptr_t
>
(
thread_msg_data
+
kAlign
)
&
~
kAlign
);
data_
=
new
(
align_ptr
)
LogMessageData
;
assert
(
reinterpret_cast
<
uintptr_t
>
(
align_ptr
)
%
sizeof
(
void
*
)
==
0
);
#endif
}
else
{
allocated_
=
new
LogMessageData
();
data_
=
allocated_
;
...
...
@@ -1294,7 +1311,7 @@ void LogMessage::Init(const char* file,
LogMessage
::~
LogMessage
()
{
Flush
();
#ifdef GLOG_THREAD_LOCAL_STORAGE
if
(
data_
==
static_cast
<
void
*>
(
thread_msg_data
))
{
if
(
data_
==
static_cast
<
void
*>
(
&
thread_msg_data
))
{
data_
->~
LogMessageData
();
thread_data_available
=
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment