diff mbox

[rs6000,v3] powerpc musl libc support

Message ID 56211E8E.6060004@arm.com
State New
Headers show

Commit Message

Szabolcs Nagy Oct. 16, 2015, 3:58 p.m. UTC
Revision of
https://gcc.gnu.org/ml/gcc-patches/2015-04/msg01640.html

This adds musl libc support to powerpc:

- The dynamic-linker name is /lib/ld-musl-powerpc{64}{le}{-sf}.so.1
- The include order is changed for musl as in linux.h.

New in this revision:

Soft float abi detection through "{msoft-float:-sf}".
(this is imperfect but there is no easy way to determine if the
target is soft float in link spec and this should work for the
common case: a soft float toolchain is built --with-float=soft.)

(secure-plt changes are in separate patches now, this patch applies
on top of
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01501.html
but independent.)

gcc/ChangeLog:

2015-10-16  Gregor Richards  <gregor.richards@uwaterloo.ca>
	    Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* config/rs6000/linux64.h (MUSL_DYNAMIC_LINKER32): Define.
	(MUSL_DYNAMIC_LINKER64): Define.
	(GNU_USER_DYNAMIC_LINKER32): Update.
	(GNU_USER_DYNAMIC_LINKER64): Update.
	(CHOOSE_DYNAMIC_LINKER): Update.

	* config/rs6000/sysv4.h (GNU_USER_DYNAMIC_LINKER): Update.
	(MUSL_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER_E,)
	(INCLUDE_DEFAULTS_MUSL_GPP, INCLUDE_DEFAULTS_MUSL_LOCAL,)
	(INCLUDE_DEFAULTS_MUSL_PREFIX, INCLUDE_DEFAULTS_MUSL_CROSS,)
	(INCLUDE_DEFAULTS_MUSL_TOOL, INCLUDE_DEFAULTS_MUSL_NATIVE): Define.
	(CHOOSE_DYNAMIC_LINKER): Update.

	* config/rs6000/sysv4le.h (MUSL_DYNAMIC_LINKER_E): Define.

Comments

Segher Boessenkool Oct. 16, 2015, 4:35 p.m. UTC | #1
Hi!

On Fri, Oct 16, 2015 at 04:58:06PM +0100, Szabolcs Nagy wrote:
>  #if DEFAULT_LIBC == LIBC_UCLIBC
> -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
> +#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
> +  "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
>  #elif DEFAULT_LIBC == LIBC_GLIBC
> -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
> +#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
> +  "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
> +#elif DEFAULT_LIBC == LIBC_MUSL
> +#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
> +  "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
>  #else
>  #error "Unsupported DEFAULT_LIBC"
>  #endif

This doesn't really scale, I wonder if some more elegant non-quadratic
way is possible?  Not that I expect terribly many other libcs to show
up in the near future ;-)


Segher
Szabolcs Nagy Oct. 16, 2015, 6:23 p.m. UTC | #2
On 16/10/15 17:35, Segher Boessenkool wrote:
> Hi!
>
> On Fri, Oct 16, 2015 at 04:58:06PM +0100, Szabolcs Nagy wrote:
>>   #if DEFAULT_LIBC == LIBC_UCLIBC
>> -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
>> +#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
>> +  "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
>>   #elif DEFAULT_LIBC == LIBC_GLIBC
>> -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
>> +#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
>> +  "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
>> +#elif DEFAULT_LIBC == LIBC_MUSL
>> +#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
>> +  "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
>>   #else
>>   #error "Unsupported DEFAULT_LIBC"
>>   #endif
>
> This doesn't really scale, I wonder if some more elegant non-quadratic
> way is possible?  Not that I expect terribly many other libcs to show
> up in the near future ;-)
>

it is also error prone, but it was easier to use the
existing infrastructure than to figure out a clean way..

i guess the macro could be changed to

#define CHOOSE_LD(G,U,M,D) \
   "%{mglibc:" G ";:" \
   "%{muclibc:" U ";:" \
   "%{mmusl:" M ";:" \
   D \
   "}}}"

where D is the default and then

#if DEFAULT_LIBC == LIBC_UCLIBC
#define DEFAULT_LD UCLIBC_LD
#elif
..
#endif

#define LINUX_LD \
   CHOOSE_LD(GLIBC_LD, UCLIBC_LD, MUSL_LD, DEFAULT_LD)

but then the default dynlinker is listed twice
in the expansion of LINUX_LD.

i don't see an easy way to do this -mlibc logic in
the linkspec.
diff mbox

Patch

diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index 9599735..d7f5709 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -402,19 +402,31 @@  extern int dot_symbols;
 ":%(dynamic_linker_prefix)/lib64/ld64.so.1}"
 #endif
 
+#define MUSL_DYNAMIC_LINKER32 \
+  "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
+#define MUSL_DYNAMIC_LINKER64 \
+  "/lib/ld-musl-powerpc64" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
+
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
 #if DEFAULT_LIBC == LIBC_UCLIBC
