mailing list of musl libc
 help / color / mirror / code / Atom feed
* Successfull build of gnat-6.3.0 with musl-cross-make
@ 2017-11-02  9:44 Didier Kryn
  2017-11-05 18:01 ` Rich Felker
  2017-11-30 16:30 ` Building musl-cross-make with gnat in musl environement Didier Kryn
  0 siblings, 2 replies; 7+ messages in thread
From: Didier Kryn @ 2017-11-02  9:44 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]

     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.

     Note on static linking:
     Compilation of Ada program is often made in one invocation of 
gnatmake, which calls gcc, gnatbind and gnatlink. By default, gnatmake 
links everything statically, except the libc (probably a gnuism). If the 
option -shared is given, then it links everything dynamically. The 
option -static is ignored by gnatmake.
     However, it is possible to produce static executables by invoking 
gcc -c, gnatbind, andgnatlink, because gnatlink honours the -static option.

     I attach the patches in case someone is interested.

     I was able to compile a native x86_64-pc-linux-musl-gcc-6.3.0 (with 
the 3 steps) using this cross-compiler for build.

                 Didier

[-- Attachment #2: gnat63-terminals.diff --]
[-- Type: text/x-patch, Size: 597 bytes --]

diff -rupN gcc-6.3.0-A/gcc/ada/terminals.c gcc-6.3.0-B/gcc/ada/terminals.c
--- gcc-6.3.0-A/gcc/ada/terminals.c	2016-02-12 00:53:54.000000000 +0100
+++ gcc-6.3.0-B/gcc/ada/terminals.c	2017-10-13 08:17:35.000000000 +0200
@@ -1068,12 +1068,6 @@ __gnat_setup_winsize (void *desc, int ro
 #include <stdio.h>
 #include <stdlib.h>
 
-/* On some system termio is either absent or including it will disable termios
-   (HP-UX) */
-#if !defined (__hpux__) && !defined (BSD) && !defined (__APPLE__) \
-  && !defined (__rtems__)
-#   include <termio.h>
-#endif
 
 #include <sys/ioctl.h>
 #include <termios.h>

[-- Attachment #3: gnat63-prj-attr.diff --]
[-- Type: text/x-patch, Size: 932 bytes --]

diff -rupN gcc-6.3.0-A/gcc/ada/prj-attr.ads gcc-6.3.0-B/gcc/ada/prj-attr.ads
--- gcc-6.3.0-A/gcc/ada/prj-attr.ads	2014-08-04 11:55:01.000000000 +0200
+++ gcc-6.3.0-B/gcc/ada/prj-attr.ads	2017-11-01 20:31:11.000000000 +0100
@@ -86,9 +86,6 @@ package Prj.Attr is
      Positive range 1 .. Max_Attribute_Name_Length;
 
    type Attribute_Data (Name_Length : Attribute_Name_Length := 1) is record
-      Name : String (1 .. Name_Length);
-      --  The name of the attribute
-
       Attr_Kind  : Defined_Attribute_Kind;
       --  The type of the attribute
 
@@ -111,6 +108,8 @@ package Prj.Attr is
       --  The value of the attribute when referenced if the attribute has not
       --  yet been declared.
 
+      Name : String (1 .. Name_Length);
+      --  The name of the attribute
    end record;
    --  Name and characteristics of an attribute in a package registered
    --  explicitly with Register_New_Package (see below).

[-- Attachment #4: gnat63-xr_tabls.diff --]
[-- Type: text/x-patch, Size: 1451 bytes --]

diff -rupN gcc-6.3.0-A/gcc/ada/xr_tabls.ads gcc-6.3.0-B/gcc/ada/xr_tabls.ads
--- gcc-6.3.0-A/gcc/ada/xr_tabls.ads	2014-08-01 11:38:48.000000000 +0200
+++ gcc-6.3.0-B/gcc/ada/xr_tabls.ads	2017-10-13 08:50:24.000000000 +0200
@@ -292,12 +292,11 @@ package Xr_Tabls is
 
 private
    type Project_File (Src_Dir_Length, Obj_Dir_Length : Natural) is record
-      Src_Dir : String (1 .. Src_Dir_Length);
       Src_Dir_Index : Integer;
-
-      Obj_Dir            : String (1 .. Obj_Dir_Length);
       Obj_Dir_Index      : Integer;
       Last_Obj_Dir_Start : Natural;
+      Src_Dir : String (1 .. Src_Dir_Length);
+      Obj_Dir            : String (1 .. Obj_Dir_Length);
    end record;
 
    type Project_File_Ptr is access all Project_File;
@@ -364,7 +363,6 @@ private
 
    type Declaration_Record (Symbol_Length : Natural) is record
       Key          : Cst_String_Access;
-      Symbol       : String (1 .. Symbol_Length);
       Decl         : Reference;
       Is_Parameter : Boolean := False; -- True if entity is subprog param
       Decl_Type    : Character;
@@ -374,6 +372,7 @@ private
       Match        : Boolean := False;
       Par_Symbol   : Declaration_Reference := null;
       Next         : Declaration_Reference := null;
+      Symbol       : String (1 .. Symbol_Length);
    end record;
    --  The lists of referenced (Body_Ref, Ref_Ref and Modif_Ref) are
    --  kept unsorted until the results needs to be printed. This saves

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Successfull build of gnat-6.3.0 with musl-cross-make
  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 ` Building musl-cross-make with gnat in musl environement Didier Kryn
  1 sibling, 1 reply; 7+ messages in thread
From: Rich Felker @ 2017-11-05 18:01 UTC (permalink / raw)
  To: musl

On Thu, Nov 02, 2017 at 10:44:13AM +0100, Didier Kryn wrote:
>     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++' .

This is very interesting! Thanks for the report. As an aside, I know
there's been some interest in building GHDL, which depends on GNU Ada;
I'm not sure if this gets us closer to making that work but I suspect
it might.

>     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.

Are the second and third actually necessary, and are they related to
musl at all? If they're actual improvement regardless of libc, they
should probably go upstream in gcc. But if they're needed for now to
make mcm work with ada out of the box, I don't mind including them in
mcm as a convenience.

>     Note on static linking:
>     Compilation of Ada program is often made in one invocation of
> gnatmake, which calls gcc, gnatbind and gnatlink. By default,
> gnatmake links everything statically, except the libc (probably a
> gnuism). If the option -shared is given, then it links everything
> dynamically. The option -static is ignored by gnatmake.
>     However, it is possible to produce static executables by
> invoking gcc -c, gnatbind, andgnatlink, because gnatlink honours the
> -static option.
> 
>     I attach the patches in case someone is interested.
> 
>     I was able to compile a native x86_64-pc-linux-musl-gcc-6.3.0
> (with the 3 steps) using this cross-compiler for build.

Seems there's no reason not to static link libc if everything else is
static too, except for glibc issues with static linking. It might make
sense to change the default for musl target tuples.

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Successfull build of gnat-6.3.0 with musl-cross-make
  2017-11-05 18:01 ` Rich Felker
@ 2017-11-05 20:35   ` Didier Kryn
  0 siblings, 0 replies; 7+ messages in thread
From: Didier Kryn @ 2017-11-05 20:35 UTC (permalink / raw)
  To: musl

Le 05/11/2017 à 19:01, Rich Felker a écrit :
> On Thu, Nov 02, 2017 at 10:44:13AM +0100, Didier Kryn wrote:
>>      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++' .
> This is very interesting! Thanks for the report. As an aside, I know
> there's been some interest in building GHDL, which depends on GNU Ada;
> I'm not sure if this gets us closer to making that work but I suspect
> it might.
>
>>      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.
> Are the second and third actually necessary, and are they related to
> musl at all? If they're actual improvement regardless of libc, they
> should probably go upstream in gcc. But if they're needed for now to
> make mcm work with ada out of the box, I don't mind including them in
> mcm as a convenience.
     The second and third are meant to prevent a warning because the 
compilation is done with option -Werror. They are only related to 
-Werror. But I think this compiler option is sensible considering this 
is a single-step build.

     The patches might be slightly less intrusive: instead of changing 
the layout of the record, it would be enough to insert a pragma to 
disable the warning. But, frankly, the original layout of the record 
only makes the source slightly more readable: a record in Ada is like a 
struct in C or C++. In this case, the first componant is the name which 
is a string of variable length. It makes sense to put the name first but 
it is better for performance that the fixed-size components of a record 
are placed first. Hence the warning. This is a tool for which 
performance isn't critical; this is why the author didn't take care.

>
>>      Note on static linking:
>>      Compilation of Ada program is often made in one invocation of
>> gnatmake, which calls gcc, gnatbind and gnatlink. By default,
>> gnatmake links everything statically, except the libc (probably a
>> gnuism). If the option -shared is given, then it links everything
>> dynamically. The option -static is ignored by gnatmake.
>>      However, it is possible to produce static executables by
>> invoking gcc -c, gnatbind, andgnatlink, because gnatlink honours the
>> -static option.
>>
>>      I attach the patches in case someone is interested.
>>
>>      I was able to compile a native x86_64-pc-linux-musl-gcc-6.3.0
>> (with the 3 steps) using this cross-compiler for build.
> Seems there's no reason not to static link libc if everything else is
> static too, except for glibc issues with static linking. It might make
> sense to change the default for musl target tuples.
     The problem is that it requires a better understanding of the 
program than I have.

     HTH
                         Didier




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building musl-cross-make with gnat in musl environement
  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-30 16:30 ` Didier Kryn
  2017-11-30 17:06   ` Rich Felker
  1 sibling, 1 reply; 7+ messages in thread
From: Didier Kryn @ 2017-11-30 16:30 UTC (permalink / raw)
  To: musl

[-- 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);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Building musl-cross-make with gnat in musl environement
  2017-11-30 16:30 ` Building musl-cross-make with gnat in musl environement Didier Kryn
@ 2017-11-30 17:06   ` Rich Felker
  2017-12-01  7:31     ` Didier Kryn
  2017-12-13  9:29     ` Didier Kryn
  0 siblings, 2 replies; 7+ messages in thread
From: Rich Felker @ 2017-11-30 17:06 UTC (permalink / raw)
  To: musl

On Thu, Nov 30, 2017 at 05:30:35PM +0100, Didier Kryn wrote:
> 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
> 

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

Just patch out the poisoning instead. It's only meaningful to GCC
developers and should _not_ be used in deployment for reasons exactly
like what you discovered here, pretty much the same reasons -Werror
should not be enabled in deployment.

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Building musl-cross-make with gnat in musl environement
  2017-11-30 17:06   ` Rich Felker
@ 2017-12-01  7:31     ` Didier Kryn
  2017-12-13  9:29     ` Didier Kryn
  1 sibling, 0 replies; 7+ messages in thread
From: Didier Kryn @ 2017-12-01  7:31 UTC (permalink / raw)
  To: musl

Le 30/11/2017 à 18:06, Rich Felker a écrit :
> On Thu, Nov 30, 2017 at 05:30:35PM +0100, Didier Kryn wrote:
>> 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
>>
>> --- 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);
> Just patch out the poisoning instead. It's only meaningful to GCC
> developers and should _not_ be used in deployment for reasons exactly
> like what you discovered here, pretty much the same reasons -Werror
> should not be enabled in deployment.
>
> Rich

     Makes sense. Will look at that.

         Didier





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Building musl-cross-make with gnat in musl environement
  2017-11-30 17:06   ` Rich Felker
  2017-12-01  7:31     ` Didier Kryn
@ 2017-12-13  9:29     ` Didier Kryn
  1 sibling, 0 replies; 7+ messages in thread
From: Didier Kryn @ 2017-12-13  9:29 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 464 bytes --]

Le 30/11/2017 à 18:06, Rich Felker a écrit :
> Just patch out the poisoning instead. It's only meaningful to GCC
> developers and should_not_  be used in deployment for reasons exactly
> like what you discovered here, pretty much the same reasons -Werror
> should not be enabled in deployment.

     Here is a new set of patches in this spirit. Posionning of calloc 
is removed and compilation switches are changed for gnattools.

     Didier


[-- Attachment #2: gnat63-no-poison.diff --]
[-- Type: text/x-patch, Size: 317 bytes --]

--- gcc-6.3.0-A/gcc/system.h
+++ gcc-6.3.0-B/gcc/system.h
@@ -819,7 +819,8 @@
 #ifndef USES_ISL
 #undef calloc
 #undef strdup
- #pragma GCC poison calloc strdup
+/* Do not poison calloc because it is declared in musl's sched.h */
+ #pragma GCC poison strdup
 #endif
 
 #if !defined(FLEX_SCANNER) && !defined(YYBISON)

[-- Attachment #3: gnat63-gnattools.diff --]
[-- Type: text/x-patch, Size: 451 bytes --]

diff -rupN gcc-6.3.0-A/gnattools/Makefile.in gcc-6.3.0-B/gnattools/Makefile.in
--- gcc-6.3.0-A/gnattools/Makefile.in	2016-04-04 18:37:58.000000000 +0200
+++ gcc-6.3.0-B/gnattools/Makefile.in	2017-12-06 15:15:01.000000000 +0100
@@ -52,7 +52,7 @@ WARN_CFLAGS = @warn_cflags@
 ADA_CFLAGS=@ADA_CFLAGS@
 
 # Variables for gnattools.
-ADAFLAGS= -gnatpg -gnata
+ADAFLAGS= -gnata
 
 # For finding the GCC build dir, which is used far too much
 GCC_DIR=../gcc

[-- Attachment #4: gnat63-terminals.diff --]
[-- Type: text/x-patch, Size: 597 bytes --]

diff -rupN gcc-6.3.0-A/gcc/ada/terminals.c gcc-6.3.0-B/gcc/ada/terminals.c
--- gcc-6.3.0-A/gcc/ada/terminals.c	2016-02-12 00:53:54.000000000 +0100
+++ gcc-6.3.0-B/gcc/ada/terminals.c	2017-10-13 08:17:35.000000000 +0200
@@ -1068,12 +1068,6 @@ __gnat_setup_winsize (void *desc, int ro
 #include <stdio.h>
 #include <stdlib.h>
 
-/* On some system termio is either absent or including it will disable termios
-   (HP-UX) */
-#if !defined (__hpux__) && !defined (BSD) && !defined (__APPLE__) \
-  && !defined (__rtems__)
-#   include <termio.h>
-#endif
 
 #include <sys/ioctl.h>
 #include <termios.h>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-12-13  9:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` Building musl-cross-make with gnat in musl environement Didier Kryn
2017-11-30 17:06   ` Rich Felker
2017-12-01  7:31     ` Didier Kryn
2017-12-13  9:29     ` Didier Kryn

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