Compiling to 68K processor (Maybe GDC?)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Jan 20 09:27:33 UTC 2019


On Saturday, January 19, 2019 10:45:41 AM MST Patrick Schluter via 
Digitalmars-d-learn wrote:
> On Saturday, 19 January 2019 at 12:54:28 UTC, rikki cattermole
>
> wrote:
> > On 20/01/2019 1:38 AM, Edgar Vivar wrote:
> >> Hi,
> >>
> >> I have a project aiming to old 68K processor. While I don't
> >> think DMD would be able for this on the other hand I think GDC
> >> can, am I right?
> >>
> >> If yes would be any restriction of features to be used? Or the
> >> compiler would be smart enough to handle this properly?
> >>
> >> Edgar V.
> >
> > Potentially.
> >
> > D is designed to only work on 32bit+ architectures. The 68k
> > series did have 32bit versions of them.
> >
> > After a quick check it does look like LDC is out as LLVM has
> > not yet got support for M68k target. Which is unfortunate
> > because with the -betterC flag it could have pretty much out of
> > the box worked. Even if you don't have most of D at your
> > disposal e.g. classes and GC (but hey old cpu! can't expect
> > that).
> >
> > I have no idea about GDC, but the -betterC flag is pretty
> > recent so its support may not be what you would consider first
> > class there yet.
>
> At least 68030 (or 68020+68851) would be necessary for proper
> segfault managing (MMU) and an OS that uses it. Afaict NULL
> pointer derefernecing must fault for D to be "usable". At least
> all code is written with that assumption.

For @safe to work properly, dereferencing null must be @safe, which means
more or less means that either it results in a segfault, or the compiler has
to add additional checks to ensure that null isn't dereferenced. The
situation does get a bit more complicated in the details (e.g. calling a
non-virtual member function on a null pointer or reference wouldn't segfault
if the object's members are never actually accessed, and that's fine,
because it doesn't violate @safe), but in general, either a segfault must
occur, or the compiler has to add extra checks so that invalid memory is not
accessed. At this point, AFAIK, all of the D compilers assume that
dereferencing null will segfault, and they don't ever add additional checks.
If an architecture does not segfault when dereferencing null, then it will
need special handling by the compiler, and I don't think that ever happens
right now. So, if D were compiled on such an architecture, @safe wouldn't
provide the full guarantees that it's supposed to.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list