From c289fc341bd947cccac501f2321a8c8aeadcb3bd Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 26 Apr 2023 02:45:27 -0700 Subject: [PATCH] gcc: disable libsanitizer on mips64n32 On MIPS, libsanitizer appears to have very detailed knowledge of the Linux system call ABI manually encoded, by hand, into the library. This encoding covers the o32 and 64 abis, but does not cover n32. Adding support for n32 would be a major undertaking. Without adding this encoding, builds of gcc will fail with errors including (but not limited to) the following: ``` In file included from ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp:21: ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp:75:38: error: static assertion failed 75 | COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat)); | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_internal_defs.h:348:44: note: in definition of macro 'COMPILER_CHECK' 348 | #define COMPILER_CHECK(pred) static_assert(pred, "") | ^~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp:75:38: note: the comparison reduces to '(144 == 160)' 75 | COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat)); | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_internal_defs.h:348:44: note: in definition of macro 'COMPILER_CHECK' 348 | #define COMPILER_CHECK(pred) static_assert(pred, "") | ^~~~ ... In file included from ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:184: ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp: In function '__sanitizer::uptr __sanitizer::internal_mmap(void*, uptr, int, int, int, u64)': ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc:19:24: error: '__NR_mmap2' was not declared in this scope 19 | # define SYSCALL(name) __NR_ ## name | ^~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:198:27: note: in expansion of macro 'SYSCALL' 198 | return internal_syscall(SYSCALL(mmap2), addr, length, prot, flags, fd, | ^~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp: In function 'void __sanitizer::stat64_to_stat(stat64*, stat*)': ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:279:23: error: 'struct stat64' has no member named 'st_atim'; did you mean 'st_atime'? 279 | out->st_atime = in->st_atime; | ^~~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:280:23: error: 'struct stat64' has no member named 'st_mtim'; did you mean 'st_mtime'? 280 | out->st_mtime = in->st_mtime; | ^~~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:281:23: error: 'struct stat64' has no member named 'st_ctim'; did you mean 'st_ctime'? 281 | out->st_ctime = in->st_ctime; | ^~~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp: In function '__sanitizer::uptr __sanitizer::internal_stat(const char*, void*)': ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc:19:24: error: '__NR_stat64' was not declared in this scope 19 | # define SYSCALL(name) __NR_ ## name | ^~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:353:30: note: in expansion of macro 'SYSCALL' 353 | int res = internal_syscall(SYSCALL(stat64), path, &buf64); | ^~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp: In function '__sanitizer::uptr __sanitizer::internal_lstat(const char*, void*)': ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc:19:24: error: '__NR_lstat64' was not declared in this scope 19 | # define SYSCALL(name) __NR_ ## name | ^~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:378:30: note: in expansion of macro 'SYSCALL' 378 | int res = internal_syscall(SYSCALL(lstat64), path, &buf64); | ^~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp: In function '__sanitizer::uptr __sanitizer::internal_fstat(fd_t, void*)': ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc:19:24: error: '__NR_fstat64' was not declared in this scope 19 | # define SYSCALL(name) __NR_ ## name | ^~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:397:30: note: in expansion of macro 'SYSCALL' 397 | int res = internal_syscall(SYSCALL(fstat64), fd, &buf64); | ^~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp: At global scope: ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp:303:13: warning: 'void __sanitizer::kernel_stat_to_stat(kernel_stat*, stat*)' defined but not used [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunused-function-Wunused-function8;;] 303 | static void kernel_stat_to_stat(struct kernel_stat *in, struct stat *out) { | ^~~~~~~~~~~~~~~~~~~ mv -f .deps/sanitizer_mutex.Tpo .deps/sanitizer_mutex.Plo make[4]: *** [Makefile:617: sanitizer_linux.lo] Error 1 mv -f .deps/sancov_flags.Tpo .deps/sancov_flags.Plo ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_posix.cpp: In function '__sanitizer::fd_t __sanitizer::OpenFile(const char*, FileAccessMode, error_t*)': ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_posix.cpp:162:27: warning: 'flags' may be used uninitialized [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmaybe-uninitialized-Wmaybe-uninitialized8;;] 162 | fd_t res = internal_open(filename, flags, 0660); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ ../../../../gcc-12.2.0/libsanitizer/sanitizer_common/sanitizer_posix.cpp:156:7: note: 'flags' was declared here 156 | int flags; | ^~~~~ ``` --- pkgs/development/compilers/gcc/common/platform-flags.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/compilers/gcc/common/platform-flags.nix b/pkgs/development/compilers/gcc/common/platform-flags.nix index c0593cd781ed..90153be10516 100644 --- a/pkgs/development/compilers/gcc/common/platform-flags.nix +++ b/pkgs/development/compilers/gcc/common/platform-flags.nix @@ -25,4 +25,5 @@ in lib.concatLists [ "--with-long-double-128" "--with-long-double-format=${gcc.long-double-format or "ieee"}" ])) + (lib.optional targetPlatform.isMips64n32 "--disable-libsanitizer") # libsanitizer does not compile on mips64n32 ]