Re: Fix D compilation on Solaris

2018-11-04 Thread Iain Buclaw
On Sun, 4 Nov 2018 at 17:50, Rainer Orth  wrote:
>
> Hi Iain,
>
> > On Sat, 3 Nov 2018 at 23:23, Iain Buclaw  wrote:
> >>
> >> On Wed, 31 Oct 2018 at 10:40, Rainer Orth  
> >> 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.
>

That's alright.  I meant that #pragma pack is for DMC compatibility.

I've the changes have been made upstream:

https://github.com/dlang/dmd/pull/8907
https://github.com/dlang/dmd/pull/8914  (Backport to C++)


> I'm including the current patch here.
>
> Rainer
>
> --
> -
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2018-10-29  Iain Buclaw  
>
> gcc/d:
> * dmd/expression.h (UnionExp.u): Change for_alignment_only to long
> double.
>
> 2018-10-29  Rainer Orth  
>
> 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.
>

The gcc changes look OK.  I will commit the front-end and library
changes though in a merge later today, as I've been sending them
upstream first.

-- 
Iain


Re: Fix D compilation on Solaris

2018-11-04 Thread Rainer Orth
Hi Iain,

> On Sat, 3 Nov 2018 at 23:23, Iain Buclaw  wrote:
>>
>> On Wed, 31 Oct 2018 at 10:40, Rainer Orth  
>> 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  

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

2018-10-29  Rainer Orth  

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.

# 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) 20

Re: Fix D compilation on Solaris

2018-11-04 Thread Rainer Orth
Hi Iain,

> On Wed, 31 Oct 2018 at 10:40, Rainer Orth  
> 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?

it does indeed, as checked by a sparc-sun-solaris2.11 bootstrap.

Thanks.
Rainer

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


Re: Fix D compilation on Solaris

2018-11-04 Thread Rainer Orth
Hi Iain,

