logging: Prevent LogStream constructor from being discarded (#925)

Fixes linker error reported in #922
This commit is contained in:
Eric Kilmer 2023-05-25 15:26:33 -04:00 committed by GitHub
parent 4945347d07
commit 22491eb123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -29,6 +29,7 @@ Andy Ying <andy@trailofbits.com>
Bret McKee <bretmckee@google.com> Bret McKee <bretmckee@google.com>
Brian Silverman <bsilver16384@gmail.com> Brian Silverman <bsilver16384@gmail.com>
Dmitriy Arbitman <d.arbitman@gmail.com> Dmitriy Arbitman <d.arbitman@gmail.com>
Eric Kilmer <eric.d.kilmer@gmail.com>
Fumitoshi Ukai <ukai@google.com> Fumitoshi Ukai <ukai@google.com>
Guillaume Dumont <dumont.guillaume@gmail.com> Guillaume Dumont <dumont.guillaume@gmail.com>
Håkan L. S. Younes <hyounes@google.com> Håkan L. S. Younes <hyounes@google.com>

View File

@ -1344,6 +1344,15 @@ GLOG_MSVC_PUSH_DISABLE_WARNING(4275)
class GLOG_EXPORT LogStream : public std::ostream { class GLOG_EXPORT LogStream : public std::ostream {
GLOG_MSVC_POP_WARNING() GLOG_MSVC_POP_WARNING()
public: 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) LogStream(char *buf, int len, int64 ctr)
: std::ostream(NULL), : std::ostream(NULL),
streambuf_(buf, len), streambuf_(buf, len),