diff mbox series

[RS6000] Use config/linux.h for powerpc*-*-linux*

Message ID 20181112112637.GB22752@bubble.grove.modra.org
State New
Headers show
Series [RS6000] Use config/linux.h for powerpc*-*-linux* | expand

Commit Message

Alan Modra Nov. 12, 2018, 11:26 a.m. UTC
Using the macros in config/linux.h rather than duplicating them helps
stop future bitrot, and repairs existing bitrot (4 choices for libc in
linux.h, fewer in the rs6000 files not that it matters much).  Also
fixes the fact that __gnu_linux__ was always defined rather than just
when glibc was the libc of choice.

Bootstrapped etc. powerpc-linux and powerpc64le-linux.

	* config.gcc (powerpc*-*-linux*): Add linux.h to tm_file.
	* config/rs6000/linux.h (TARGET_OS_CPP_BUILTINS): Use
	GNU_USER_TARGET_OS_CPP_BUILTINS.
	(RS6000_ABI_NAME): Define.
	* config/rs6000/linux64.h (TARGET_OS_CPP_BUILTINS): Use
	GNU_USER_TARGET_OS_CPP_BUILTINS.
	(MUSL_DYNAMIC_LINKER32): Undef before defining.
	(UCLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER64): Don't define.
	(CHOOSE_DYNAMIC_LINKER): Don't define.
	(GNU_USER_DYNAMIC_LINKER32, GNU_USER_DYNAMIC_LINKER64): Don't define.
	* config/rs6000/sysv4.h (MUSL_DYNAMIC_LINKER): Undef before defining.
	(CHOOSE_DYNAMIC_LINKER, GNU_USER_DYNAMIC_LINKER): Only define when
	not already defined.
	(CPP_OS_LINUX_SPEC): Remove defines and asserts handled by
	TARGET_OS_CPP_BUILTINS.

Comments

Segher Boessenkool Nov. 26, 2018, 11:16 p.m. UTC | #1
Hi Alan,

On Mon, Nov 12, 2018 at 09:56:37PM +1030, Alan Modra wrote:
> Using the macros in config/linux.h rather than duplicating them helps
> stop future bitrot, and repairs existing bitrot (4 choices for libc in
> linux.h, fewer in the rs6000 files not that it matters much).  Also
> fixes the fact that __gnu_linux__ was always defined rather than just
> when glibc was the libc of choice.

Sorry for the slow review.  This is okay for trunk.  Thanks!


Segher


> 	* config.gcc (powerpc*-*-linux*): Add linux.h to tm_file.
> 	* config/rs6000/linux.h (TARGET_OS_CPP_BUILTINS): Use
> 	GNU_USER_TARGET_OS_CPP_BUILTINS.
> 	(RS6000_ABI_NAME): Define.
> 	* config/rs6000/linux64.h (TARGET_OS_CPP_BUILTINS): Use
> 	GNU_USER_TARGET_OS_CPP_BUILTINS.
> 	(MUSL_DYNAMIC_LINKER32): Undef before defining.
> 	(UCLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER64): Don't define.
> 	(CHOOSE_DYNAMIC_LINKER): Don't define.
> 	(GNU_USER_DYNAMIC_LINKER32, GNU_USER_DYNAMIC_LINKER64): Don't define.
> 	* config/rs6000/sysv4.h (MUSL_DYNAMIC_LINKER): Undef before defining.
> 	(CHOOSE_DYNAMIC_LINKER, GNU_USER_DYNAMIC_LINKER): Only define when
> 	not already defined.
> 	(CPP_OS_LINUX_SPEC): Remove defines and asserts handled by
> 	TARGET_OS_CPP_BUILTINS.
Alan Modra Nov. 26, 2018, 11:56 p.m. UTC | #2
On Mon, Nov 26, 2018 at 05:16:38PM -0600, Segher Boessenkool wrote:
> On Mon, Nov 12, 2018 at 09:56:37PM +1030, Alan Modra wrote:
> > Using the macros in config/linux.h rather than duplicating them helps
> > stop future bitrot, and repairs existing bitrot (4 choices for libc in
> > linux.h, fewer in the rs6000 files not that it matters much).  Also
> > fixes the fact that __gnu_linux__ was always defined rather than just
> > when glibc was the libc of choice.
> 
> Sorry for the slow review.  This is okay for trunk.  Thanks!