> On Wed, 31 Oct 2018 at 10:40, Rainer Orth  
> 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 :-)
>>
>> Here are the new issues I saw while completing the sparc build:
>>
>> * math.d has two problems on 32-bit sparc:
>>
>> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5278:18: error:
>> undefined identifier 'ControlState'
>>  5278 | ControlState savedState;
>>   |  ^
>> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5325:25: error:
>> undefined identifier 'ControlState'
>>  5325 | static ControlState getControlState() @trusted nothrow @nogc
>>   | ^
>> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5390:17: error:
>> undefined identifier 'ControlState'
>>  5390 | static void setControlState(ControlState newState) @trusted
>> nothrow @nogc
>>   | ^
>>
>>   Fixed by using the ControlState alias on both SPARC64 and SPARC.
>>
>> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5211:9: error: static 
>> assert  "Not implemented for this architecture"
>>  5211 | static assert(false, "Not implemented for this 
>> architecture");
>>   | ^
>>
>>   Similarly, ExceptionMask was only defined for SPARC64.  However,
>>   looking closer it seems that the current definition only matches Linux
>>   resp. Glibc fenv.h (FE_*).  The Solaris values are different on sparc.
>>
>>   This seems to be a recurring theme, unfortunately: definitions guarded
>>   by version ($CPU) are really CRuntime_Glibc && $CPU.  I fear libphobos
>>   has to be way more careful to distinguish between definitions that
>>   only depend on the target cpu and those that are (also) OS-dependent.
>>
>
> The phobos part is largely free of version (CPU), the druntime
> bindings are in a little better shape, despite there being a lot of
> places dotted around the place that need to be checked.
>
>>   Instead of hardcoding all this, it may be worth having a look at how
>>   Go handles this: they dump the definitions with gcc
>>   -fdump-go-spec=tmp-gen-sysinfo.go and postprocess them in
>>   libgo/mksysinfo.sh.  This way, such errors and potential
>>   inconsistencies are avoided from the start.  This would also massivly
>>   simplify work for potential porters.
>>
>
> You mean a tool such as htod (header to D)?  I don't think that has
> ever gained traction in upstream.

that's a pity.  It certainly would simplify things...

> The existing C bindings for sure are brittle, and never take into
> account changes between versions (FreeBSD comes to mind), but for new
> ports, it at least tries to be consistent in that unhandled places
> always end with a 'static assert (false)' compiler error.  If I was
> just to defend the current status quo a little.

I see.  Types and interfaces changing between versions can certainly be
a problem.  However, Solaris is usually very careful not to make
incompatible changes.

>> * My previous patch had a typo, now also fixed:
>>
>> /vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/sys/posix/ucontext.d:984:20:
>> error: undefined identifier 'uint32_t'
>>   984 |   uint32_t[32] fpu_regs;
>>   |^
>>
>> While those were enough to finish the build, I noticed a couple of
>> additional issues:
>>
>> * During make check, part (or all) of libphobos was rebuilt.  I strongly
>>   suspect that this happens because contrib/gcc_update doesn't handle
>>   libphobos yet: it needs to touch generated files to avoid exactly this
>>   sort of problem.  I'll post a separate patch once tested.
>>
>> * Unlike the gdc.dg tests, many gdc.test tests appear as UNRESOLVED like
>>   this:
>>
>> UNRESOLVED: runnable/A16.d   compilation failed to produce executable
>>
>>   There's no preceding FAIL for the link failure itself.  Besides, the
>>   testname needs to include the gdc.test prefix.
>>
>> * One issue I forgot last time: when defining the SPARC64 struct
>>   fpregset_t in libdruntime/core/sys/posix/ucontext.d, one field
>>   couldn't be represented: the structure contains a union
>>
>> union fpu_fr
>> {
>> uint[32]fpu_regs;
>> double[32]  fpu_dregs;
>> /* long double[16]  fpu_qregs; */
>>
>>   but there's no D type corresponding to 

Re: Fix D compilation on Solaris

2018-11-04 Thread Rainer Orth
Hi Iain,

> On Wed, 31 Oct 2018 at 10:43, Rainer Orth  
> 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 :-)
>>
>> and now with the updated patch ;-)
>>
>
> Thanks, the front-end and library parts should be posted upstream.
>
> Mapping would be:
> - d/dmd: https://github.com/dlang/dmd/tree/dmd-cxx
> - libdruntime/core: https://github.com/dlang/druntime
> - libphobos/src/std: https://github.com/dlang/phobos
>
> I can take care of this, then backport/merge it down here.

that would be great.  I'd like to avoid becoming involved in the
procedures of too many upstream projects if possible.  The way Ian
handles my Solaris Go changes is very convenient for me ;-)

> As for the patch itself:
>
>> --- 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"
>
> Is this still required?  For sure it would cover non-glibc,
> non-solaris sparc targets though.

There are other *-protos.h files using enum memmodel beside sparc:
alpha, ia64, and tilegx.  This may or may not be a reason to keep the
include.

>> 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
>
> [-- snip --]
>
>> +solaris_d_os_builtins (void)
>> +{
>> +  d_add_builtin_version ("Posix");
>> +  d_add_builtin_version ("Solaris"); \
>> +}
>> +
>
> I'll assume that backslash is a typo.
>
> You'll also need to add this target hook:
>
> /* Implement TARGET_D_CRITSEC_SIZE for Solaris targets.  */
>
> static unsigned
> solaris_d_critsec_size (void)
> {
>   /* This is the sizeof pthread_mutex_t.  */
>   return 24;
> }
>
> I hope that pthread_mutex_t does not differ between x86 and SPARC.

I saw it in glibc-d.c, but initially thought it were Linux-only in some
way.  Fortunately, pthread_mutex_t is identical between sparc and x86,
32 and 64-bit on Solaris.  Added to the updated patch.

>> 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
>>  # .
>>
>> -# Solaris-specific format checking and pragmas
>> +# Solaris-specific format checking and pragmas.
>>  sol2-c.o: $(srcdir)/config/sol2-c.c
>>  $(COMPILE) $<
>>  $(POSTCOMPILE)
>
> Not sure what the policy is about mixing unrelated changes in a patch here.

In general, they are frowned upon ;-)  However, in this case for a
single-character comment change in code I maintain, I believe it would
be overkill to move it to a separate check-in.

>> 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
>
> [-- snip --]
>
>> + struct fq
>> + {
>> + union FQu
>> + {
>> + double whole;
>> + _fpq fpq;
>> + };
>> + }
>
> Just an FYI, this won't do what I think you expect, 'struct fq' here
> would be an empty struct.  Better make this an anonymous union, I can
> see the same mistake done elsewhere.
>
> struct fq
> {
> union
> {
> double whole;
> _fpq fpq;
> }
> }

Thanks, all instances fixed, I hope.

>> 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:
>
> This is curious, I wonder when was the last time someone tested x86
> Solaris in upstream.  What was the compilation error?

I got

/vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/thread.d:989:21: error: 
cannot modify immutable expression m_isRTClass
  989 | m_isRTClass = true;
  | ^
/vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/thread.d:997:21: error: 
cannot modify immutable expression 

Re: Fix D compilation on Solaris

2018-11-03 Thread Iain Buclaw
On Sat, 3 Nov 2018 at 23:23, Iain Buclaw  wrote:
>
> On Wed, 31 Oct 2018 at 10:40, Rainer Orth  
> 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

-- 
Iain


Re: Fix D compilation on Solaris

2018-11-03 Thread Iain Buclaw
On Wed, 31 Oct 2018 at 10:40, Rainer Orth  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?

Iain.


Re: Fix D compilation on Solaris

2018-10-31 Thread Iain Buclaw
On Wed, 31 Oct 2018 at 10:43, Rainer Orth  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 :-)
>
> and now with the updated patch ;-)
>

Thanks, the front-end and library parts should be posted upstream.

Mapping would be:
- d/dmd: https://github.com/dlang/dmd/tree/dmd-cxx
- libdruntime/core: https://github.com/dlang/druntime
- libphobos/src/std: https://github.com/dlang/phobos

I can take care of this, then backport/merge it down here.

As for the patch itself:

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

Is this still required?  For sure it would cover non-glibc,
non-solaris sparc targets though.

> 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

[-- snip --]

> +solaris_d_os_builtins (void)
> +{
> +  d_add_builtin_version ("Posix");
> +  d_add_builtin_version ("Solaris"); \
> +}
> +

I'll assume that backslash is a typo.

You'll also need to add this target hook:

/* Implement TARGET_D_CRITSEC_SIZE for Solaris targets.  */

static unsigned
solaris_d_critsec_size (void)
{
  /* This is the sizeof pthread_mutex_t.  */
  return 24;
}

I hope that pthread_mutex_t does not differ between x86 and SPARC.

> 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
>  # .
>
> -# Solaris-specific format checking and pragmas
> +# Solaris-specific format checking and pragmas.
>  sol2-c.o: $(srcdir)/config/sol2-c.c
>  $(COMPILE) $<
>  $(POSTCOMPILE)

Not sure what the policy is about mixing unrelated changes in a patch here.

> 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

[-- snip --]

> + struct fq
> + {
> + union FQu
> + {
> + double whole;
> + _fpq fpq;
> + };
> + }

Just an FYI, this won't do what I think you expect, 'struct fq' here
would be an empty struct.  Better make this an anonymous union, I can
see the same mistake done elsewhere.

struct fq
{
union
{
double whole;
_fpq fpq;
}
}

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

This is curious, I wonder when was the last time someone tested x86
Solaris in upstream.  What was the compilation error?

> 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

[-- snip --]

>
> +// interface for core.thread to inherit loaded libraries
> +void* pinLoadedLibraries() nothrow @nogc
> +{
> +return null;
> +}
> +

