Bug 104799 - Header issue with x86_64-linux-musl based cross-compiler
Summary: Header issue with x86_64-linux-musl based cross-compiler
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libcc1 (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 12.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-05 17:25 UTC by Francois-Xavier Coudert
Modified: 2022-10-27 02:23 UTC (History)
5 users (show)

See Also:
Host:
Target: x86_64-linux-musl
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch for poisoned calloc on Musl systems (273 bytes, patch)
2022-03-05 18:37 UTC, Mosè Giordano
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2022-03-05 17:25:04 UTC
Trying to build a cross-compiler for build == host == x86_64-linux-musl (Alpine Linux 3.15) and target == aarch64-apple-darwin leads to the following build error:

[12:57:48] libtool: compile:  x86_64-linux-musl-g++ -DHAVE_CONFIG_H -I. -I/workspace/srcdir/gcc-darwin-arm64/libcc1 -I /workspace/srcdir/gcc-darwin-arm64/libcc1/../include -I /workspace/srcdir/gcc-darwin-arm64/libcc1/../libgcc -I ../gcc -I/workspace/srcdir/gcc-darwin-arm64/libcc1/../gcc -I /workspace/srcdir/gcc-darwin-arm64/libcc1/../gcc/c -I/workspace/srcdir/gcc_build/./gmp -I/workspace/srcdir/gcc-darwin-arm64/gmp -I/workspace/srcdir/gcc_build/./mpfr/src -I/workspace/srcdir/gcc-darwin-arm64/mpfr/src -I/workspace/srcdir/gcc-darwin-arm64/mpc/src -I /workspace/srcdir/gcc-darwin-arm64/libcc1/../gcc/c-family -I /workspace/srcdir/gcc-darwin-arm64/libcc1/../libcpp/include -W -Wall -fvisibility=hidden -fcf-protection -g -O2 -MT libcc1plugin.lo -MD -MP -MF .deps/libcc1plugin.Tpo -c /workspace/srcdir/gcc-darwin-arm64/libcc1/libcc1plugin.cc  -fPIC -DPIC -o .libs/libcc1plugin.o
[12:57:49] In file included from /usr/include/pthread.h:30,
[12:57:49]                  from /usr/include/c++/10.3.1/x86_64-alpine-linux-musl/bits/gthr-default.h:35,
[12:57:49]                  from /usr/include/c++/10.3.1/x86_64-alpine-linux-musl/bits/gthr.h:148,
[12:57:49]                  from /usr/include/c++/10.3.1/ext/atomicity.h:35,
[12:57:49]                  from /usr/include/c++/10.3.1/memory:75,
[12:57:49]                  from /workspace/srcdir/gcc-darwin-arm64/libcc1/deleter.hh:23,
[12:57:49]                  from /workspace/srcdir/gcc-darwin-arm64/libcc1/rpc.hh:25,
[12:57:49]                  from /workspace/srcdir/gcc-darwin-arm64/libcc1/libcc1plugin.cc:67:
[12:57:49] /usr/include/sched.h:84:7: error: attempt to use poisoned "calloc"
[12:57:49]    84 | void *calloc(size_t, size_t);
[12:57:49]       |       ^
[12:57:49] /usr/include/sched.h:124:36: error: attempt to use poisoned "calloc"
[12:57:49]   124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
[12:57:49]       |                                    ^


This was reported on the Iain Sandoe's GCC branch, but appears to be generic (i.e., not specific to aarch64 at all). It seems like it's an issue with musl headers, and there has been a similar issue reported in libgccjit before, at gentoo: https://bugs.gentoo.org/828580 (for which Alpine is shipping a patch: https://git.alpinelinux.org/aports/tree/main/gcc/0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch?id=dae75528cea4d8ea8e110dd4a2fbd454cc686d15)
Comment 1 Francois-Xavier Coudert 2022-03-05 17:27:17 UTC
Should have added a link to the original report: https://github.com/iains/gcc-darwin-arm64/issues/84
Comment 2 Mosè Giordano 2022-03-05 18:37:37 UTC
Created attachment 52568 [details]
Patch for poisoned calloc on Musl systems

Following the example of https://git.alpinelinux.org/aports/tree/main/gcc/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch, reported in https://bugs.gentoo.org/828580, I wrote the attached patch for libcc1, which seems to solve the issue for me.
Comment 3 Lance Fredrickson 2022-05-25 14:39:30 UTC
Similar? to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105632
Comment 4 Sergei Trofimovich 2022-07-02 15:35:35 UTC
> libcc1/libcc1plugin.cc

(In reply to Mosè Giordano from comment #2)
> Created attachment 52568 [details]
> Patch for poisoned calloc on Musl systems
> 
> Following the example of
> https://git.alpinelinux.org/aports/tree/main/gcc/0042-Fix-attempt-to-use-
> poisoned-calloc-error-in-libgccji.patch, reported in
> https://bugs.gentoo.org/828580, I wrote the attached patch for libcc1, which
> seems to solve the issue for me.

I think the change looks reasonable. Should be fixed by "c++: avoid <memory> poisoning on musl [PR106102]" patch from PR106102 in master and gcc-12 branches.

Can you give it a try?