Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

gcc

musl

I'm building a native musl compiler (GCC 8.3.0) with a cross musl compiler (same version) and I'm getting this error:

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)))
                                    ^

Any ideas on how to circumvent this?

Details:

target/host triple: x86_64-linux-musl

musl version: 1.1.21

I've applied the musl patches here: http://port70.net/~nsz/musl/gcc-8.2.0/

And I've run this command while in the source directory:

sed -e '/m64=/s/lib64/lib/' -i gcc/config/i386/t-linux64
like image 365
S.S. Anne Avatar asked Mar 08 '19 22:03

S.S. Anne


1 Answers

So I'm going to just go ahead and assume that #pragma poison calloc is in your header files rather than in system header files.

Recommended general solution: include all system headers before using #pragma poison; this can get tricky when multiple program headers but it really needs to be done.

The alternative is to just up and remove #pragma poison from the source code and the safeguard with it.

like image 102
Joshua Avatar answered Nov 15 '22 01:11

Joshua