如何使用 GCC 避免 "attempt to use poisoned malloc/calloc" 错误?

How to circumvent "attempt to use poisoned malloc/calloc" errors with GCC?

我正在使用交叉 musl 编译器(相同版本)构建本机 musl 编译器 (GCC 8.3.0),但出现此错误:

In file included from /usr/local/x86_64-cros-linux-musl/include/pthread.h:30,
                 from /usr/local/x86_64-cros-linux-musl/lib/gcc/x86_64-cros-linux-musl/8.3.0/include/c++/x86_64-cros-linux-musl/bits/gthr-default.h:35,
                 from /usr/local/x86_64-cros-linux-musl/lib/gcc/x86_64-cros-linux-musl/8.3.0/include/c++/x86_64-cros-linux-musl/bits/gthr.h:148,
                 from /usr/local/x86_64-cros-linux-musl/lib/gcc/x86_64-cros-linux-musl/8.3.0/include/c++/ext/atomicity.h:35,
                 from /usr/local/x86_64-cros-linux-musl/lib/gcc/x86_64-cros-linux-musl/8.3.0/include/c++/bits/basic_string.h:39,
                 from /usr/local/x86_64-cros-linux-musl/lib/gcc/x86_64-cros-linux-musl/8.3.0/include/c++/string:52,
                 from ../../gcc-8.3.0/gcc/brig/brigfrontend/brig-to-generic.h:25,
                 from ../../gcc-8.3.0/gcc/brig/brig-lang.c:46:
/usr/local/x86_64-cros-linux-musl/include/sched.h:76:7: error: attempt to use poisoned "calloc"
 void *calloc(size_t, size_t);
       ^
/usr/local/x86_64-cros-linux-musl/include/sched.h:116:36: error: attempt to use poisoned "calloc"
 #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
                                    ^

关于如何规避此问题的任何想法?

详情:

target/host 三元组:x86_64-linux-musl

musl 版本:1.1.21

我在这里应用了 musl 补丁:http://port70.net/~nsz/musl/gcc-8.2.0/

而且我在源目录中运行这个命令:

sed -e '/m64=/s/lib64/lib/' -i gcc/config/i386/t-linux64

我在构建 gcc 时遇到了与 malloc 类似的问题,我通过将 malloc 调用更改为 'xmalloc' 来修复它,我做了一个 grep 并且有一个 'xcalloc' 可用。

所以我将继续并假设 #pragma poison calloc 在您的头文件中而不是在系统头文件中。

推荐的通用解决方案:在使用前包括所有系统头文件#pragma poison;当多个程序头时,这可能会变得棘手,但确实需要完成。

另一种方法是直接从源代码中移除 #pragma poison 和保护措施。