spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

MDC logging fails with gcc-14 when SPDLOG_COMPILED_LIB

Open wdconinc opened this issue 9 months ago • 1 comments

We are encountering failures with gcc-14 when attempting to use MDC with SPDLOG_COMPILED_LIB (spdlog-1.14.1, unable to test with newer since we are stuck on fmt-10).

The following testing code is use:

#include "spdlog/spdlog.h"
#include "spdlog/mdc.h"

int main(int, char **) {
    spdlog::set_pattern("[%&] %v");
    spdlog::mdc::put("key", "value");
    spdlog::info("Some log message with context");
}

This compiled with gcc-14.2.0 (in Ubuntu 25.04):

/usr/bin/g++ -DFMT_SHARED -DSPDLOG_FMT_EXTERNAL -DSPDLOG_COMPILED_LIB -DSPDLOG_SHARED_LIB -isystem /opt/local/include example.cpp -o example /opt/local/lib/libspdlog.so.1.14.1 /opt/local/lib/libfmt.so.10.2.1

(This is what a CMake project does essentially, without any additional compiler flags, but details have been stripped for this minimal reproducer.)

We can also compile this with:

/usr/bin/g++ -DFMT_SHARED -DSPDLOG_FMT_EXTERNAL -isystem /opt/local/include example.cpp -o example /opt/local/lib/libfmt.so.10.2.1

In the first case (SPDLOG_COMPILED_LIB), the invocation of ./example results in:

[] Some log message with context

In the second case (no SPDLOG_COMPILED_LIB), the invocation of ./example results in:

[key:value] Some log message with context

This behavior is compiler-dependent. clang++ (21.0.0, development snapshot) works in the case of SPDLOG_COMPILED_LIB.

wdconinc avatar Apr 01 '25 18:04 wdconinc

Does the problem reproduce in another version of gcc? It sounds like a GCC bug since it uses the static thread_local variable.

https://github.com/gabime/spdlog/blob/48bcf39a661a13be22666ac64db8a7f886f2637e/include/spdlog/mdc.h#L44-L47

tt4g avatar Apr 01 '25 21:04 tt4g