public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
To: Iain Buclaw <ibuclaw@gdcproject.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: Fix D compilation on Solaris
Date: Sun, 04 Nov 2018 16:50:00 -0000	[thread overview]
Message-ID: <yddr2g0hjnn.fsf@CeBiTec.Uni-Bielefeld.DE> (raw)
In-Reply-To: <CABOHX+fS3mBMNuuoTMBfduqidw8_QaYSpK++DRi8W0pHTECYQw@mail.gmail.com>	(Iain Buclaw's message of "Sun, 4 Nov 2018 01:08:07 +0100")

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

Hi Iain,

> On Sat, 3 Nov 2018 at 23:23, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>>
>> On Wed, 31 Oct 2018 at 10:40, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>> >
>> > Hi Iain,
>> >
>> > > My first suspect here would be 'struct UnionExp', see d/dmd/expression.h
>> > >
>> > > Upstream dmd use a poor man's alignment, from what I recall to be
>> > > compatible with the dmc compiler.
>> > >
>> > >         // Ensure that the union is suitably aligned.
>> > >         real_t for_alignment_only;
>> > >
>> > > What happens if you were to replace that with marking the type as
>> > > __attribute__ ((aligned (8))) ?
>> >
>> > thanks for the suggestion: this worked just fine.  After a couple more
>> > libphobos adjustments (described below), I was able to finish the build
>> > on both sparc-sun-solaris2.11 and i386-pc-solaris2.11.
>> >
>> > The link tests still all fail as before, but sparc and x86 are now on
>> > par here :-)
>> >
>>
>> Hi Rainer,
>>
>> On making the relevant change to dmd, this header probably should
>> remain compatible with dmc++, which unfortunately doesn't implement
>> any __attribute__ extensions.  Does s/real_t/long double/ also prevent
>> the alignment error from occurring?
>>
>
> Actually, turns out I'm wrong and was grepping for the wrong name.
>
> It is supported in the form of #pragma pack(8)
>
> https://www.digitalmars.com/ctg/pragmas.html#pack

I tried wrapping union u in #pragma pack(8)/#pragma pack().
Unfortunately, this doesn't seem to work as I got the same SIGBUS errors
during a sparc-sun-solaris2.11 bootstrap.  Seems we have to stay with
the long double version instead.

I'm including the current patch here.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2018-10-29  Iain Buclaw  <ibuclaw@gdcproject.org>

	gcc/d:
	* dmd/expression.h (UnionExp.u): Change for_alignment_only to long
	double.

2018-10-29  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc:
	* config/default-d.c: Include memmodel.h.

	* config/sol2-d.c: New file.
	* config/t-sol2 (sol2-d.o): New rule.
	* config.gcc <*-*-solaris2*>: Set d_target_objs,
	target_has_targetdm.

	libphobos:
	* libdruntime/core/stdc/fenv.d [SPARC, SPARC64]: Set SPARC_Any.
	[X86, X86_64]: Set X86_Any.
	[Solaris]: Provide FE_* constants.
	* libdruntime/core/sys/posix/aio.d [Solaris] (struct aio_result,
	struct aiocb): New types.
	* libdruntime/core/sys/posix/ucontext.d [SPARC64, SPARC] (_NGREG,
	greg_t): Define.
	[SPARC64, SPARC] (struct _fpq, struct fq, struct fpregset_t): New
	types.
	* libdruntime/core/thread.d (Class Thread) [Solaris]
	(m_isRTClass): Don't declare immutable.
	* libdruntime/rt/sections_solaris.d (SectionGroup.moduleGroup):
	Declare nothrow @nogc.
	(pinLoadedLibraries, unpinLoadedLibraries, inheritLoadedLibraries)
	(cleanupLoadedLibraries): New functions.
	* src/std/datetime/systime.d (class Clock) [Solaris]
	(clock_gettime): Import.
	* src/std/math.d [SPARC, SPARC64]: Set SPARC_Any.
	(struct FloatingPointControl): Use SPARC_Any for ExceptionMask,
	ControlState.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sol2-d-build.patch --]
[-- Type: text/x-patch, Size: 10281 bytes --]

# HG changeset patch
# Parent  0f6ccc9cfd024f705876c70a6403268ea9dbf0a2
Fix D compilation on Solaris

