Building for ARM with LDC

Mike via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Sun Jul 13 06:35:17 PDT 2014


On Sunday, 13 July 2014 at 12:42:41 UTC, Joseph Rushton Wakeling 
wrote:
> On Sunday, 13 July 2014 at 10:53:06 UTC, Mike wrote:
>> Are you targeting ARM (e.g. Cortex-A), or ARM Thumb (e.g 
>> Cortex-M)?
>
> Cortex-M, I believe.  But as all I'm doing for now is 
> qemu-based I guess I can adapt to either.

The very first compiler I used to make my semihosted hello world 
(http://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22) 
was LDC.  I haven't used it in while, though I intend to when I 
get a little farther with my project.

Once again, my goal was to have a compiler that I could use to 
create a D runtime, so I didn't need phobos or the D Runtime.  I 
don't know how many people know this, but you don't actually need 
the D Runtime to program in D.  You just have to keep yourself 
limited to a C-like subset of D.

If you want to use structs, however, you will need to give the 
compiler some phony TypeInfo stuff from the object.d/di file.  
See my example here: 
(https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/blob/master/1.3-structs/source/object.d). 
  I wrote a wiki about this too 
(https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/wiki/1.3-Structs). 
  This also needs to be done for GDC.  LDC would crash if I did 
not provide them 
(https://github.com/ldc-developers/ldc/issues/552).  Some of 
these issues seem to have been fixed 
(https://github.com/ldc-developers/ldc/issues/551), but I haven't 
gotten around to testing them and providing feedback.

Adam Ruppe actually recommended a potential solution to this 
nonsense (https://issues.dlang.org/show_bug.cgi?id=12270).

Also with LDC, I don't think there is a linker capable of 
creating an executable for ARM Cortex-M.  You can build binutils, 
or you can use the linker from here GNU Tools for ARM Embedded 
(https://launchpad.net/gcc-arm-embedded).

LDC folks, Does LLVM have its own linker?

LDC also needs to be built with an ARM Thumb LLVM backend. I did 
this, but I lost my script files :(  I'll have to recreate them.  
I remember it being much simpler than GDC.  I've asked the LDC 
folks to include an ARM Thumb backend in their release, but I 
don't think they've done it yet.  On Arch Linux, the LDC package 
seems to already include ARM Thumb:

ldc2 --version
LDC - the LLVM D compiler (0.13.0):
   based on DMD v2.064 and LLVM 3.4.2
   Default target: x86_64-unknown-linux-gnu
   Host CPU: corei7
   http://dlang.org - http://wiki.dlang.org/LDC

   Registered Targets:
     aarch64  - AArch64 (ARM 64-bit target)
     arm      - ARM
     cpp      - C++ backend
     hexagon  - Hexagon
     mips     - Mips
     mips64   - Mips64 [experimental]
     mips64el - Mips64el [experimental]
     mipsel   - Mipsel
     msp430   - MSP430 [experimental]
     nvptx    - NVIDIA PTX 32-bit
     nvptx64  - NVIDIA PTX 64-bit
     ppc32    - PowerPC 32
     ppc64    - PowerPC 64
     ppc64le  - PowerPC 64 LE
     r600     - AMD GPUs HD2XXX-HD6XXX
     sparc    - Sparc
     sparcv9  - Sparc V9
     systemz  - SystemZ
     thumb    - Thumb
     x86      - 32-bit X86: Pentium-Pro and above
     x86-64   - 64-bit X86: EM64T and AMD64
     xcore    - XCore


Mike




More information about the digitalmars-d-ldc mailing list