diff mbox

[0/13] Add musl support to GCC

Message ID 5549FCA6.2020302@arm.com
State New
Headers show

Commit Message

Szabolcs Nagy May 6, 2015, 11:36 a.m. UTC
On 30/04/15 00:18, Joseph Myers wrote:
> On Wed, 29 Apr 2015, Szabolcs Nagy wrote:
>> only affects [u]int_fastN_t types
>> (on 64bit systems for N=16,32 musl uses int but glibc uses long)
>>
>> i can fix glibc-stdint.h, but it's yet another way in which the
>> compiler is tied to a particular libc.
>>
...
>> (i'd prefer if the compiler did not know about these types, but
...
> 
> The compiler also needs to know these types for the Fortran C bindings.
> 

This is a work around patch so -mmusl or default musl libc
changes the [U]INT_FAST{16,32}_TYPE macro definitions.

The undef/define logic is needed because glibc-stdint.h is
used on non-linux targets where OPTION_MUSL would not be
defined and it is used both before and after config/linux.h on
various linux targets.

I did not find any cleaner workaround. (Separate musl-stdint.h
would need significant changes in config.gcc.)

gcc/Changelog:

2015-05-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* config/glibc-stdint.h (OPTION_MUSL): Define.
	(INT_FAST16_TYPE, INT_FAST32_TYPE, UINT_FAST16_TYPE, UINT_FAST32_TYPE):
	Change the definition based on OPTION_MUSL for 64 bit targets.

	* config/linux.h (OPTION_MUSL): Redefine.
	* config/alpha/linux.h (OPTION_MUSL): Redefine.
	* config/rs6000/linux.h (OPTION_MUSL): Redefine.
	* config/rs6000/linux64.h (OPTION_MUSL): Redefine.

Comments

Jeff Law May 7, 2015, 6:07 p.m. UTC | #1
On 05/06/2015 05:36 AM, Szabolcs Nagy wrote:
>
> On 30/04/15 00:18, Joseph Myers wrote:
>> On Wed, 29 Apr 2015, Szabolcs Nagy wrote:
>>> only affects [u]int_fastN_t types
>>> (on 64bit systems for N=16,32 musl uses int but glibc uses long)
>>>
>>> i can fix glibc-stdint.h, but it's yet another way in which the
>>> compiler is tied to a particular libc.
>>>
> ...
>>> (i'd prefer if the compiler did not know about these types, but
> ...
>>
>> The compiler also needs to know these types for the Fortran C bindings.
>>
>
> This is a work around patch so -mmusl or default musl libc
> changes the [U]INT_FAST{16,32}_TYPE macro definitions.
>
> The undef/define logic is needed because glibc-stdint.h is
> used on non-linux targets where OPTION_MUSL would not be
> defined and it is used both before and after config/linux.h on
> various linux targets.
>
> I did not find any cleaner workaround. (Separate musl-stdint.h
> would need significant changes in config.gcc.)
>
> gcc/Changelog:
>
> 2015-05-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>
>
> 	* config/glibc-stdint.h (OPTION_MUSL): Define.
> 	(INT_FAST16_TYPE, INT_FAST32_TYPE, UINT_FAST16_TYPE, UINT_FAST32_TYPE):
> 	Change the definition based on OPTION_MUSL for 64 bit targets.
>
> 	* config/linux.h (OPTION_MUSL): Redefine.
> 	* config/alpha/linux.h (OPTION_MUSL): Redefine.
> 	* config/rs6000/linux.h (OPTION_MUSL): Redefine.
> 	* config/rs6000/linux64.h (OPTION_MUSL): Redefine.
I really don't like the MUSL bits inside glibc-stdint.h.  But I don't 
see an easy way to avoid it.

OK for the trunk.

jeff
Kyrylo Tkachov May 8, 2015, 8:31 a.m. UTC | #2
On 07/05/15 19:07, Jeff Law wrote:
> On 05/06/2015 05:36 AM, Szabolcs Nagy wrote:
>> On 30/04/15 00:18, Joseph Myers wrote:
>>> On Wed, 29 Apr 2015, Szabolcs Nagy wrote:
>>>> only affects [u]int_fastN_t types
>>>> (on 64bit systems for N=16,32 musl uses int but glibc uses long)
>>>>
>>>> i can fix glibc-stdint.h, but it's yet another way in which the
>>>> compiler is tied to a particular libc.
>>>>
>> ...
>>>> (i'd prefer if the compiler did not know about these types, but
>> ...
>>> The compiler also needs to know these types for the Fortran C bindings.
>>>
>> This is a work around patch so -mmusl or default musl libc
>> changes the [U]INT_FAST{16,32}_TYPE macro definitions.
>>
>> The undef/define logic is needed because glibc-stdint.h is
>> used on non-linux targets where OPTION_MUSL would not be
>> defined and it is used both before and after config/linux.h on
>> various linux targets.
>>
>> I did not find any cleaner workaround. (Separate musl-stdint.h
>> would need significant changes in config.gcc.)
>>
>> gcc/Changelog:
>>
>> 2015-05-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>
>>
>> 	* config/glibc-stdint.h (OPTION_MUSL): Define.
>> 	(INT_FAST16_TYPE, INT_FAST32_TYPE, UINT_FAST16_TYPE, UINT_FAST32_TYPE):
>> 	Change the definition based on OPTION_MUSL for 64 bit targets.
>>
>> 	* config/linux.h (OPTION_MUSL): Redefine.
>> 	* config/alpha/linux.h (OPTION_MUSL): Redefine.
>> 	* config/rs6000/linux.h (OPTION_MUSL): Redefine.
>> 	* config/rs6000/linux64.h (OPTION_MUSL): Redefine.
> I really don't like the MUSL bits inside glibc-stdint.h.  But I don't
> see an easy way to avoid it.
>
> OK for the trunk.

I've committed this on Szabolcs' behalf with r222905.

Kyrill

>
> jeff
>
diff mbox

Patch

diff --git a/gcc/config/alpha/linux.h b/gcc/config/alpha/linux.h
index c567f43..475ea06 100644
--- a/gcc/config/alpha/linux.h
+++ b/gcc/config/alpha/linux.h
@@ -61,10 +61,14 @@  along with GCC; see the file COPYING3.  If not see
 #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
+#undef OPTION_MUSL
+#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
 #else
 #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
+#undef OPTION_MUSL
+#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
 #endif
 
 /* Determine what functions are present at the runtime;
diff --git a/gcc/config/glibc-stdint.h b/gcc/config/glibc-stdint.h
index 3fc67dc..98f4f04 100644
--- a/gcc/config/glibc-stdint.h
+++ b/gcc/config/glibc-stdint.h
@@ -22,6 +22,12 @@  a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+/* Systems using musl libc should use this header and make sure
+   OPTION_MUSL is defined correctly before using the TYPE macros. */
+#ifndef OPTION_MUSL
+#define OPTION_MUSL 0
+#endif
+
 #define SIG_ATOMIC_TYPE "int"
 
 #define INT8_TYPE "signed char"
@@ -43,12 +49,12 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UINT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
 
 #define INT_FAST8_TYPE "signed char"
-#define INT_FAST16_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
-#define INT_FAST32_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
+#define INT_FAST16_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long int" : "int")
+#define INT_FAST32_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long int" : "int")
 #define INT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
 #define UINT_FAST8_TYPE "unsigned char"
-#define UINT_FAST16_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
-#define UINT_FAST32_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
+#define UINT_FAST16_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long unsigned int" : "unsigned int")
+#define UINT_FAST32_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long unsigned int" : "unsigned int")
 #define UINT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
 
 #define INTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index b551c56..7bc87ab 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -32,11 +32,13 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
+#undef OPTION_MUSL
 #define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
 #else
 #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
+#undef OPTION_MUSL
 #define OPTION_MUSL   (linux_libc == LIBC_MUSL)
 #endif
 
diff --git a/gcc/config/rs6000/linux.h b/gcc/config/rs6000/linux.h
index fe0ebd6..a68ff69 100644
--- a/gcc/config/rs6000/linux.h
+++ b/gcc/config/rs6000/linux.h
@@ -30,10 +30,14 @@ 
 #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
+#undef OPTION_MUSL
+#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
 #else
 #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
+#undef OPTION_MUSL
+#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
 #endif
 
 /* Determine what functions are present at the runtime;
diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index 0879e7e..1b7f695 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -299,10 +299,14 @@  extern int dot_symbols;
 #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
+#undef OPTION_MUSL
+#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
 #else
 #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
+#undef OPTION_MUSL
+#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
 #endif
 
 /* Determine what functions are present at the runtime;