diff --git a/gcc/config.gcc b/gcc/config.gcc
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -918,6 +918,7 @@ case ${target} in
   target_gtfiles="$target_gtfiles \$(srcdir)/config/sol2.c"
   c_target_objs="${c_target_objs} sol2-c.o"
   cxx_target_objs="${cxx_target_objs} sol2-c.o sol2-cxx.o"
+  d_target_objs="${d_target_objs} sol2-d.o"
   extra_objs="${extra_objs} sol2.o sol2-stubs.o"
   extra_options="${extra_options} sol2.opt"
   case ${enable_threads}:${have_pthread_h}:${have_thread_h} in
@@ -925,6 +926,7 @@ case ${target} in
       thread_file=posix
       ;;
   esac
+  target_has_targetdm=yes
   ;;
 *-*-*vms*)
   extra_options="${extra_options} vms/vms.opt"
diff --git a/gcc/config/default-d.c b/gcc/config/default-d.c
--- a/gcc/config/default-d.c
+++ b/gcc/config/default-d.c
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "memmodel.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/sol2-d.c b/gcc/config/sol2-d.c
new file mode 100644
--- /dev/null
+++ b/gcc/config/sol2-d.c
@@ -0,0 +1,51 @@
+/* Solaris support needed only by D front-end.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "memmodel.h"
+#include "tm_p.h"
+#include "d/d-target.h"
+#include "d/d-target-def.h"
+
+/* Implement TARGET_D_OS_VERSIONS for Solaris targets.  */
+
+static void
+solaris_d_os_builtins (void)
+{
+  d_add_builtin_version ("Posix");
+  d_add_builtin_version ("Solaris");			\
+}
+
+/* Implement TARGET_D_CRITSEC_SIZE for Solaris targets.  */
+
+static unsigned
+solaris_d_critsec_size (void)
+{
+  /* This is the sizeof pthread_mutex_t.  */
+  return 24;
+}
+
+#undef TARGET_D_OS_VERSIONS
+#define TARGET_D_OS_VERSIONS solaris_d_os_builtins
+
+#undef TARGET_D_CRITSEC_SIZE
+#define TARGET_D_CRITSEC_SIZE solaris_d_critsec_size
+
+struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/t-sol2 b/gcc/config/t-sol2
--- a/gcc/config/t-sol2
+++ b/gcc/config/t-sol2
@@ -16,7 +16,7 @@
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
-# Solaris-specific format checking and pragmas
+# Solaris-specific format checking and pragmas.
 sol2-c.o: $(srcdir)/config/sol2-c.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
@@ -26,6 +26,11 @@ sol2-cxx.o: $(srcdir)/config/sol2-cxx.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
 
+# Solaris-specific D support.
+sol2-d.o: $(srcdir)/config/sol2-d.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+
 # Corresponding stub routines.
 sol2-stubs.o: $(srcdir)/config/sol2-stubs.c
 	$(COMPILE) $<
diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h
--- a/gcc/d/dmd/expression.h
+++ b/gcc/d/dmd/expression.h
@@ -1509,7 +1509,7 @@ private:
         char sliceexp  [sizeof(SliceExp)];
 
         // Ensure that the union is suitably aligned.
-        real_t for_alignment_only;
+        long double for_alignment_only;
     } u;
 };
 
diff --git a/libphobos/libdruntime/core/stdc/fenv.d b/libphobos/libdruntime/core/stdc/fenv.d
--- a/libphobos/libdruntime/core/stdc/fenv.d
+++ b/libphobos/libdruntime/core/stdc/fenv.d
@@ -33,6 +33,16 @@ version (PPC)
 else version (PPC64)
     version = PPC_Any;
 
+version (SPARC)
+    version = SPARC_Any;
+version (SPARC64)
+    version = SPARC_Any;
+
+version (X86)
+    version = X86_Any;
+version (X86_64)
+    version = X86_Any;
+
 version (MinGW)
     version = GNUFP;
 version (CRuntime_Glibc)
@@ -451,6 +461,50 @@ version (CRuntime_Microsoft)
         FE_TOWARDZERO   = 0x300, ///
     }
 }
