Thread overview
How can I use ldc2 and link to full runtime on arm with no OS
Jun 20, 2017
Dan Walmsley
Jun 20, 2017
kinke
Jun 21, 2017
Dan Walmsley
Jun 21, 2017
Dan Walmsley
Jun 21, 2017
David Nadlinger
Jun 21, 2017
Dan Walmsley
Jun 21, 2017
David Nadlinger
Jun 22, 2017
Mike
Jun 21, 2017
David Nadlinger
June 20, 2017
I'm starting to make attempts to find out what is needed to make D finally work on low level embedded targets. I have been using LDC2, i compile each .d file to and .o file and link using arm-none-eabi-gcc. I have a demo available here: Www.github.com/vitalelement/stm32dblinky includes a linked script.

I was originally trying to have a minimal run time approach but having read a lot here I don't buy the argument that these targets cant run with GC. So id like to now link to the full run time if possible and try out the GC.

However there doesn't seem to be any guide on how to do this?

I need to know, how does the run time know which area of ram to use for heap? In c/c++ usually we use linked script to provide an area of ram for this.

How do I link in the run time and gc, etc?

Many thanks

Dan

June 20, 2017
On Tuesday, 20 June 2017 at 17:52:59 UTC, Dan Walmsley wrote:
> How do I link in the run time and gc, etc?

In your case, you firstly need to cross-compile druntime to your target. This means compiling most files in the src subdirectory of LDC's druntime [1], excluding obvious ones like src\test_runner.d, src\core\sys, src\core\stdcpp etc. There are also a bunch of C and assembly files which need to be cross-compiled with a matching gcc. You'll need to do this manually via something along these lines:

cross-gcc -c <.c files and .asm/S files>
ldc2 -mtriple=... -lib -betterC -release -boundscheck=off <.o files generated above> <list of D source modules> -of=libdruntime.a

Then try linking your minimal code against that druntime (and static C libs, as druntime is built on top of the C runtime, see [2]). Depending on what features you make use of in your code, you'll need to patch linked-in druntime modules to remove the OS dependencies and possibly reduce the C runtime dependencies as well.

[1] https://github.com/ldc-developers/druntime.
[2] http://forum.dlang.org/thread/mojmxbjwtfmioevuoggb@forum.dlang.org
June 21, 2017
On Tuesday, 20 June 2017 at 17:52:59 UTC, Dan Walmsley wrote:
> I need to know, how does the run time know which area of ram to use for heap?

It uses C's malloc/calloc().

 — David
June 21, 2017
On Tuesday, 20 June 2017 at 19:44:46 UTC, kinke wrote:
> On Tuesday, 20 June 2017 at 17:52:59 UTC, Dan Walmsley wrote:
>> How do I link in the run time and gc, etc?
>
> In your case, you firstly need to cross-compile druntime to your target. This means compiling most files in the src subdirectory of LDC's druntime [1], excluding obvious ones like src\test_runner.d, src\core\sys, src\core\stdcpp etc. There are also a bunch of C and assembly files which need to be cross-compiled with a matching gcc. You'll need to do this manually via something along these lines:
>
> cross-gcc -c <.c files and .asm/S files>
> ldc2 -mtriple=... -lib -betterC -release -boundscheck=off <.o files generated above> <list of D source modules> -of=libdruntime.a
>
> Then try linking your minimal code against that druntime (and static C libs, as druntime is built on top of the C runtime, see [2]). Depending on what features you make use of in your code, you'll need to patch linked-in druntime modules to remove the OS dependencies and possibly reduce the C runtime dependencies as well.
>
> [1] https://github.com/ldc-developers/druntime.
> [2] http://forum.dlang.org/thread/mojmxbjwtfmioevuoggb@forum.dlang.org

when trying to compile I'm getting lots of errors like this one:

C:\dev\repos\druntime\src\gc\impl\manual\gc.d(28): Error: module config is in file 'gc\config.d' which cannot be read

