[Bug sanitizer/84285] New: Fail to statically link with -fsanitize=undefined
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 = 0x7fff; 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
[Bug sanitizer/84285] Fail to statically link with -fsanitize=undefined
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285 --- Comment #4 from Marc-André Lureau --- (In reply to Jakub Jelinek from comment #3) > Created attachment 43371 [details] > gcc8-pr84285.patch > > Untested fix. Thanks patch texted successfully.
[Bug c/105080] New: Bugus -Wformat-truncation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105080 Bug ID: 105080 Summary: Bugus -Wformat-truncation Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: marcandre.lureau at gmail dot com Target Milestone: --- With Fedora gcc-12.0.1-0.12.fc36.x86_64 gcc (GCC) 12.0.1 20220308 (Red Hat 12.0.1-0) test.c: #include void main(void) { char foo[3]; int i; for (i = 0; i < 16; i++) { snprintf(foo, sizeof(foo), "%d", i); } } $ gcc -Wformat-truncation test.c test.c: In function ‘main’: test.c:9:45: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=] 9 | snprintf(foo, sizeof(foo), "%d", i); | ^~ test.c:9:44: note: directive argument in the range [-2147483647, 15] 9 | snprintf(foo, sizeof(foo), "%d", i); |^~~~ test.c:9:17: note: ‘snprintf’ output between 2 and 12 bytes into a destination of size 3 9 | snprintf(foo, sizeof(foo), "%d", i); | ^~~ The computed range seems incorrect. There are similar variants of this bug that have been found while compiling QEMU (https://patchew.org/QEMU/20220328084717.367993-1-marcandre.lur...@redhat.com/)
[Bug sanitizer/113304] New: zero-length array and bound checking error
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113304 Bug ID: 113304 Summary: zero-length array and bound checking error Product: gcc Version: 13.2.1 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: --- gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6) gcc -fsanitize=bounds-strict -lubsan test.c test.c:6:11: runtime error: index 3 out of bounds for type 'int [*]' typedef struct BN { int d[0]; } BN; void test(BN *foo) { foo->d[3] = 0; } int main(int argc, char *argv[]) { struct BN { int d[4]; } foo; test((BN *)&foo); return 0; } This coding style is used in bignum libraries, such as libtpms BN implementation. Is this incompatible with bounds-strict usage?