Bug 275854 - -fsanitize=address and -fsanitize=memory fail with clang 17
Summary: -fsanitize=address and -fsanitize=memory fail with clang 17
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
: 275892 (view as bug list)
Depends on:
Blocks: 273753
  Show dependency treegraph
 
Reported: 2023-12-20 09:23 UTC by Jan Beich
Modified: 2024-01-07 23:09 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2023-12-20 09:23:52 UTC
$ echo 'int main() {}' >a.c

$ cc -fsanitize=address a.c
ld: error: undefined symbol: __sanitizer::ThreadArgRetval::GetAllPtrsLocked(__sanitizer::InternalMmapVector<unsigned long>*)
>>> referenced by asan_thread.cpp:560 (/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_thread.cpp:560)
>>>               asan_thread.o:(__lsan::GetAdditionalThreadContextPtrsLocked(__sanitizer::InternalMmapVector<unsigned long>*)) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a

ld: error: undefined symbol: __sanitizer::ThreadArgRetval::CreateLocked(unsigned long, bool, __sanitizer::ThreadArgRetval::Args const&)
>>> referenced by sanitizer_thread_arg_retval.h:48 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_arg_retval.h:48)
>>>               asan_interceptors.o:(__interceptor_pthread_create) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a

ld: error: undefined symbol: __sanitizer::ThreadArgRetval::BeforeJoin(unsigned long) const
>>> referenced by sanitizer_thread_arg_retval.h:74 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_arg_retval.h:74)
>>>               asan_interceptors.o:(__interceptor_pthread_join) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a

ld: error: undefined symbol: __sanitizer::ThreadArgRetval::AfterJoin(unsigned long, unsigned int)
>>> referenced by sanitizer_thread_arg_retval.h:76 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_arg_retval.h:76)
>>>               asan_interceptors.o:(__interceptor_pthread_join) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a

ld: error: undefined symbol: __sanitizer::ThreadArgRetval::DetachLocked(unsigned long)
>>> referenced by sanitizer_thread_arg_retval.h:65 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_arg_retval.h:65)
>>>               asan_interceptors.o:(__interceptor_pthread_detach) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a

ld: error: undefined symbol: __sanitizer::ThreadArgRetval::Finish(unsigned long, void*)
>>> referenced by asan_interceptors.cpp:290 (/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:290)
>>>               asan_interceptors.o:(__interceptor_pthread_exit) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a
>>> referenced by asan_interceptors.cpp:226 (/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:226)
>>>               asan_interceptors.o:(asan_thread_start(void*)) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a

ld: error: undefined symbol: __sanitizer::ThreadArgRetval::GetArgs(unsigned long) const
>>> referenced by asan_interceptors.cpp:224 (/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:224)
>>>               asan_interceptors.o:(asan_thread_start(void*)) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a
cc: error: linker command failed with exit code 1 (use -v to see invocation)

$ cc -fsanitize=memory a.c
ld: error: undefined symbol: __msan::UnpoisonDllAddrInfo(void*)
>>> referenced by msan_interceptors.cpp:1550 (/usr/src/contrib/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:1550)
>>>               msan_interceptors.o:(__interceptor_dladdr) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.msan-x86_64.a
cc: error: linker command failed with exit code 1 (use -v to see invocation)

Note, -fsanitize=undefined, -fsanitize=thread work fine.
Comment 1 commit-hook freebsd_committer freebsd_triage 2023-12-20 16:13:55 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0c3af23961e170538f375c392b043903c1397780

commit 0c3af23961e170538f375c392b043903c1397780
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-20 16:08:26 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-12-20 16:08:26 +0000

    Add missing sources to libclang_rt Makefiles, clean up unneeded ones

    During the llvm-17 merge, a few new source files were not added to the
    libclang_rt Makefiles, in particular sanitizer_thread_arg_retval.cpp
    which is now required for AddressSanitizer and MemorySanitizer. Also,
    MemorySanitizer now requires msan_dl.cpp.

    While here, clean out a number of source files that compile into nothing
    (because they only contain non-FreeBSD parts). Also, remove a duplicated
    instance of tsan_new_delete.cpp from libclang_rt.tsan, since it is only
    supposed to live in libclang_rt.tsan_cxx.

    PR:             275854
    Reported by:    jbeich
    MFC after:      1 month

 lib/libclang_rt/asan/Makefile             | 3 +--
 lib/libclang_rt/asan_dynamic/Makefile     | 3 +--
 lib/libclang_rt/cfi/Makefile              | 2 +-
 lib/libclang_rt/cfi_diag/Makefile         | 2 +-
 lib/libclang_rt/dd/Makefile               | 2 +-
 lib/libclang_rt/msan/Makefile             | 3 ++-
 lib/libclang_rt/safestack/Makefile        | 1 -
 lib/libclang_rt/stats/Makefile            | 1 +
 lib/libclang_rt/tsan/Makefile             | 3 ---
 lib/libclang_rt/ubsan_standalone/Makefile | 2 +-
 lib/libclang_rt/xray/Makefile             | 1 +
 11 files changed, 10 insertions(+), 13 deletions(-)
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2023-12-22 23:51:58 UTC
*** Bug 275892 has been marked as a duplicate of this bug. ***
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-01-07 17:51:02 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4883ad3ada84d4fee7372ac30b80eb1dfeca0d80

