From: Didier Kryn <kryn@in2p3.fr>
To: musl@lists.openwall.com
Subject: Building musl-cross-make with gnat in musl environement
Date: Thu, 30 Nov 2017 17:30:35 +0100 [thread overview]
Message-ID: <d73f9451-e64a-57c0-5e6b-2b26067afcdf@in2p3.fr> (raw)
In-Reply-To: <69c03d16-1946-d4e3-f909-2bd2196afe97@in2p3.fr>
[-- Attachment #1: Type: text/plain, Size: 2849 bytes --]
Le 02/11/2017 à 10:44, Didier Kryn a écrit :
> I report the successfull build of the cross-compiler
> x86_64-musl-gcc-6.3.0 - understanding Ada - on x86_64 Debian Wheezy.
>
> The toolchain for build was gcc-6.3.0 for Linux-Gnu provided by
> Adacore.The build toolchain to build major version 6 must be at least
> major version 5.
>
> Of course, the language option must be
> '--enable-languages=ada,c,c++' .
>
> Three patches were necessary:
> gnat63-terminals.diff: removes a #include <termio.h> in a C
> source file.
> gnat63-prj-attr.diff: corrects the layout of a record in an Ada
> source file to prevent a warning concerning performance.
> gnat63-xr_tabls.diff: same as the previous.
In a glibc environment, x86_64-musl-gcc-6.3.0 builds without error
with the three patches I have previously reported. To check there is no
leak of the glibc native toolchain into the cross-compiler, I tried the
build in a musl chroot (without any glibc headers or library), still
with '--enable-languages=ada,c,c++'.
In a first attempt, the compilation fails with the following error:
----------------------------------------
In file included from ../../src_toolchain/gcc/ada/adaint.h:290:0,
from ../../src_toolchain/gcc/ada/adadecode.c:45:
/usr/pkg/gcc-6.3/lib/gcc/x86_64-pc-linux-musl/6.3.0/../../../../x86_64-pc-linux-musl/include/sched.h:76:7:
error: attempt to use poisoned "calloc"
void *calloc(size_t, size_t);
^
/usr/pkg/gcc-6.3/lib/gcc/x86_64-pc-linux-musl/6.3.0/../../../../x86_64-pc-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)))
----------------------------------------
The Ada language has "tasking" primitives, which are nowadays based
on POSIX threads. For this, adaint.h and other files include <sched.h>
which, unfortunately, contains a declaration of calloc() and references
to it. This is unfortunate because calloc() is poisoned by gcc, to
avoid interferences with its own allocation functions, and Gnat does
only need a small part of sched.h.
There must be a necessity, specific to musl, to make use of
calloc() in sched.h, because glibc doesn't do so.
A workaround, provided by the patch gnat63-adaint.diff, is to
replace #include <sched.h> with the few lines of this file actually
needed in adaint.h. The patch contains also #define _SCHED_H, which is
necessary to prevent the inclusion of sched.h by other files, directly
or indirectly.
With this additional patch, x86_64-musl-gcc-6.3.0 builds without
error both in a glibc environement and in a musl environment.
Didier
[-- Attachment #2: gnat63-adaint.diff --]
[-- Type: text/x-patch, Size: 1236 bytes --]
--- gcc-6.3.0-A/gcc/ada/adaint.c
+++ gcc-6.3.0-B/gcc/ada/adaint.c
@@ -3086,7 +3086,7 @@
#endif
#if defined (__linux__)
-#include <sched.h>
+/* do not #include <sched.h> */
/* glibc versions earlier than 2.7 do not define the routines to handle
dynamically allocated CPU sets. For these targets, we use the static
--- gcc-6.3.0-A/gcc/ada/adaint.h
+++ gcc-6.3.0-B/gcc/ada/adaint.h
@@ -287,7 +287,17 @@
/* Routines for interface to required CPU set primitives */
-#include <sched.h>
+/* Do not #include <sched.h>, but copy part of it and prevent its inclusion */
+# ifndef _SCHED_H
+# define _SCHED_H
+typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t;
+# define CPU_ZERO_S(size,set) memset(set,0,size)
+# define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
+# define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
+ (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) )
+# define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=)
+# define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
+# endif
extern cpu_set_t *__gnat_cpu_alloc (size_t);
extern size_t __gnat_cpu_alloc_size (size_t);
next prev parent reply other threads:[~2017-11-30 16:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-02 9:44 Successfull build of gnat-6.3.0 with musl-cross-make Didier Kryn
2017-11-05 18:01 ` Rich Felker
2017-11-05 20:35 ` Didier Kryn
2017-11-30 16:30 ` Didier Kryn [this message]
2017-11-30 17:06 ` Building musl-cross-make with gnat in musl environement Rich Felker
2017-12-01 7:31 ` Didier Kryn
2017-12-13 9:29 ` Didier Kryn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d73f9451-e64a-57c0-5e6b-2b26067afcdf@in2p3.fr \
--to=kryn@in2p3.fr \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).