Skip to content

Building with --enable-memory-sanitizer on FreeBSD errors with duplicate strlcpy and strlcat #20002

@outtersg

Description

@outtersg

Description

./configure --with-pdo-pgsql=$HOME/local --enable-memory-sanitizer
make -j8
ld: error: duplicate symbol: strlcpy
>>> defined at msan_interceptors.cpp
>>>            msan_interceptors.o:(strlcpy) in archive /usr/lib/clang/19/lib/freebsd/libclang_rt.msan-x86_64.a
>>> defined at zend_string.c:507 (Zend/zend_string.c:507)
>>>            Zend/zend_string.o:(.text+0x5500)

And in fact the stock FreeBSD 14.3 clang, as well as my home-compiled ones, define the symbols, contrary to what is suggested in a comment:

/* strlcpy and strlcat are not intercepted by msan, so we need to do it ourselves. */
#if __has_feature(memory_sanitizer)
/* here strlcat and strlcpy are redefined with some msan */
#endif

while, as seen with nm -o:

/usr/lib/clang/19/lib/freebsd/libclang_rt.msan-x86_64.a:msan_interceptors.o:000000000000073f T strlcpy
/home/gui/local/clang+libcxx+omp+rt-20.1.4/lib/clang/20/lib/freebsd/libclang_rt.msan-x86_64.a:msan_interceptors.cpp.o:000000000000073f T strlcpy

The #if should probably be more subtle, from the commit comment it applied to Clang 17 but I can't say to what compiler and versions it should be limited: should it be detected in the configure?

PHP Version

master 2025-09-30

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions