Jump to page: 1 2
Thread overview
LDC with ARM backend
Jul 15, 2016
Claude
Jul 15, 2016
Radu
Jul 15, 2016
Claude
Jul 15, 2016
Kai Nacke
Jul 19, 2016
Claude
Jul 20, 2016
Claude
Jul 20, 2016
Claude
Jul 21, 2016
Claude
Jul 21, 2016
Andrea Fontana
Jul 21, 2016
Claude
Aug 01, 2016
Kai Nacke
Aug 02, 2016
Joakim
Aug 09, 2016
Claude
July 15, 2016
Hello,

I would like to cross-compile a D program from a x86 machine to an ARM target.

I work on GNU/Linux Ubuntu 64-bit.
I have an ARM gcc toolchain, which I can use to make programs on an ARM Cortex-A9 architecture running a Linux kernel 3.4.11+.

I managed to build and install LLVM 3.8.1 with LDC 1.1-alpha1, which works fine to build and run native programs.

I read some documentation here:
http://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22

... but it seems to target bare-metal programming, whereas I already have a GNU/Linux running on my ARM target and want to use it. It does noty tell how to have an LDC with ARM backend.

So I'm a bit confused of what the current state of LDC+ARM is. For example, is the run-time fully ported on ARM/Linux?

What would be the steps to have an LDC cross-compiling to ARM?

Thanks
July 15, 2016
On Friday, 15 July 2016 at 14:09:40 UTC, Claude wrote:
> Hello,
>
> I would like to cross-compile a D program from a x86 machine to an ARM target.
>
> I work on GNU/Linux Ubuntu 64-bit.
> I have an ARM gcc toolchain, which I can use to make programs on an ARM Cortex-A9 architecture running a Linux kernel 3.4.11+.
>
> I managed to build and install LLVM 3.8.1 with LDC 1.1-alpha1, which works fine to build and run native programs.
>
> I read some documentation here:
> http://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22
>
> ... but it seems to target bare-metal programming, whereas I already have a GNU/Linux running on my ARM target and want to use it. It does noty tell how to have an LDC with ARM backend.
>
> So I'm a bit confused of what the current state of LDC+ARM is. For example, is the run-time fully ported on ARM/Linux?
>
> What would be the steps to have an LDC cross-compiling to ARM?
>
> Thanks

Hi,
LDC on Linux ARM is fairly complete. I think it is a fully supported platform (all tests are passing). Check in https://wiki.dlang.org/Compilers the LDC column.

This is the close for a tutorial for cross-compiling https://wiki.dlang.org/Build_LDC_for_Android builds.
July 15, 2016
On Friday, 15 July 2016 at 15:02:15 UTC, Radu wrote:
> Hi,
> LDC on Linux ARM is fairly complete. I think it is a fully supported platform (all tests are passing). Check in https://wiki.dlang.org/Compilers the LDC column.
>
> This is the close for a tutorial for cross-compiling https://wiki.dlang.org/Build_LDC_for_Android builds.

Great, I didn't see it.

However I don't use Android on my ARM target, I have a arm-none-linux-gnueabi toolchain.

I think I have to change the Android patch, keep the "80-bit float" stuff, and modify the build scripts somehow to use GNU version.
July 15, 2016
Hi Claude!

On Friday, 15 July 2016 at 14:09:40 UTC, Claude wrote:
> Hello,
>
> I would like to cross-compile a D program from a x86 machine to an ARM target.
> [...]
> So I'm a bit confused of what the current state of LDC+ARM is. For example, is the run-time fully ported on ARM/Linux?

LDC is fully ported to Linux/ARM. The current release also includes LDC pre-compiled for ARMv7 with hard floats (e.g. matches recent Raspberry hardware). On such a platform you can simply unpack the binary packages and LDC should run out of the box.

> What would be the steps to have an LDC cross-compiling to ARM?

That is a somewhat different story. First, you need to built LLVM with support for ARM and then compile LDC against this version of LLVM. You can run ldc2 -version to see if the ARM target is supported. As Radu already mentioned, most of the required steps are described in the wiki at https://wiki.dlang.org/Build_LDC_for_Android. From a different perspective there is an old news post about cross-compiling to AArch64, too: http://forum.dlang.org/post/fhwvxatxezkafnalwhqr@forum.dlang.org.

There is a reason why we do not distribute a binary version of LDC with all LLVM targets enabled. LDC still uses the real format of the host. This is different on ARM (80bit on Linux/x86 vs. 64bit on Linux/ARM). Do not expect that applications using real type work correctly.
(The Windows version of LDC uses 64bit reals. The binary build has the ARM target enabled.)

Regards,
Kai
July 19, 2016
On Friday, 15 July 2016 at 15:24:36 UTC, Kai Nacke wrote:
> There is a reason why we do not distribute a binary version of LDC with all LLVM targets enabled. LDC still uses the real format of the host. This is different on ARM (80bit on Linux/x86 vs. 64bit on Linux/ARM). Do not expect that applications using real type work correctly.
> (The Windows version of LDC uses 64bit reals. The binary build has the ARM target enabled.)
>
> Regards,
> Kai

Hello Kai,

Thanks for your answer.

From the link https://wiki.dlang.org/Build_LDC_for_Android , I did exactly the same steps described in section "Compile LLVM" (patch applied).