Thanks, committed revision 266493.
Matthias Klose Nov. 28, 2018, 12:12 p.m. UTC | #3
On 27.11.18 00:56, Alan Modra wrote:
> On Mon, Nov 26, 2018 at 05:16:38PM -0600, Segher Boessenkool wrote:
>> On Mon, Nov 12, 2018 at 09:56:37PM +1030, Alan Modra wrote:
>>> Using the macros in config/linux.h rather than duplicating them helps
>>> stop future bitrot, and repairs existing bitrot (4 choices for libc in
>>> linux.h, fewer in the rs6000 files not that it matters much).  Also
>>> fixes the fact that __gnu_linux__ was always defined rather than just
>>> when glibc was the libc of choice.
>>
>> Sorry for the slow review.  This is okay for trunk.  Thanks!
> 
> Thanks, committed revision 266493.

would that be appropriate to backport to the 7 and 8 branches as well?
Alan Modra Nov. 28, 2018, 1:24 p.m. UTC | #4
On Wed, Nov 28, 2018 at 01:12:45PM +0100, Matthias Klose wrote:
> On 27.11.18 00:56, Alan Modra wrote:
> > On Mon, Nov 26, 2018 at 05:16:38PM -0600, Segher Boessenkool wrote:
> >> On Mon, Nov 12, 2018 at 09:56:37PM +1030, Alan Modra wrote:
> >>> Using the macros in config/linux.h rather than duplicating them helps
> >>> stop future bitrot, and repairs existing bitrot (4 choices for libc in
> >>> linux.h, fewer in the rs6000 files not that it matters much).  Also
> >>> fixes the fact that __gnu_linux__ was always defined rather than just
> >>> when glibc was the libc of choice.
> >>
> >> Sorry for the slow review.  This is okay for trunk.  Thanks!
> > 
> > Thanks, committed revision 266493.
> 
> would that be appropriate to backport to the 7 and 8 branches as well?

Well, the patch does fix a bug regarding the __gnu_linux__ define, but
no one complained about that as far as I know.  So I don't regard it
as important.
Segher Boessenkool Nov. 28, 2018, 4:19 p.m. UTC | #5
On Wed, Nov 28, 2018 at 11:54:55PM +1030, Alan Modra wrote:
> On Wed, Nov 28, 2018 at 01:12:45PM +0100, Matthias Klose wrote:
> > On 27.11.18 00:56, Alan Modra wrote:
> > > On Mon, Nov 26, 2018 at 05:16:38PM -0600, Segher Boessenkool wrote:
> > >> On Mon, Nov 12, 2018 at 09:56:37PM +1030, Alan Modra wrote:
> > >>> Using the macros in config/linux.h rather than duplicating them helps
> > >>> stop future bitrot, and repairs existing bitrot (4 choices for libc in
> > >>> linux.h, fewer in the rs6000 files not that it matters much).  Also
> > >>> fixes the fact that __gnu_linux__ was always defined rather than just
> > >>> when glibc was the libc of choice.
> > >>
> > >> Sorry for the slow review.  This is okay for trunk.  Thanks!
> > > 
> > > Thanks, committed revision 266493.
> > 
> > would that be appropriate to backport to the 7 and 8 branches as well?
> 
> Well, the patch does fix a bug regarding the __gnu_linux__ define, but
> no one complained about that as far as I know.  So I don't regard it
> as important.

It also would need a lot of testing.  Yeah, let's not backport this.


Segher
diff mbox series

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b960de34e54..75ff2f5658e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2643,7 +2643,7 @@  powerpc*-*-linux*spe*)
 	tm_file="${tm_file} powerpcspe/linuxspe.h powerpcspe/e500.h"
 	;;
 powerpc*-*-linux*)
-	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h freebsd-spec.h rs6000/sysv4.h"
+	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h freebsd-spec.h rs6000/sysv4.h"
 	extra_options="${extra_options} rs6000/sysv4.opt"
 	tmake_file="${tmake_file} rs6000/t-fprules rs6000/t-ppccomm"
 	extra_objs="$extra_objs rs6000-linux.o"