I ran into this on OSX as well.  The problem lies elsewhere, and I'm
going to fix this.  The shared library is being built with
'-fversion=Shared', but this is only valid for targets that use
rt/sections_elf_shared.d

I suspect that Solaris/SPARC should be using the ELF sections support anyway.

Apart from comments, the GCC parts look OK to me.  Unless you want to
raise a pull request, I'll submit the library patches upstream later.

Thanks!
Iain


Re: Fix D compilation on Solaris

2018-10-31 Thread Iain Buclaw
On Wed, 31 Oct 2018 at 10:40, Rainer Orth  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 :-)
>
> Here are the new issues I saw while completing the sparc build:
>
> * math.d has two problems on 32-bit sparc:
>
> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5278:18: error: 
> undefined identifier 'ControlState'
>  5278 | ControlState savedState;
>   |  ^
> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5325:25: error: 
> undefined identifier 'ControlState'
>  5325 | static ControlState getControlState() @trusted nothrow @nogc
>   | ^
> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5390:17: error: 
> undefined identifier 'ControlState'
>  5390 | static void setControlState(ControlState newState) @trusted 
> nothrow @nogc
>   | ^
>
>   Fixed by using the ControlState alias on both SPARC64 and SPARC.
>
> /vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5211:9: error: static 
> assert  "Not implemented for this architecture"
>  5211 | static assert(false, "Not implemented for this architecture");
>   | ^
>
>   Similarly, ExceptionMask was only defined for SPARC64.  However,
>   looking closer it seems that the current definition only matches Linux
>   resp. Glibc fenv.h (FE_*).  The Solaris values are different on sparc.
>
>   This seems to be a recurring theme, unfortunately: definitions guarded
>   by version ($CPU) are really CRuntime_Glibc && $CPU.  I fear libphobos
>   has to be way more careful to distinguish between definitions that
>   only depend on the target cpu and those that are (also) OS-dependent.
>

The phobos part is largely free of version (CPU), the druntime
bindings are in a little better shape, despite there being a lot of
places dotted around the place that need to be checked.

>   Instead of hardcoding all this, it may be worth having a look at how
>   Go handles this: they dump the definitions with gcc
>   -fdump-go-spec=tmp-gen-sysinfo.go and postprocess them in
>   libgo/mksysinfo.sh.  This way, such errors and potential
>   inconsistencies are avoided from the start.  This would also massivly
>   simplify work for potential porters.
>

You mean a tool such as htod (header to D)?  I don't think that has
ever gained traction in upstream.

The existing C bindings for sure are brittle, and never take into
account changes between versions (FreeBSD comes to mind), but for new
ports, it at least tries to be consistent in that unhandled places
always end with a 'static assert (false)' compiler error.  If I was
just to defend the current status quo a little.

> * My previous patch had a typo, now also fixed:
>
> /vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/sys/posix/ucontext.d:984:20:
>  error: undefined identifier 'uint32_t'
>   984 |   uint32_t[32] fpu_regs;
>   |^
>
> While those were enough to finish the build, I noticed a couple of
> additional issues:
>
> * During make check, part (or all) of libphobos was rebuilt.  I strongly
>   suspect that this happens because contrib/gcc_update doesn't handle
>   libphobos yet: it needs to touch generated files to avoid exactly this
>   sort of problem.  I'll post a separate patch once tested.
>
> * Unlike the gdc.dg tests, many gdc.test tests appear as UNRESOLVED like
>   this:
>
> UNRESOLVED: runnable/A16.d   compilation failed to produce executable
>
>   There's no preceding FAIL for the link failure itself.  Besides, the
>   testname needs to include the gdc.test prefix.
>
> * One issue I forgot last time: when defining the SPARC64 struct
>   fpregset_t in libdruntime/core/sys/posix/ucontext.d, one field
>   couldn't be represented: the structure contains a union
>
> union fpu_fr
> {
> uint[32]fpu_regs;
> double[32]  fpu_dregs;
> /* long double[16]  fpu_qregs; */
>
>   but there's no D type corresponding to long double: the D real type
>   represents the biggest floating-point type implemented in hardware,
>   and AFAIK no SPARC CPU ever implemented 128-bit floating point.
>   Still, with this missing the alignment of the union is wrong.
>

In practice however, the 'real' type maps to C 'long double', so you
can safely use real[16] here.

-- 

Re: Fix D compilation on Solaris

2018-10-31 Thread Rainer Orth
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 :-)

