www.digitalmars.com         C & C++   DMDScript  

D.gnu - iphone + D, getting closer!

reply Dan Olson <zans.is.for.cans yahoo.com> writes:
Ok, D is not there yet, but I managed to build a crippled gcc-4.8 (with
D) targeting arm-apple-darwin and I can compile simple C functions to .o
files and link them into an iphone app.  And run it on my iphone.  The D
and C++ compilers built, but I have probably a potpourri of issues since
I gave 4.8 a arm-darwin target by selectively copying apple's 4.2
changes for arm-darwin.  gcc-4.8 was configured to use tools (as, ld) in
the apple iphone SDK.

The biggest hassle is that apple's version of arm as is different than
binutils as.  So I am learning what it wants for debug and pseudo op
differences.

Even a simple D module with just a extern(C) function depends on
something in druntime, so I have to get part of that to build first.

-- 
dano
Nov 11 2012
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-11-12 02:38, Dan Olson wrote:
 Ok, D is not there yet, but I managed to build a crippled gcc-4.8 (with
 D) targeting arm-apple-darwin and I can compile simple C functions to .o
 files and link them into an iphone app.  And run it on my iphone.  The D
 and C++ compilers built, but I have probably a potpourri of issues since
 I gave 4.8 a arm-darwin target by selectively copying apple's 4.2
 changes for arm-darwin.  gcc-4.8 was configured to use tools (as, ld) in
 the apple iphone SDK.

 The biggest hassle is that apple's version of arm as is different than
 binutils as.  So I am learning what it wants for debug and pseudo op
 differences.

 Even a simple D module with just a extern(C) function depends on
 something in druntime, so I have to get part of that to build first.

Cool, I'm really looking forward to this. How did it go with the simulator? -- /Jacob Carlborg
Nov 11 2012
parent reply Dan Olson <zans.is.for.cans yahoo.com> writes:
Jacob Carlborg <doob me.com> writes:
 Cool, I'm really looking forward to this. How did it go with the simulator?

D for the iphone simulator worked without changes to gcc-4.8 src since it targets i686 darwin fine. To get it to work it was more of finding the right config recipe. I did have to use my druntme changes for osx. For the simulator, I built an i686-apple-darwin target and had it use the iphone simulator sdk + as, ld toolchain. To run D code in the iphone sim, the D code is compiled to .o files on the command line then added to an xcode project along with libgphobos2.a and libgcc_eh.a. I give my D code an extern(C) entry point so I can kick it off. -- dano
Nov 12 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-11-12 16:28, Dan Olson wrote:

 D for the iphone simulator worked without changes to gcc-4.8 src since
 it targets i686 darwin fine.  To get it to work it was more of finding
 the right config recipe.  I did have to use my druntme changes for osx.
 For the simulator, I built an i686-apple-darwin target and had it use
 the iphone simulator sdk + as, ld toolchain.

 To run D code in the iphone sim, the D code is compiled to .o files on
 the command line then added to an xcode project along with libgphobos2.a
 and libgcc_eh.a.  I give my D code an extern(C) entry point so I can
 kick it off.

Sounds like a great start :) -- /Jacob Carlborg
Nov 12 2012
prev sibling next sibling parent reply Johannes Pfau <nospam example.com> writes:
Am Sun, 11 Nov 2012 17:38:08 -0800
schrieb Dan Olson <zans.is.for.cans yahoo.com>:

 Ok, D is not there yet, but I managed to build a crippled gcc-4.8
 (with D) targeting arm-apple-darwin and I can compile simple C
 functions to .o files and link them into an iphone app.  And run it
 on my iphone.  The D and C++ compilers built, but I have probably a
 potpourri of issues since I gave 4.8 a arm-darwin target by
 selectively copying apple's 4.2 changes for arm-darwin.  gcc-4.8 was
 configured to use tools (as, ld) in the apple iphone SDK.
 
 The biggest hassle is that apple's version of arm as is different than
 binutils as.  So I am learning what it wants for debug and pseudo op
 differences.
 
 Even a simple D module with just a extern(C) function depends on
 something in druntime, so I have to get part of that to build first.
 

_Dmodule_ref? You can just declare it as extern(C) __gshared void* _Dmodule_ref; (But IIRC you have to compile with -nophoboslib to make it work) It's used by the runtime/compiler to setup the ModuleInfos but you don't have to initialize it, it just needs to be declared.
Nov 12 2012
next sibling parent "Timo Sintonen" <t.sintonen luukku.com> writes:
On Monday, 12 November 2012 at 08:31:32 UTC, Johannes Pfau wrote:
 Am Sun, 11 Nov 2012 17:38:08 -0800
 schrieb Dan Olson <zans.is.for.cans yahoo.com>:


 
 Even a simple D module with just a extern(C) function depends 
 on
 something in druntime, so I have to get part of that to build 
 first.
 

_Dmodule_ref? You can just declare it as extern(C) __gshared void* _Dmodule_ref; (But IIRC you have to compile with -nophoboslib to make it work) It's used by the runtime/compiler to setup the ModuleInfos but you don't have to initialize it, it just needs to be declared.

Module initialization code seems to use _Dmodule_ref to make some kind of linked list of module constructors even when we do not have any. I disabled module stuff from d-glue.cc:2828. The only unresolved reference I get now is __aeabi_unwind_cpp_pr1, which is found in libgcc.a. This library may not be searched by default in cross compilers, but has to be given separately. In arm compiler it should be checked in gcc sources that the right library for the target processor is generated (Cortex libraries for example are not generated by default) The file is in one in gcc-source/gcc/config/arm/t-* . If the library is there it has to be checked that the linker finds the right one. Command gcc -print-libgcc-file-name tells the library name and gcc -print-multi-lib tells the available libraries I have now a minimum libdruntime library for arm-eabi. If there are any other unresolved symbols, please let us know.
Nov 12 2012
prev sibling next sibling parent Dan Olson <zans.is.for.cans yahoo.com> writes:
Johannes Pfau <nospam example.com> writes:
 _Dmodule_ref?
 You can just declare it as extern(C) __gshared void* _Dmodule_ref; (But
 IIRC you have to compile with -nophoboslib to make it work)
 It's used by the runtime/compiler to setup the ModuleInfos but you
 don't have to initialize it, it just needs to be declared.

I might try that. It will give me a warm+fuzy before I get all of libgdruntime built. It would just be a simple "Hello D" to the console using puts(). My main task now is creating a arm-*-darwin target for libgcc. Last time I worked on gcc for a custom toolchain, libgcc was configured as part of gcc.
Nov 12 2012
prev sibling next sibling parent Dan Olson <zans.is.for.cans yahoo.com> writes:
Dan Olson <zans.is.for.cans yahoo.com> writes:

 Johannes Pfau <nospam example.com> writes:
 _Dmodule_ref?
 You can just declare it as extern(C) __gshared void* _Dmodule_ref; (But
 IIRC you have to compile with -nophoboslib to make it work)
 It's used by the runtime/compiler to setup the ModuleInfos but you
 don't have to initialize it, it just needs to be declared.

I might try that. It will give me a warm+fuzy before I get all of libgdruntime built. It would just be a simple "Hello D" to the console using puts().

Ok, that gave me an arm object file with simple D code. I linked in to an iphone app. When I run, module init code get called (yeah) but soon tries a move from an bad address. Probably my own doing with my port of arm-darwin. I'll look through Timo post, see if it is related. Later this week I will compare my toolchain's D assembler output with a D arm-eabi chain, see what's up.
Nov 12 2012
prev sibling parent Dan Olson <zans.is.for.cans yahoo.com> writes:
Dan Olson <zans.is.for.cans yahoo.com> writes:

 Dan Olson <zans.is.for.cans yahoo.com> writes:

 Johannes Pfau <nospam example.com> writes:
 _Dmodule_ref?
 You can just declare it as extern(C) __gshared void* _Dmodule_ref; (But
 IIRC you have to compile with -nophoboslib to make it work)
 It's used by the runtime/compiler to setup the ModuleInfos but you
 don't have to initialize it, it just needs to be declared.

I might try that. It will give me a warm+fuzy before I get all of libgdruntime built. It would just be a simple "Hello D" to the console using puts().

Ok, that gave me an arm object file with simple D code. I linked in to an iphone app. When I run, module init code get called (yeah) but soon tries a move from an bad address. Probably my own doing with my port of arm-darwin. I'll look through Timo post, see if it is related. Later this week I will compare my toolchain's D assembler output with a D arm-eabi chain, see what's up.