diff --git a/gcc/config/rs6000/linux.h b/gcc/config/rs6000/linux.h
index fd06b14d837..29653c13455 100644
--- a/gcc/config/rs6000/linux.h
+++ b/gcc/config/rs6000/linux.h
@@ -46,15 +46,17 @@ 
 #define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function
 
 #undef  TARGET_OS_CPP_BUILTINS
-#define TARGET_OS_CPP_BUILTINS()		\
-  do						\
-    {						\
-      builtin_define_std ("PPC");		\
-      builtin_define_std ("powerpc");		\
-      builtin_assert ("cpu=powerpc");		\
-      builtin_assert ("machine=powerpc");	\
-      TARGET_OS_SYSV_CPP_BUILTINS ();		\
-    }						\
+#define TARGET_OS_CPP_BUILTINS()			\
+  do							\
+    {							\
+      if (strcmp (rs6000_abi_name, "linux") == 0)	\
+	GNU_USER_TARGET_OS_CPP_BUILTINS();		\
+      builtin_define_std ("PPC");			\
+      builtin_define_std ("powerpc");			\
+      builtin_assert ("cpu=powerpc");			\
+      builtin_assert ("machine=powerpc");		\
+      TARGET_OS_SYSV_CPP_BUILTINS ();			\
+    }							\
   while (0)
 
 #define GNU_USER_TARGET_D_OS_VERSIONS()		\
@@ -126,6 +128,9 @@ 
 #define RELOCATABLE_NEEDS_FIXUP \
   (rs6000_isa_flags & rs6000_isa_flags_explicit & OPTION_MASK_RELOCATABLE)
 
+#undef	RS6000_ABI_NAME
+#define	RS6000_ABI_NAME "linux"
+
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* ppc32 glibc provides __stack_chk_guard in -0x7008(2).  */
 #define TARGET_THREAD_SSP_OFFSET	-0x7008
diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index 0d8e164a598..b1818b43cf4 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -369,6 +369,8 @@  extern int dot_symbols;
 #define TARGET_OS_CPP_BUILTINS()			\
   do							\
     {							\
+      if (strcmp (rs6000_abi_name, "linux") == 0)	\
+	GNU_USER_TARGET_OS_CPP_BUILTINS();		\
       if (TARGET_64BIT)					\
 	{						\
 	  builtin_define ("__PPC__");			\
@@ -438,32 +440,13 @@  extern int dot_symbols;
 ":%(dynamic_linker_prefix)/lib64/ld64.so.1}"
 #endif
 
+#undef MUSL_DYNAMIC_LINKER32
 #define MUSL_DYNAMIC_LINKER32 \
   "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
+#undef MUSL_DYNAMIC_LINKER64
 #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, M) \
-  "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
-#elif DEFAULT_LIBC == LIBC_GLIBC
-#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, \
-			 MUSL_DYNAMIC_LINKER32)
-#define GNU_USER_DYNAMIC_LINKER64 \
-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
-			 MUSL_DYNAMIC_LINKER64)
-
 #undef  DEFAULT_ASM_ENDIAN
 #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
 #define DEFAULT_ASM_ENDIAN " -mlittle"
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index 0c676349cf7..73541af3e69 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -786,8 +786,10 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
 
 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
+#undef MUSL_DYNAMIC_LINKER
 #define MUSL_DYNAMIC_LINKER \
   "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
+#ifndef GNU_USER_DYNAMIC_LINKER
 #if DEFAULT_LIBC == LIBC_UCLIBC
 #define CHOOSE_DYNAMIC_LINKER(G, U, M) \
   "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
@@ -803,6 +805,7 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
 #define GNU_USER_DYNAMIC_LINKER \
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
 			 MUSL_DYNAMIC_LINKER)
+#endif
 
 #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
   %{rdynamic:-export-dynamic} \
@@ -812,12 +815,7 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
 # define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
-#define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
-%{!undef:							  \
-  %{!ansi:							  \
-    %{!std=*:-Dunix -D__unix -Dlinux -D__linux}			  \
-    %{std=gnu*:-Dunix -D__unix -Dlinux -D__linux}}}		  \
--Asystem=linux -Asystem=unix -Asystem=posix %{pthread:-D_REENTRANT}"
+#define CPP_OS_LINUX_SPEC "%{pthread:-D_REENTRANT}"
 
 /* NetBSD support.  */
 #define LIB_NETBSD_SPEC "\