and now with the updated patch ;-)

Rainer

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


2018-10-29  Iain Buclaw  

gcc/d:
* dmd/expression.h (UnionExp.u): Remove for_alignment_only.
Force 8-byte alignment.

2018-10-29  Rainer Orth  

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.

# HG changeset patch
# Parent  feb1bc98079b57185692621c744578b658d1fc1a
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,39 @@
+/* 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&

Re: Fix D compilation on Solaris

2018-10-31 Thread Rainer Orth
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 :-)

Here are the new issues I saw while completing the sparc build:

* math.d has two problems on 32-bit sparc:

/vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5278:18: error: undefined 
identifier 'ControlState'
 5278 | ControlState savedState;
  |  ^
/vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5325:25: error: undefined 
identifier 'ControlState'
 5325 | static ControlState getControlState() @trusted nothrow @nogc
  | ^
/vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5390:17: error: undefined 
identifier 'ControlState'
 5390 | static void setControlState(ControlState newState) @trusted nothrow 
@nogc
  | ^

  Fixed by using the ControlState alias on both SPARC64 and SPARC.

/vol/gcc/src/hg/trunk/local/libphobos/src/std/math.d:5211:9: error: static 
assert  "Not implemented for this architecture"
 5211 | static assert(false, "Not implemented for this architecture");
  | ^

  Similarly, ExceptionMask was only defined for SPARC64.  However,
  looking closer it seems that the current definition only matches Linux
  resp. Glibc fenv.h (FE_*).  The Solaris values are different on sparc.

  This seems to be a recurring theme, unfortunately: definitions guarded
  by version ($CPU) are really CRuntime_Glibc && $CPU.  I fear libphobos
  has to be way more careful to distinguish between definitions that
  only depend on the target cpu and those that are (also) OS-dependent.

  Instead of hardcoding all this, it may be worth having a look at how
  Go handles this: they dump the definitions with gcc
  -fdump-go-spec=tmp-gen-sysinfo.go and postprocess them in
  libgo/mksysinfo.sh.  This way, such errors and potential
  inconsistencies are avoided from the start.  This would also massivly
  simplify work for potential porters.

* My previous patch had a typo, now also fixed:

/vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/sys/posix/ucontext.d:984:20:
 error: undefined identifier 'uint32_t'
  984 |   uint32_t[32] fpu_regs;
  |^

While those were enough to finish the build, I noticed a couple of
additional issues:

* During make check, part (or all) of libphobos was rebuilt.  I strongly
  suspect that this happens because contrib/gcc_update doesn't handle
  libphobos yet: it needs to touch generated files to avoid exactly this
  sort of problem.  I'll post a separate patch once tested.

* Unlike the gdc.dg tests, many gdc.test tests appear as UNRESOLVED like
  this:

UNRESOLVED: runnable/A16.d   compilation failed to produce executable

  There's no preceding FAIL for the link failure itself.  Besides, the
  testname needs to include the gdc.test prefix.

* One issue I forgot last time: when defining the SPARC64 struct
  fpregset_t in libdruntime/core/sys/posix/ucontext.d, one field
  couldn't be represented: the structure contains a union

union fpu_fr
{
uint[32]fpu_regs;
double[32]  fpu_dregs;
/* long double[16]  fpu_qregs; */

  but there's no D type corresponding to long double: the D real type
  represents the biggest floating-point type implemented in hardware,
  and AFAIK no SPARC CPU ever implemented 128-bit floating point.
  Still, with this missing the alignment of the union is wrong.