Well, I got some time to work on this again. More progress, although a baby step. D compiled code running in an iphone. Looks like my modified gcc-4.8 -fPIC assembler output is not correct, but it (and PIE) is the default for an iphone toolchain. So for now I turn off PIC and then can compile and execute a simple D module that needs no druntime support or emutls. That's it for now. I include some of the details below if anyone is interested in following this. ncc is an alias to a freshly built xgcc as I work on the gcc build: # My latest gcc-4.8 for arm-darwin alias ncc='/Users/dan/projects/gdc/ios-arm-obj/./gcc/xgcc -B/Users/dan/projects/gdc/ios-arm-obj/./gcc/ -B/usr/local/gdc-iosim/arm-apple-darwin/bin/ -B/usr/local/gdc-iosim/arm-apple-darwin/lib/ -isystem /usr/local/gdc-iosim/arm-apple-darwin/include -isystem /usr/local/gdc-iosim/arm-apple-darwin/sys-include --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk' Build a .o (I have some warnings to look at): $ ncc -O2 -fno-pic -I ~/projects/gdc/devnew/libphobos/libdruntime -c dhello.d cc1d: warning: command line option '-fno-builtin-strcat' is valid for C/C++/ObjC/ObjC++ but not for D cc1d: warning: command line option '-fno-builtin-strcpy' is valid for C/C++/ObjC/ObjC++ but not for D cc1d: warning: this target does not support '-fsection-anchors' The linker complains about not being able to use PIE (because I am cheating with -fno-pic). Also, link complains about CPU_SUBTYPE_ARM_ALL subtype is deprecated, so I need to look into that. ---- dhello.d ---- extern (C) { __gshared void* _Dmodule_ref; int puts(const(char) *str); int write(int fd, const(void*) buf, int len); } extern(C) int dhello() { puts("dhello is puts()ing this message"); realDfunc(); return 2012; } // shared, otherwise need emutls shared string s = "A message from a D string\n"; void realDfunc() { // need druntime support //auto m = s ~ "\n"; foreach (c; s) { write(1, &c, 1); } } --- D output from my iphone (on xcode gdb console) ---- dhello is puts()ing this message A message from a D string dhello() returned 2012
Nov 16 2012
prev sibling next sibling parent reply Iain Buclaw <ibuclaw ubuntu.com> writes:
On 12 November 2012 01:38, Dan Olson <zans.is.for.cans yahoo.com> wrote:
 Ok, D is not there yet, but I managed to build a crippled gcc-4.8 (with
 D) targeting arm-apple-darwin and I can compile simple C functions to .o
 files and link them into an iphone app.  And run it on my iphone.  The D
 and C++ compilers built, but I have probably a potpourri of issues since
 I gave 4.8 a arm-darwin target by selectively copying apple's 4.2
 changes for arm-darwin.  gcc-4.8 was configured to use tools (as, ld) in
 the apple iphone SDK.

 The biggest hassle is that apple's version of arm as is different than
 binutils as.  So I am learning what it wants for debug and pseudo op
 differences.

 Even a simple D module with just a extern(C) function depends on
 something in druntime, so I have to get part of that to build first.

 --
 dano

Doesn't Apple forbid any language except Objective-C ? Or is that a misguided fallacy of mine? (Objective D, anyone? :-) -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Nov 12 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-11-13 00:45, Iain Buclaw wrote:

 Doesn't Apple forbid any language except Objective-C ?  Or is that a
 misguided fallacy of mine? (Objective D, anyone? :-)

We actually do need Objective-D if we're going to run D on iOS. Fortunately we already have something, although it's not finished and it's getting old: http://michelf.ca/projects/d-objc This project makes it so much easier to interact with Objective-C. Which is needed on Mac OS X and iOS when you want to have a GUI. -- /Jacob Carlborg
Nov 12 2012
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-11-16 18:44, Denis V. Shelomovskij wrote:

 As XCode natively supports C++ and that MonoTouch gays sells their "C#
 for iOS" fine Apple doesn't "forbid any language except Objective-C".

Xcode has had support for C++ long before iPhone was developed. Originally the only allowed C, C++, Objective-C, HTML and JavaScript. Now they've removed that constraint and allows other languages. -- /Jacob Carlborg
Nov 16 2012
prev sibling next sibling parent "Bernard Helyer" <b.helyer gmail.com> writes:
On Monday, 12 November 2012 at 23:45:37 UTC, Iain Buclaw wrote:
(Objective D, anyone? :-)


Too far man. D:
Nov 12 2012
prev sibling next sibling parent Dan Olson <zans.is.for.cans yahoo.com> writes:
Iain Buclaw <ibuclaw ubuntu.com> writes:
 Doesn't Apple forbid any language except Objective-C ?  Or is that a
 misguided fallacy of mine? (Objective D, anyone? :-)

I think it once was so, but no longer. http://stackoverflow.com/questions/3949995/what-programming-languages-can-one-use-to-develop-iphone-ipod-touch-and-ipad-i
Nov 12 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 13 November 2012 01:19, Bernard Helyer <b.helyer gmail.com> wrote:
 On Monday, 12 November 2012 at 23:45:37 UTC, Iain Buclaw wrote:
 (Objective D, anyone? :-)


 Too far man. D:

Far out man. :o) -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Nov 13 2012
prev sibling parent "Denis V. Shelomovskij" <verylonglogin.reg gmail.com> writes:
On Monday, 12 November 2012 at 23:45:37 UTC, Iain Buclaw wrote:
 Doesn't Apple forbid any language except Objective-C ?  Or is 
 that a
 misguided fallacy of mine? (Objective D, anyone? :-)

As XCode natively supports C++ and that MonoTouch gays sells their "C# for iOS" fine Apple doesn't "forbid any language except Objective-C". -- Денис В. Шеломовский Denis V. Shelomovskij
Nov 16 2012