https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
Bug ID: 84285 Summary: Fail to statically link with -fsanitize=undefined Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: marcandre.lureau at gmail dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- With gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) (fedora 27) int main(int argc, char **argv) { int k = 0x7fffffff; k += argc; return 0; } $ clang -static -fsanitize=undefined test.c vs $ gcc -static -fsanitize=undefined test.c /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_linux_libcdep.o): In function `__sanitizer::GetThreadStackTopAndBottom(bool, unsigned long*, unsigned long*)': (.text+0x551): undefined reference to `pthread_attr_init' (.text+0x556): undefined reference to `pthread_self' (.text+0x561): undefined reference to `pthread_getattr_np' (.text+0x599): undefined reference to `pthread_attr_destroy' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_linux_libcdep.o): In function `__sanitizer::SetEnv(char const*, char const*)': (.text+0x70b): undefined reference to `dlsym' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_linux_libcdep.o): In function `__sanitizer::InitTlsSize()': (.text+0x843): undefined reference to `dlsym' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_posix_libcdep.o): In function `__sanitizer::GetNamedMappingFd(char const*, unsigned long)': (.text+0x747): undefined reference to `shm_open' (.text+0x763): undefined reference to `shm_unlink' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_posix_libcdep.o): In function `__sanitizer::AdjustStackSize(void*)': (.text+0xa8f): undefined reference to `pthread_attr_setstacksize' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_posix_libcdep.o): In function `__sanitizer::GetThreadSelf()': (.text+0x1d1): undefined reference to `pthread_self' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_posix_libcdep.o): In function `__sanitizer::my_pthread_attr_getstack(void*, void**, unsigned long*)': (.text+0x9b1): undefined reference to `pthread_attr_getstack' /usr/lib/gcc/x86_64-redhat-linux/7/libubsan.a(sanitizer_symbolizer_posix_libcdep.o): In function `__sanitizer::Symbolizer::LateInitialize()': (.text+0x7e3): undefined reference to `dlsym' collect2: error: ld returned 1 exit status