+else version (Solaris)
+{
+	version (SPARC_Any)
+	{
+	    enum
+	    {
+		FE_TONEAREST    = 0,
+		FE_TOWARDZERO   = 1,
+		FE_UPWARD       = 2,
+		FE_DOWNWARD     = 3,
+	    }
+
+	    enum
+	    {
+		FE_INEXACT      = 0x01,
+		FE_DIVBYZERO    = 0x02,
+		FE_UNDERFLOW    = 0x04,
+		FE_OVERFLOW     = 0x08,
+		FE_INVALID      = 0x10,
+		FE_ALL_EXCEPT   = 0x1f,
+	    }
+
+	}
+	else version (X86_Any)
+	{
+	    enum
+	    {
+		FE_TONEAREST    = 0,
+		FE_DOWNWARD     = 1,
+		FE_UPWARD       = 2,
+		FE_TOWARDZERO   = 3,
+	    }
+
+	    enum
+	    {
+		FE_INVALID      = 0x01,
+		FE_DIVBYZERO    = 0x04,
+		FE_OVERFLOW     = 0x08,
+		FE_UNDERFLOW    = 0x10,
+		FE_INEXACT      = 0x20,
+		FE_ALL_EXCEPT   = 0x3d,
+	    }
+	}
+}
 else
 {
     version (X86)
diff --git a/libphobos/libdruntime/core/sys/posix/aio.d b/libphobos/libdruntime/core/sys/posix/aio.d
--- a/libphobos/libdruntime/core/sys/posix/aio.d
+++ b/libphobos/libdruntime/core/sys/posix/aio.d
@@ -123,6 +123,32 @@ else version (DragonFlyBSD)
 
     version = BSD_Posix;
 }
+else version (Solaris)
+{
+    struct aio_result_t
+    {
+	ssize_t aio_return;
+	int aio_errno;
+    };
+
+    struct aiocb
+    {
+        int aio_fildes;
+        void* aio_buf;   // volatile
+        size_t aio_nbytes;
+        off_t aio_offset;
+	int aio_reqprio;
+        sigevent aio_sigevent;
+        int aio_lio_opcode;
+	aio_result_t aio_result;
+	byte aio_state;
+	byte aio_returned;
+	byte[2] aio__pad1;
+	int aio_flags;
+    }
+
+    version = BSD_Posix;
+}
 else
     static assert(false, "Unsupported platform");
 
diff --git a/libphobos/libdruntime/core/sys/posix/ucontext.d b/libphobos/libdruntime/core/sys/posix/ucontext.d
--- a/libphobos/libdruntime/core/sys/posix/ucontext.d
+++ b/libphobos/libdruntime/core/sys/posix/ucontext.d
@@ -937,7 +937,17 @@ else version (Solaris)
 {
     alias uint[4] upad128_t;
 
-    version (X86_64)
+    version (SPARC64)
+    {
+        enum _NGREG = 21;
+        alias long greg_t;
+    }
+    else version (SPARC)
+    {
+        enum _NGREG = 19;
+        alias int greg_t;
+    }
+    else version (X86_64)
     {
         enum _NGREG = 28;
         alias long greg_t;
@@ -950,7 +960,70 @@ else version (Solaris)
 
     alias greg_t[_NGREG] gregset_t;
 
-    version (X86_64)
+    version (SPARC64)
+    {
+	struct _fpq
+	{
+	    uint *fpq_addr;
+	    uint fpq_instr;
+	}
+
+	struct fq
+	{
+	    union
+	    {
+		double whole;
+		_fpq fpq;
+	    };
+	}
+
+        struct fpregset_t
+	{
+	    union
+	    {
+	    	uint[32]	fpu_regs;
+		double[32]	fpu_dregs;
+		real[16]	fpu_qregs;
+	    };
+	    fq		*fpu_q;
+	    ulong	fpu_fsr;
+	    ubyte	fpu_qcnt;
+	    ubyte	fpu_q_entrysize;
+	    ubyte	fpu_en;
+	}
+    }
+    else version (SPARC)
+    {
+	struct _fpq
+	{
+	    uint *fpq_addr;
+	    uint fpq_instr;
+	}
+
+	struct fq
+	{
+	    union
+	    {
+		double whole;
+		_fpq fpq;
+	    };
+	}
+
+	struct fpregset_t
+	{
+	    union
+	    {
+		uint[32]	fpu_regs;
+		double[16]	fpu_dregs;
+	    };
+	    fq		*fpu_q;
+	    uint	fpu_fsr;
+	    ubyte	fpu_qcnt;
+	    ubyte	fpu_q_entrysize;
+	    ubyte	fpu_en;
+	}
+    }
+    else version (X86_64)
     {
         union _u_st
         {
diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d
--- a/libphobos/libdruntime/core/thread.d
+++ b/libphobos/libdruntime/core/thread.d
@@ -1547,7 +1547,7 @@ private:
 
     version (Solaris)
     {
-        __gshared immutable bool m_isRTClass;
+        __gshared bool m_isRTClass;
     }
 
 private:
diff --git a/libphobos/libdruntime/rt/sections_solaris.d b/libphobos/libdruntime/rt/sections_solaris.d
--- a/libphobos/libdruntime/rt/sections_solaris.d
+++ b/libphobos/libdruntime/rt/sections_solaris.d
@@ -34,7 +34,7 @@ struct SectionGroup
         return _moduleGroup.modules;
     }
 
-    @property ref inout(ModuleGroup) moduleGroup() inout
+    @property ref inout(ModuleGroup) moduleGroup() inout nothrow @nogc
     {
         return _moduleGroup;
     }
@@ -87,6 +87,24 @@ void scanTLSRanges(void[] rng, scope voi
     dg(rng.ptr, rng.ptr + rng.length);
 }
 
+// interface for core.thread to inherit loaded libraries
+void* pinLoadedLibraries() nothrow @nogc
+{
+    return null;
+}
+
+void unpinLoadedLibraries(void* p) nothrow @nogc
+{
+}
+
+void inheritLoadedLibraries(void* p) nothrow @nogc
+{
+}
+
+void cleanupLoadedLibraries() nothrow @nogc
+{
+}
+
 private:
 
 __gshared SectionGroup _sections;
diff --git a/libphobos/src/std/datetime/systime.d b/libphobos/src/std/datetime/systime.d
--- a/libphobos/src/std/datetime/systime.d
+++ b/libphobos/src/std/datetime/systime.d
@@ -221,6 +221,7 @@ public:
                 else
                 {
                     import core.sys.solaris.time : CLOCK_REALTIME;
+                    import core.sys.posix.time : clock_gettime;
                     static if (clockType == ClockType.coarse)       alias clockArg = CLOCK_REALTIME;
                     else static if (clockType == ClockType.normal)  alias clockArg = CLOCK_REALTIME;
                     else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME;
diff --git a/libphobos/src/std/math.d b/libphobos/src/std/math.d
--- a/libphobos/src/std/math.d
+++ b/libphobos/src/std/math.d
@@ -160,6 +160,8 @@ version (MIPS32)    version = MIPS_Any;
 version (MIPS64)    version = MIPS_Any;
 version (AArch64)   version = ARM_Any;
 version (ARM)       version = ARM_Any;
+version (SPARC)     version = SPARC_Any;
+version (SPARC64)   version = SPARC_Any;
 
 version (D_InlineAsm_X86)
 {
@@ -5161,7 +5163,7 @@ struct FloatingPointControl
                                  | inexactException,
         }
     }
-    else version (SPARC64)
+    else version (SPARC_Any)
     {
         enum : ExceptionMask
         {
@@ -5291,7 +5293,7 @@ private:
     {
         alias ControlState = uint;
     }
-    else version (SPARC64)
+    else version (SPARC_Any)
     {
         alias ControlState = ulong;
     }

  reply	other threads:[~2018-11-04 16:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 12:18 Rainer Orth
2018-10-30 14:49 ` Rainer Orth
2018-10-30 19:00   ` Iain Buclaw
2018-10-31 10:02     ` Rainer Orth
2018-10-31 10:03       ` Rainer Orth
2018-10-31 17:51         ` Iain Buclaw
2018-11-04 16:47           ` Rainer Orth
2018-10-31 17:33       ` Iain Buclaw
2018-11-04 16:47         ` Rainer Orth
2018-11-03 22:23       ` Iain Buclaw
2018-11-04  0:08         ` Iain Buclaw
2018-11-04 16:50           ` Rainer Orth [this message]
2018-11-04 18:31             ` Iain Buclaw
2018-11-04 16:47         ` Rainer Orth

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=yddr2g0hjnn.fsf@CeBiTec.Uni-Bielefeld.DE \
    --to=ro@cebitec.uni-bielefeld.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ibuclaw@gdcproject.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).