Jump to page: 1 2
Thread overview
getting to know dmd and druntime
Jul 22, 2012
maarten van damme
Jul 22, 2012
maarten van damme
Jul 22, 2012
Nick Sabalausky
Jul 22, 2012
maarten van damme
Jul 22, 2012
David Nadlinger
Jul 23, 2012
maarten van damme
Jul 23, 2012
Jacob Carlborg
Jul 23, 2012
Dmitry Olshansky
Jul 23, 2012
maarten van damme
Jul 23, 2012
David Nadlinger
Jul 23, 2012
Sean Kelly
Jul 23, 2012
maarten van damme
Jul 24, 2012
Sean Kelly
July 22, 2012
Noticed I've sent this to digitalmars.D instead of digitalmars.D.learn. Sorry for that, going to resend this in D.learn.
July 22, 2012
Right now I'm a bit confused. I assume that the garbage collector and
some other parts from druntime need startup code. But what gets run
first is my main method in the d file I compile.
Does this mean that the first call to something in druntime calls that
startup code? If not, what does get ran first? how can I intercept
this and run something else?
When compiling without druntime the program will crash when
initializing an object. How can I implement my own limited druntime
that provides it's own version of the new expression?
Druntime contains it's own trimmed down garbage collector that is most
likely not very efficient. How can I use that one instead of the other
more advanced one?
Is the garbage collector embedded in druntime or is it somehow linked
at compile time from a c-source (I found gc.c in the dmd source).
What else gets linked? What exactly does dmd do? Which parts of
druntime does it rely on?

I really want to get to know that part of D a bit better. Is this
somewhere documented?
Ideally I want to compile a d file without druntime (and thus with a
very limited subset of D). Then, I want to start writing my own
version of druntime (that is, providing the needed methods to get
something more advanced working but stubbing everything out).

I came accross this blog
https://www.semitwist.com/articles/article/view/d-on-gba-nds-progress-thanks-to-oopman
but the link to the documentation seems to not be working (and judging
by the date it will most likely be about D1).

To sum everything up : are the inner workings of dmd-druntime somewhere documented?
July 22, 2012
On Sun, 22 Jul 2012 11:30:14 +0200
maarten van damme <maartenvd1994@gmail.com> wrote:

> Right now I'm a bit confused. I assume that the garbage collector and some other parts from druntime need startup code. But what gets run first is my main method in the d file I compile.

Actually, that's just a clever illusion. Your main() method isn't really the first thing called, the first thing called is a function in druntime called dmain (or Dmain or _dmain or something like that, I forget offhand). This function does all the initial stuff like calling all the static/module constructors, initializing druntime including the GC, some other stuff, and then actually calling *your* main().

IIRC, this dmain function is in object.d.

> Does this mean that the first call to something in druntime calls that
> startup code? If not, what does get ran first? how can I intercept
> this and run something else?
> When compiling without druntime the program will crash when
> initializing an object. How can I implement my own limited druntime
> that provides it's own version of the new expression?
> Druntime contains it's own trimmed down garbage collector that is most
> likely not very efficient. How can I use that one instead of the other
> more advanced one?
> Is the garbage collector embedded in druntime or is it somehow linked
> at compile time from a c-source (I found gc.c in the dmd source).
> What else gets linked? What exactly does dmd do? Which parts of
> druntime does it rely on?
> 
> I really want to get to know that part of D a bit better. Is this somewhere documented?

You can just modify and recompile druntime itself. Or, according to Walter you should be able to replace any druntime function by simply writing your own and including it when you compile. As long as the name & function signature are correct, the linker apparently will just use your version instead of the one in druntime.

Beyond that though, I don't really know anything more specific about druntime or the GC. And I don't know whether there's any documentation anywhere (you could try just browsing through the druntime sources or searching around on the D wiki: http://www.prowiki.org/wiki4d/wiki.cgi ). Someone more familiar with druntime will have to answer those questions.

> Ideally I want to compile a d file without druntime (and thus with a very limited subset of D). Then, I want to start writing my own version of druntime (that is, providing the needed methods to get something more advanced working but stubbing everything out).
> 
> I came accross this blog
> https://www.semitwist.com/articles/article/view/d-on-gba-nds-progress-thanks-to-oopman
> but the link to the documentation seems to not be working (and judging
> by the date it will most likely be about D1).
> 