-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
+#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
+  "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
 #elif DEFAULT_LIBC == LIBC_GLIBC
-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
+#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
+  "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
+#elif DEFAULT_LIBC == LIBC_MUSL
+#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
+  "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
 #else
 #error "Unsupported DEFAULT_LIBC"
 #endif
 #define GNU_USER_DYNAMIC_LINKER32 \
-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
+			 MUSL_DYNAMIC_LINKER32)
 #define GNU_USER_DYNAMIC_LINKER64 \
-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
+			 MUSL_DYNAMIC_LINKER64)
 
 #undef  DEFAULT_ASM_ENDIAN
 #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index c77bf5c..8c5c4b2 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -761,17 +761,27 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
 
 #define LINK_START_LINUX_SPEC ""
 
+#define MUSL_DYNAMIC_LINKER_E ENDIAN_SELECT("","le","")
+
 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
+#define MUSL_DYNAMIC_LINKER \
+  "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
 #if DEFAULT_LIBC == LIBC_UCLIBC
-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
+#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
+  "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
+#elif DEFAULT_LIBC == LIBC_MUSL
+#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
+  "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
 #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
+#define CHOOSE_DYNAMIC_LINKER(G, U, M) \
+  "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
 #else
 #error "Unsupported DEFAULT_LIBC"
 #endif
 #define GNU_USER_DYNAMIC_LINKER \
-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
+			 MUSL_DYNAMIC_LINKER)
 
 #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
   %{rdynamic:-export-dynamic} \
@@ -956,3 +966,72 @@  ncrtn.o%s"
 /* This target uses the sysv4.opt file.  */
 #define TARGET_USES_SYSV4_OPT 1
 
+/* Include order changes for musl, same as in generic linux.h.  */
+#if DEFAULT_LIBC == LIBC_MUSL
+#define INCLUDE_DEFAULTS_MUSL_GPP			\
+    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,		\
+      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },		\
+    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,		\
+      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },		\
+    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,	\
+      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
+
+#ifdef LOCAL_INCLUDE_DIR
+#define INCLUDE_DEFAULTS_MUSL_LOCAL			\
+    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },		\
+    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
+#else
+#define INCLUDE_DEFAULTS_MUSL_LOCAL
+#endif
+
+#ifdef PREFIX_INCLUDE_DIR
+#define INCLUDE_DEFAULTS_MUSL_PREFIX			\
+    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
+#else
+#define INCLUDE_DEFAULTS_MUSL_PREFIX
+#endif
+
+#ifdef CROSS_INCLUDE_DIR
+#define INCLUDE_DEFAULTS_MUSL_CROSS			\
+    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
+#else
+#define INCLUDE_DEFAULTS_MUSL_CROSS
+#endif
+
+#ifdef TOOL_INCLUDE_DIR
+#define INCLUDE_DEFAULTS_MUSL_TOOL			\
+    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
+#else
+#define INCLUDE_DEFAULTS_MUSL_TOOL
+#endif
+
+#ifdef NATIVE_SYSTEM_HEADER_DIR
+#define INCLUDE_DEFAULTS_MUSL_NATIVE			\
+    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 },	\
+    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
+#else
+#define INCLUDE_DEFAULTS_MUSL_NATIVE
+#endif
+
+#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
+# undef INCLUDE_DEFAULTS_MUSL_LOCAL
+# define INCLUDE_DEFAULTS_MUSL_LOCAL
+# undef INCLUDE_DEFAULTS_MUSL_NATIVE
+# define INCLUDE_DEFAULTS_MUSL_NATIVE
+#else
+# undef INCLUDE_DEFAULTS_MUSL_CROSS
+# define INCLUDE_DEFAULTS_MUSL_CROSS
+#endif
+
+#undef INCLUDE_DEFAULTS
+#define INCLUDE_DEFAULTS				\
+  {							\
+    INCLUDE_DEFAULTS_MUSL_GPP				\
+    INCLUDE_DEFAULTS_MUSL_PREFIX			\
+    INCLUDE_DEFAULTS_MUSL_CROSS				\
+    INCLUDE_DEFAULTS_MUSL_TOOL				\
+    INCLUDE_DEFAULTS_MUSL_NATIVE			\
+    { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 },		\
+    { 0, 0, 0, 0, 0, 0 }				\
+  }
+#endif
diff --git a/gcc/config/rs6000/sysv4le.h b/gcc/config/rs6000/sysv4le.h
index 66ee7ca..f00e8b0 100644
--- a/gcc/config/rs6000/sysv4le.h
+++ b/gcc/config/rs6000/sysv4le.h
@@ -31,3 +31,5 @@ 
 /* Little-endian PowerPC64 Linux uses the ELF v2 ABI by default.  */
 #define LINUX64_DEFAULT_ABI_ELFv2
 
+#undef MUSL_DYNAMIC_LINKER_E
+#define MUSL_DYNAMIC_LINKER_E ENDIAN_SELECT("","le","le")