Skip to content

Commit

Permalink
logging: Prevent LogStream constructor from being discarded (#925)
Browse files Browse the repository at this point in the history
Fixes linker error reported in #922
  • Loading branch information
ekilmer committed May 25, 2023
1 parent 4945347 commit 22491eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -29,6 +29,7 @@ Andy Ying <andy@trailofbits.com>
Bret McKee <bretmckee@google.com>
Brian Silverman <bsilver16384@gmail.com>
Dmitriy Arbitman <d.arbitman@gmail.com>
Eric Kilmer <eric.d.kilmer@gmail.com>
Fumitoshi Ukai <ukai@google.com>
Guillaume Dumont <dumont.guillaume@gmail.com>
Håkan L. S. Younes <hyounes@google.com>
Expand Down
9 changes: 9 additions & 0 deletions src/glog/logging.h.in
Expand Up @@ -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),
Expand Down

0 comments on commit 22491eb

Please sign in to comment.