That's mine actually, and yea it's super-old and completely out of date (It was indeed a very early D1 - before D2 even existed. And in fact, it's referring to the old, old, OLD GDC project, not same GDC we have now.)

Back then, the stuff we now call druntime was actually part of Phobos (with a separate incompatible version in Tango), and I never did get it working with DevKitARM (which I think is called DevKitPro now). What's there is as far as I ever got with it. Of course, at the time (and even today, too) I didn't know a damn thing about the internals of GCC, GDC, DevKitARM or, uhh, what was to become druntime. I was just compiling GDC/DevKitARM, didn't really even touch any of the code inside.

July 22, 2012
2012/7/22 Nick Sabalausky <SeeWebsiteToContactMe@semitwist.com>:
> Actually, that's just a clever illusion. Your main() method isn't really the first thing called, the first thing called is a function in druntime called dmain (or Dmain or _dmain or something like that, I forget offhand). This function does all the initial stuff like calling all the static/module constructors, initializing druntime including the GC, some other stuff, and then actually calling *your* main().
>
> IIRC, this dmain function is in object.d.
>

I've looked and it appears to be in rt/dmain2.d .
Great to know that my main() function isn't the first function called,
this explains a lot for me.

It looks like what I need is a function with the signature
extern (C) int main(int argc, char** argv)
which initializes the garbage collector etc.

To compile it I would need a function with signature
"_Dmodule_ref"
What is this and where does it come from?
(Got this information from
http://www.mail-archive.com/digitalmars-d@puremagic.com/msg89241.html)

I'm trying to compile my file with only extern (C) int main with -defaultlib=none and -debuglib=none but the resulting executable is 31 kb so I'm pretty sure druntime is still beeing mixed in.
July 22, 2012
On Sunday, 22 July 2012 at 10:42:58 UTC, Nick Sabalausky wrote:
> Actually, that's just a clever illusion. Your main() method isn't
> really the first thing called, the first thing called is a function in
> druntime called dmain (or Dmain or _dmain or something like that, I
> forget offhand). This function does all the initial stuff like calling
> all the static/module constructors, initializing druntime including the
> GC, some other stuff, and then actually calling *your* main().

It's the other way round. Your main() function gets mangled as _Dmain by the compiler, and druntime has the real (C) main(). On linking, the undefined reference to _Dmain in druntime is resolved to the user-supplied D function.

The D main() is also special in that the compiler transparently rewrites all the »reduced« signatures (without return value and param array) to the full one.

David
July 23, 2012
Got some more information here : http://wiki.osdev.org/D_Bare_Bones

Any way to do this with dmd? When compiling with -debuglib=none and -defaultlib=none I still get a 31 kb executable so druntime still gets linked in.
July 23, 2012
On 2012-07-23 12:53, maarten van damme wrote:
> Got some more information here : http://wiki.osdev.org/D_Bare_Bones
>
> Any way to do this with dmd? When compiling with -debuglib=none and
> -defaultlib=none I still get a 31 kb executable so druntime still gets
> linked in.

Are you sure? You can generate a map file or inspect the compiled code with "nm".

-- 
/Jacob Carlborg
July 23, 2012
On 23-Jul-12 14:53, maarten van damme wrote:
> Got some more information here : http://wiki.osdev.org/D_Bare_Bones
>
> Any way to do this with dmd? When compiling with -debuglib=none and
> -defaultlib=none I still get a 31 kb executable so druntime still gets
> linked in.
>
Might be DMC C runtime. Check with disassembler say IDA, it's state of the art and has freeware version.

-- 
Dmitry Olshansky
July 23, 2012
I couldn't find anything D-related in the map file. When I compile without -debuglib=none and -defaultlib=none I also get a 31 kb executable with the exact same map file. Does he ignore those flags?
July 23, 2012
On Jul 23, 2012, at 3:53 AM, maarten van damme wrote:

> Got some more information here : http://wiki.osdev.org/D_Bare_Bones
> 
> Any way to do this with dmd? When compiling with -debuglib=none and -defaultlib=none I still get a 31 kb executable so druntime still gets linked in.

That's not druntime.  The smallest an executable has ever been with runtime is ~60 kb, and it's larger than that now.
« First   ‹ Prev
1 2