Rainer

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


Re: Fix D compilation on Solaris

2018-10-30 Thread Iain Buclaw
On Tue, 30 Oct 2018 at 14:13, Rainer Orth  wrote:
>
> Rainer Orth  writes:
>
> > * On sparc, I didn't get that far, unfortunately: as I mentioned, many
> >   compilations die with SIGBUS:
> >
> > libtool: compile:  /var/gcc/regression/trunk/11.5-gcc/build/./gcc/gdc 
> > -B/var/gcc/regression/trunk/11.5-gcc/build/./gcc/ 
> > -B/vol/gcc/sparc-sun-solaris2.11/bin/ -B/vol/gcc/sparc-sun-solaris2.11/lib/ 
> > -isystem /vol/gcc/sparc-sun-solaris2.11/include -isystem 
> > /vol/gcc/sparc-sun-solaris2.11/sys-include -fno-checking -fPIC -O2 -g 
> > -nostdinc -I /vol/gcc/src/hg/trunk/local/libphobos/libdruntime -I . -c 
> > /vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/thread.d 
> > -fversion=Shared -o core/.libs/thread.o
> > d21: internal compiler error: Bus Error
> > 0xbb5507 crash_signal
> > /vol/gcc/src/hg/trunk/local/gcc/toplev.c:325
> > 0x518700 IntegerExp::toInteger()
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/expression.c:2943
> > 0x4d05c3 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> > 0x4d1543 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6017
> > 0x4d1543 interpret(Statement*, InterState*)
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6024
> > 0x4d263b interpretFunction
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:906
> > 0x4d263b interpretFunction
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:726
> > 0x4d05c3 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> > 0x4d14df interpret(Expression*, InterState*, CtfeGoal)
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5994
> > 0x4d05c3 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> > 0x4d14df interpret(Expression*, InterState*, CtfeGoal)
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5994
> > 0x5243d7 DeclarationExp::accept(Visitor*)
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/expression.h:661
> > 0x4d05c3 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> > 0x4d1543 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6017
> > 0x4d1543 interpret(Statement*, InterState*)
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6024
> > 0x4d263b interpretFunction
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:906
> > 0x4d263b interpretFunction
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:726
> > 0x4d05c3 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> > 0x4d14df interpret(Expression*, InterState*, CtfeGoal)
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5994
> > 0x4d05c3 interpret
> > /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> >
> >   Will need to dig further here.
>
> It's exactly as I suspected:
>
> $ d21 /vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/thread.d 
> -mcpu=v9 -fversion=Shared -I 
> /vol/gcc/src/hg/trunk/local/libphobos/libdruntime -o thread.s
>

Hi Rainer,

Thanks for looking into this.

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

-- 
Iain


Re: Fix D compilation on Solaris

2018-10-30 Thread Rainer Orth
Rainer Orth  writes:

