Building LDC runtime for a microcontroller
IGotD-
nise at nise.com
Mon Sep 7 16:18:00 UTC 2020
On Monday, 7 September 2020 at 15:23:28 UTC, Severin Teona wrote:
>
> I would also appreciate any advice regarding ways to build or
> create a small runtime for microcontrollers (runtime that can
> fit in the memory of a microcontroller).
> Thank you very much,
> Teona
>
> [1]: https://wiki.dlang.org/Building_LDC_runtime_libraries
> [2]:
> https://github.com/golang/go/issues/36633#issuecomment-576411479
Use betterC, which is much better suited for microcontrollers
than the full D. The disadvantage is that many great features are
disabled in betterC.
I have ported druntime/phobos to my system. This is pretty large
job because structure of druntime/phobos is not very good for
adding/porting to new systems. It's a cascade of version(this) {}
else version(that) {}. Some functionality must be ported, some
others can just be stubbed.
Keep in mind that you in general have to port phobos as well
because it contains many useful functions like parsing and
conversion. The OS dependent stuff is mixed together with OS
independent.
For an ARM target I get about a compiled size of about 500KB of a
simple Hello world program when linked statically. This isn't
really microcontroller size to begin with. The size quickly
increases as you start to use more modules from druntime/phobos.
Another interesting observation is that druntime has a option to
use malloc/free in a clib rather than map/VirtualAlloc for GC
allocations. What druntime does is over allocate because it
requires page aligned memory. The result is that this workaround
waste a lot of memory.
The conclusion is that D as it is isn't really suitable for
systems that are memory limited or lack an MMU (reason is that
shared libraries don't work). D is like C++ will full STL support
which is also very large. Embedded programmers who use C++ almost
never use STL because of this, among other things.
More information about the Digitalmars-d-learn
mailing list