www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Embedded Systems (STM32) LDC Absolute minimal runtime

reply Dan Walmsley <dan walms.co.uk> writes:
Hi guys,

    I run an open source project developing a modern cross 
platform IDE for embedded systems, 
https://github.com/VitalElement/avalonStudio (perhaps the IDE 
could complement D as I have not found many just works out the 
box solutions for D yet.)

    I have begun to integrate the LDC compiler and would also like 
to attempt to use D in an upcoming embedded project I have.

I have played around with the betterC flag and it looks 
promising. I would also like to have use of classes, however as 
soon as I try to use a class I get many link errors. see below:

The  undefined reference to `_d_dso_registry' comes from removing 
the -betterC flag.

I understand these other symbols would be provided by object.d, 
however I am unable to find an object.d that will compile on LDC, 
and ideally a minimal implementation.

Can anyone help?


C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o: In function 
`_D4main9TestClass3SumMFZi':
C:\dev\repos\STM32DBlinky\Blinky/main.d:9: undefined reference to 
`_D9invariant12_d_invariantFC6ObjectZv'
C:\dev\repos\STM32DBlinky\Blinky/main.d:9: undefined reference to 
`_d_assert_msg'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o: In function 
`ldc.register_dso':
C:\dev\repos\STM32DBlinky\Blinky\main.d:(.text.ldc.register_dso+0x60):
undefined reference to `_d_dso_registry'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9Test
lass6__vtblZ]+0x4): undefined reference to `_D6object6Object8toStringMFZAya'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9Test
lass6__vtblZ]+0x8): undefined reference to `_D6object6Object6toHashMFNbNeZk'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9Test
lass6__vtblZ]+0xc): undefined reference to `_D6object6Object5opCmpMFC6ObjectZi'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9TestC
ass6__vtblZ]+0x10): undefined reference to
`_D6object6Object8opEqualsMFC6ObjectZb'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data._D4main9TestClass7__ClassZ[_D4main9TestC
ass7__ClassZ]+0x0): undefined reference to `_D14TypeInfo_Class6__vtblZ'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data._D4main9TestClass7__ClassZ[_D4main9TestCl
ss7__ClassZ]+0x28): undefined reference to `_D6Object7__ClassZ'
Jun 19
next sibling parent Mike <none none.com> writes:
On Monday, 19 June 2017 at 10:24:29 UTC, Dan Walmsley wrote:

 I have played around with the betterC flag and it looks 
 promising. I would also like to have use of classes, however as 
 soon as I try to use a class I get many link errors. see below:
It is my understanding that the DMD -betterC switch currently only disables generating ModuleInfo. Walter's recent pull request (http://forum.dlang.org/post/oi9v2q$23ms$1 digitalmars.com) makes it do a little more. It is also my understanding the -betterC is just an idea at the moment, and what it should do has not yet been defined.
 The  undefined reference to `_d_dso_registry' comes from 
 removing the -betterC flag.

 I understand these other symbols would be provided by object.d, 
 however I am unable to find an object.d that will compile on 
 LDC, and ideally a minimal implementation.
The most minimal implementation I'm aware of is this: https://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22 If you're targeting STM32, you may also be interested in this: https://github.com/JinShil/stm32f42_discovery_demo I haven't tested either of those in quite some time, so I doubt the will compile out of the box. But basically, what you need is a minimal runtime implementation that implements the features of D that your code is using, and unfortunately, some that your code isn't using but is required by the compiler just to get a build.
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o: In function 
 `_D4main9TestClass3SumMFZi':
 C:\dev\repos\STM32DBlinky\Blinky/main.d:9: undefined reference 
 to `_D9invariant12_d_invariantFC6ObjectZv'
 C:\dev\repos\STM32DBlinky\Blinky/main.d:9: undefined reference 
 to `_d_assert_msg'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o: In function 
 `ldc.register_dso':
 C:\dev\repos\STM32DBlinky\Blinky\main.d:(.text.ldc.register_dso+0x60):
undefined reference to `_d_dso_registry'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9Test
lass6__vtblZ]+0x4): undefined reference to `_D6object6Object8toStringMFZAya'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9Test
lass6__vtblZ]+0x8): undefined reference to `_D6object6Object6toHashMFNbNeZk'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9Test
lass6__vtblZ]+0xc): undefined reference to `_D6object6Object5opCmpMFC6ObjectZi'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9TestC
ass6__vtblZ]+0x10): undefined reference to
`_D6object6Object8opEqualsMFC6ObjectZb'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data._D4main9TestClass7__ClassZ[_D4main9TestC
ass7__ClassZ]+0x0): undefined reference to `_D14TypeInfo_Class6__vtblZ'
 C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data._D4main9TestClass7__ClassZ[_D4main9TestCl
ss7__ClassZ]+0x28): undefined reference to `_D6Object7__ClassZ'
`_d_assert_msg` and `_d_dso_registry` and those symbols with `_d_invariant` in them look like missing druntime implementations. You can see an old and unmaintained list of such "runtime hooks" here: https://wiki.dlang.org/Runtime_Hooks. Each compiler (DMD, LDC, and GDC) have their own druntime implementation, unfortunately. LDC's implementation is here: https://github.com/ldc-developers/druntime I suspect the `.data.re.ro.*` symbols are the result of an error in your linker script. That is you haven't added that `.data` section to your linker script, so the symbols aren't being populated. I'd have to see your linker script and source code before I spend to much mental energy on it, though. No compiler that I'm aware has a druntime implementation for the ARM Cortex-M architecture, so the onus is on you to build implement whatever features the toolchain is complaining about. Mike
Jun 20
prev sibling parent Kagamin <spam here.lot> writes:
I believe you can do without any runtime at all, but it's a 
tradeoff, see also 
https://forum.dlang.org/post/tmofjecvnqdthvetezfp forum.dlang.org
Jun 20