At section "Build ldc for Android/ARM", I did it quite the same. I applied the patch ldc_1.0.0_android_arm, but changed runtime/CMakeList.txt, instead of using Android specific stuff, I did:


Line 15:
set(D_FLAGS               -w;-mtriple=arm-none-linux-gnueabi        CACHE STRING  "Runtime build flags, separated by ;")

Line 505:
#
# Set up build targets.
#
set(RT_CFLAGS "-g")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER /opt/arm-2009q1/bin/arm-none-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /opt/arm-2009q1/bin/arm-none-linux-gnueabi-c++)



On the command line, I aliased DMD to /usr/bin/dmd and runt cmake as described...

Afterwards, I ran make for ldc2, phobos2-ldc an druntime-ldc, but I did not apply the patches on phobos and runtime. It looked like the path introduced some static compilation towards Android, so I thought it would not apply to my needs.

So here' what I get if I do a "ldc2 -version":


LDC - the LLVM D compiler (1.0.0):
  based on DMD v2.070.2 and LLVM 3.8.1
  built with DMD64 D Compiler v2.071.1
  Default target: x86_64-unknown-linux-gnu
  Host CPU: westmere
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    arm     - ARM
    armeb   - ARM (big endian)
    thumb   - Thumb
    thumbeb - Thumb (big endian)



I can strictly compile a "hello world" program:
./bin/ldc2 -mtriple=arm-none-linux-gnueabi test.d

I get the expected "test.o"

But I don't know how to link it. I don't have "clang". I tried to link it with the gcc from the gnu ARM toolchain with libdruntime-ldc.a, libldc.a and libphobos2-ldc.a, but it fails miserably: many undefined symbols (pthread, and some other os related stuff).
July 20, 2016
I think my cross-compile LDC is fine.

I tried to build this D program:

/// loire.d
int main()
{
    return 42;
}



However, the run-time is not (neither is phobos), most of the linker issues come from the druntime. So...

I wrote my own druntime. Here's the code:

/// dummyruntime.d
// from rt/sections_elf_shared.d, probably don't need it right now...
extern(C) void _d_dso_registry(void* data)
{
}

// from rt/dmain2.d, just call my D main(), ignore args...
private alias extern(C) int function(char[][] args) MainFunc;

extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
{
    return mainFunc(null);
}



I built everything:

# Compilation
./bin/ldc2 -mtriple=arm-none-linux-gnueabi -c loire.d
./bin/ldc2 -mtriple=arm-none-linux-gnueabi -c dummyruntime.d
# Link
/opt/arm-2009q1/bin/arm-none-linux-gnueabi-gcc loire.o dummyruntime.o -o loire


And I ran it successfully on my ARM target:

$> loire
$> echo $?
42



So now I know I have a proper LDC cross-compiler! :)

I'm jut missing a proper druntime and phobos for GNU/Linux ARM.
July 20, 2016
So I'm trying to build druntime correctly, I corrected some problems here and there, but I still cannot link with libdruntime-ldc.a:


/opt/arm-2009q1/bin/arm-none-linux-gnueabi-gcc loire.o lib/libdruntime-ldc.a -o loire


I get many errors like:

/opt/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld: lib/libdruntime-ldc.a(libunwind.o)(.text._D3ldc2eh6common61__T21eh_personality_commonTS3ldc2eh9libunwind13NativeContextZ21eh_personality_commonUKS3ldc2eh9libunwind13NativeContextZ3acbMFNbNcNiNfZPS3ldc2eh6common18ActiveCleanupBlock[_D3ldc2eh6common61__T21eh_personality_commonTS3ldc2eh9libunwind13NativeContextZ21eh_personality_commonUKS3ldc2eh9libunwind13NativeContextZ3acbMFNbNcNiNfZPS3ldc2eh6common18ActiveCleanupBlock]+0x38): R_ARM_TLS_IE32 used with non-TLS symbol _D3ldc2eh6common21innermostCleanupBlockPS3ldc2eh6common18ActiveCleanupBlock




R_ARM_TLS_IE32 used with non-TLS symbol ??
July 21, 2016
On Wednesday, 20 July 2016 at 16:10:48 UTC, Claude wrote:
> R_ARM_TLS_IE32 used with non-TLS symbol ??

Oh, that was actually quite obvious... If I revert the first android patch on LLVM sources, and build it back it works!

I can build a "Hello world" program on ARM GNU/Linux, with druntime and phobos.
I'll write a doc page about that.
July 21, 2016
On Thursday, 21 July 2016 at 09:59:53 UTC, Claude wrote:
> I can build a "Hello world" program on ARM GNU/Linux, with druntime and phobos.
> I'll write a doc page about that.

It's a good idea :)

July 21, 2016
On Thursday, 21 July 2016 at 10:30:55 UTC, Andrea Fontana wrote:
> On Thursday, 21 July 2016 at 09:59:53 UTC, Claude wrote:
>> I can build a "Hello world" program on ARM GNU/Linux, with druntime and phobos.
>> I'll write a doc page about that.
>
> It's a good idea :)

Done:

https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux

I based it totally on Kai's previous page for LDC on Android.

It lacks the build for druntime/phobos unit-tests.
« First   ‹ Prev
1 2