From 22491eb1236c8b5c1dcba2ed3a213c74ce699988 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Thu, 25 May 2023 15:26:33 -0400 Subject: [PATCH] logging: Prevent LogStream constructor from being discarded (#925) Fixes linker error reported in #922 --- CONTRIBUTORS | 1 + src/glog/logging.h.in | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 05cb688..5780377 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -29,6 +29,7 @@ Andy Ying Bret McKee Brian Silverman Dmitriy Arbitman +Eric Kilmer Fumitoshi Ukai Guillaume Dumont HÃ¥kan L. S. Younes diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 09f9645..26fd371 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -1344,6 +1344,15 @@ GLOG_MSVC_PUSH_DISABLE_WARNING(4275) class GLOG_EXPORT LogStream : public std::ostream { GLOG_MSVC_POP_WARNING() public: +#if defined __has_attribute +# if __has_attribute (used) + // In some cases, like when compiling glog as a static library with GCC and + // linking against a Clang-built executable, this constructor will be + // removed by the linker. We use this attribute to prevent the linker from + // discarding it. + __attribute__ ((used)) +# endif +#endif LogStream(char *buf, int len, int64 ctr) : std::ostream(NULL), streambuf_(buf, len),