commit 4883ad3ada84d4fee7372ac30b80eb1dfeca0d80
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-20 16:08:26 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-01-07 17:46:19 +0000

    Add missing sources to libclang_rt Makefiles, clean up unneeded ones

    During the llvm-17 merge, a few new source files were not added to the
    libclang_rt Makefiles, in particular sanitizer_thread_arg_retval.cpp
    which is now required for AddressSanitizer and MemorySanitizer. Also,
    MemorySanitizer now requires msan_dl.cpp.

    While here, clean out a number of source files that compile into nothing
    (because they only contain non-FreeBSD parts). Also, remove a duplicated
    instance of tsan_new_delete.cpp from libclang_rt.tsan, since it is only
    supposed to live in libclang_rt.tsan_cxx.

    PR:             275854
    Reported by:    jbeich
    MFC after:      1 month

    (cherry picked from commit 0c3af23961e170538f375c392b043903c1397780)

 lib/libclang_rt/asan/Makefile             | 3 +--
 lib/libclang_rt/asan_dynamic/Makefile     | 3 +--
 lib/libclang_rt/cfi/Makefile              | 2 +-
 lib/libclang_rt/cfi_diag/Makefile         | 2 +-
 lib/libclang_rt/dd/Makefile               | 2 +-
 lib/libclang_rt/msan/Makefile             | 3 ++-
 lib/libclang_rt/safestack/Makefile        | 1 -
 lib/libclang_rt/stats/Makefile            | 1 +
 lib/libclang_rt/tsan/Makefile             | 3 ---
 lib/libclang_rt/ubsan_standalone/Makefile | 2 +-
 lib/libclang_rt/xray/Makefile             | 1 +
 11 files changed, 10 insertions(+), 13 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-01-07 23:09:15 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=197635d7a92ae6a25ef869fcad31db868d2a4f07

commit 197635d7a92ae6a25ef869fcad31db868d2a4f07
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-20 16:08:26 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-01-07 23:04:42 +0000

    Add missing sources to libclang_rt Makefiles, clean up unneeded ones

    During the llvm-17 merge, a few new source files were not added to the
    libclang_rt Makefiles, in particular sanitizer_thread_arg_retval.cpp
    which is now required for AddressSanitizer and MemorySanitizer. Also,
    MemorySanitizer now requires msan_dl.cpp.

    While here, clean out a number of source files that compile into nothing
    (because they only contain non-FreeBSD parts). Also, remove a duplicated
    instance of tsan_new_delete.cpp from libclang_rt.tsan, since it is only
    supposed to live in libclang_rt.tsan_cxx.

    PR:             275854
    Reported by:    jbeich
    MFC after:      1 month

    (cherry picked from commit 0c3af23961e170538f375c392b043903c1397780)

 lib/libclang_rt/asan/Makefile             | 3 +--
 lib/libclang_rt/asan_dynamic/Makefile     | 3 +--
 lib/libclang_rt/cfi/Makefile              | 2 +-
 lib/libclang_rt/cfi_diag/Makefile         | 2 +-
 lib/libclang_rt/dd/Makefile               | 2 +-
 lib/libclang_rt/msan/Makefile             | 3 ++-
 lib/libclang_rt/safestack/Makefile        | 1 -
 lib/libclang_rt/stats/Makefile            | 1 +
 lib/libclang_rt/tsan/Makefile             | 3 ---
 lib/libclang_rt/ubsan_standalone/Makefile | 2 +-
 lib/libclang_rt/xray/Makefile             | 1 +
 11 files changed, 10 insertions(+), 13 deletions(-)