iphone + D, getting closer!

Dan Olson zans.is.for.cans at yahoo.com
Fri Nov 16 06:56:53 PST 2012


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

> Dan Olson <zans.is.for.cans at yahoo.com> writes:
>
>> Johannes Pfau <nospam at 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


More information about the D.gnu mailing list