Windows --> arm-linux cross compiler and lld

Mike Franklin slavo5150 at yahoo.com
Tue Apr 17 08:55:42 UTC 2018


On Tuesday, 17 April 2018 at 06:53:59 UTC, Joakim wrote:

> Btw, you may be interested in this thread about using the llvm 
> linker, lld, which delves into a lot of the issues involved 
> with not delegating to the C compiler:
>
> https://github.com/ldc-developers/ldc/issues/2028

Thanks, it was an interesting read.

IMO, however, all of this dependency and C (C runtime, C standard 
library, C compiler, etc...) is all superficial.  With a little 
more due diligence in the compiler and runtime implementations, 
none of it would be necessary.

I illustrate with the following example. It is a gross 
oversimplification but demonstrates that D doesn't need C...any 
of it.

---object.d
module object;

alias immutable(char)[] string;

private long __d_sys_write(long arg1, in void* arg2, long arg3)
{
     long result;

     asm
     {
         mov RAX, 1;
         mov RDI, arg1;
         mov RSI, arg2;
         mov RDX, arg3;
         syscall;
     }

     return result;
}

void write(string text)
{
     __d_sys_write(2, text.ptr, text.length);
}

private void __d_sys_exit(long arg1)
{
     asm
     {
         mov RAX, 60;
         mov RDI, arg1;
         syscall;
     }
}

extern void main();
private extern(C) void _start()
{
     main();
     __d_sys_exit(0);
}

---main.d
module main;

void main()
{
     write("Hello, World\n");
}

$dmd -c -lib -conf= object.d main.d -of=main.o
$ld main.o -o main
$size main
    text    data     bss     dec     hex filename
     176       0       0     176      b0 main
$main
Hello, World

I admit that without leveraging C (actually gcc, even llvm still 
needs the crt files from gcc) D would be assuming more work, but 
I think doing away with the C compiler and going directly to the 
linker is a step in the right direction.

Mike


More information about the digitalmars-d-ldc mailing list