> * On sparc, I didn't get that far, unfortunately: as I mentioned, many
>   compilations die with SIGBUS:
>
> libtool: compile:  /var/gcc/regression/trunk/11.5-gcc/build/./gcc/gdc 
> -B/var/gcc/regression/trunk/11.5-gcc/build/./gcc/ 
> -B/vol/gcc/sparc-sun-solaris2.11/bin/ -B/vol/gcc/sparc-sun-solaris2.11/lib/ 
> -isystem /vol/gcc/sparc-sun-solaris2.11/include -isystem 
> /vol/gcc/sparc-sun-solaris2.11/sys-include -fno-checking -fPIC -O2 -g 
> -nostdinc -I /vol/gcc/src/hg/trunk/local/libphobos/libdruntime -I . -c 
> /vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/thread.d 
> -fversion=Shared -o core/.libs/thread.o
> d21: internal compiler error: Bus Error
> 0xbb5507 crash_signal
> /vol/gcc/src/hg/trunk/local/gcc/toplev.c:325
> 0x518700 IntegerExp::toInteger()
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/expression.c:2943
> 0x4d05c3 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> 0x4d1543 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6017
> 0x4d1543 interpret(Statement*, InterState*)
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6024
> 0x4d263b interpretFunction
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:906
> 0x4d263b interpretFunction
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:726
> 0x4d05c3 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> 0x4d14df interpret(Expression*, InterState*, CtfeGoal)
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5994
> 0x4d05c3 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> 0x4d14df interpret(Expression*, InterState*, CtfeGoal)
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5994
> 0x5243d7 DeclarationExp::accept(Visitor*)
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/expression.h:661
> 0x4d05c3 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> 0x4d1543 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6017
> 0x4d1543 interpret(Statement*, InterState*)
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6024
> 0x4d263b interpretFunction
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:906
> 0x4d263b interpretFunction
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:726
> 0x4d05c3 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
> 0x4d14df interpret(Expression*, InterState*, CtfeGoal)
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5994
> 0x4d05c3 interpret
> /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
>
>   Will need to dig further here.

It's exactly as I suspected:

$ d21 /vol/gcc/src/hg/trunk/local/libphobos/libdruntime/core/thread.d -mcpu=v9 
-fversion=Shared -I /vol/gcc/src/hg/trunk/local/libphobos/libdruntime -o 
thread.s

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1 (LWP 1)]
0x00518700 in IntegerExp::toInteger (this=)
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/expression.c:2942
2942return value;
(gdb) where
#0  0x00518700 in IntegerExp::toInteger (this=)
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/expression.c:2942
#1  0x004d8f24 in Interpreter::visit(BinExp*) ()
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/declaration.h:292
#2  0x005268ec in CmpExp::accept(Visitor*) ()
#3  0x004d05c4 in interpret (pue=0xffbfbbf4, e=0x22778f0, istate=0xffbfc144, 
goal=ctfeNeedRvalue)
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:5984
#4  0x004d6254 in Interpreter::visit(ForStatement*) ()
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/declaration.h:292
#5  0x005aec68 in ForStatement::accept(Visitor*) ()
#6  0x004d475c in Interpreter::visit(CompoundStatement*) ()
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/declaration.h:292
#7  0x005b5708 in CompoundStatement::accept(Visitor*) ()
#8  0x004d4810 in Interpreter::visit(ScopeStatement*) ()
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/declaration.h:292
#9  0x005aec08 in ScopeStatement::accept(Visitor*) ()
#10 0x004d475c in Interpreter::visit(CompoundStatement*) ()
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/declaration.h:292
#11 0x005b5708 in CompoundStatement::accept(Visitor*) ()
#12 0x004d475c in Interpreter::visit(CompoundStatement*) ()
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/declaration.h:292
#13 0x005b5708 in CompoundStatement::accept(Visitor*) ()
#14 0x004d1544 in interpret (istate=, s=, 
pue=0xffbfc07c) at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6017
#15 interpret (s=0x22ea0f8, istate=0xffbfc144)
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:6024
#16 0x004d263c in interpretFunction (thisarg=0x22f6198, 
arguments=, istate=0xffbfcb5c, fd=0x2270cc0)
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:906
#17 interpretFunction (fd=0x2270cc0, istate=0xffbfcb5c, 
arguments=, thisarg=)
at /vol/gcc/src/hg/trunk/local/gcc/d/dmd/dinterpret.c:726
#18 0x004e22ac in 

Fix D compilation on Solaris

2018-10-30 Thread Rainer Orth
* 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.

# HG changeset patch
# Parent  21c0e7e50f9c14ddadbc6c3102da8956fb19e01f
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,39 @@
+/* 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");			\
+}
+
+#undef TARGET_D_OS_VERSIONS
+#define TARGET_D_OS_VERSIONS solaris_d_os_builtins
+
+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/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