import path[0] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import\ldc

import path[1] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import

Build Failed

any ideas what could be the cause?

June 21, 2017
On Wednesday, 21 June 2017 at 14:53:04 UTC, Dan Walmsley wrote:
> On Tuesday, 20 June 2017 at 19:44:46 UTC, kinke wrote:
>> [...]
>
> when trying to compile I'm getting lots of errors like this one:
>
> C:\dev\repos\druntime\src\gc\impl\manual\gc.d(28): Error: module config is in file 'gc\config.d' which cannot be read
>
> import path[0] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import\ldc
>
> import path[1] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import
>
> Build Failed
>
> any ideas what could be the cause?

and also:


LLVM ERROR: unsupported relocation on symbol
[CC 9/164]    [druntime]    convert.d

Build Failed

LLVM ERROR: unsupported relocation on symbol

after changing flags to:

-c -O0 -lib -betterC -release -boundscheck=off -march=thumb -mcpu=cortex-m4 -mtriple=thumb-none-linux-eabi
June 21, 2017
On Wednesday, 21 June 2017 at 14:53:04 UTC, Dan Walmsley wrote:
> when trying to compile I'm getting lots of errors like this one:
>
> C:\dev\repos\druntime\src\gc\impl\manual\gc.d(28): Error: module config is in file 'gc\config.d' which cannot be read
>
> import path[0] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import\ldc
>
> import path[1] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import
>
> Build Failed
>
> any ideas what could be the cause?

You are not adding druntime/src to the import path.

I'd suggest you focus on other things first, though. Having D's GC on a platform with less than 1 MiB RAM is a rather sketchy proposition.

 — David
June 21, 2017
On Wednesday, 21 June 2017 at 15:45:32 UTC, David Nadlinger wrote:
> On Wednesday, 21 June 2017 at 14:53:04 UTC, Dan Walmsley wrote:
>> when trying to compile I'm getting lots of errors like this one:
>>
>> C:\dev\repos\druntime\src\gc\impl\manual\gc.d(28): Error: module config is in file 'gc\config.d' which cannot be read
>>
>> import path[0] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import\ldc
>>
>> import path[1] = C:\Users\danw\AvalonStudio\AppData\Repos\AvalonStudio.Toolchains.LDC.win-x64.4.0.0-build2-alpha\content\bin\..\import
>>
>> Build Failed
>>
>> any ideas what could be the cause?
>
> You are not adding druntime/src to the import path.
>
> I'd suggest you focus on other things first, though. Having D's GC on a platform with less than 1 MiB RAM is a rather sketchy proposition.
>
>  — David

My idea is to build the whole thing, see what the code size and performance is, and then one by one reduce things down as needed.

Starting from nothing so far has been a bit of a none starter!
June 21, 2017
On Wednesday, 21 June 2017 at 16:10:41 UTC, Dan Walmsley wrote:
> My idea is to build the whole thing, see what the code size and performance is, and then one by one reduce things down as needed.
>
> Starting from nothing so far has been a bit of a none starter!

This way, you'll end up having to port all of druntime to your target, though, only to then throw away considerable amounts of work that went into the parts you don't want to use.

I don't think the notion of implementing a feature being easier than understanding how to rip it out is very realistic.

 — David
June 22, 2017
On Wednesday, 21 June 2017 at 22:11:04 UTC, David Nadlinger wrote:

> This way, you'll end up having to port all of druntime to your target, though, only to then throw away considerable amounts of work that went into the parts you don't want to use.

You are correct, but if you omit certain parts of the runtime, you end up with things like these:

https://github.com/ldc-developers/ldc/issues/2174
https://github.com/ldc-developers/ldc/issues/552
https://github.com/ldc-developers/ldc/issues/781

The compiler and druntime are too tightly-coupled to make pay-as-you-go D development practical.  Some support to remedy that would be most welcome.

Mike