Can dmd compile with my own runtime library?

Alexander Panek alexander.panek at brainsware.org
Thu Aug 23 02:07:49 PDT 2007


Huang F Guan wrote:
> Hi, I'm an operating system developer. I've written a win32-compatible and POSIX operating system, just for fun, but it can run many windows api programs. My system is written in C, it is not readable and diffcult to manage. Now I am looking for the new techniques to rewrite this os.
> 
> I've ever thought for an own compiler and linker, it is so complicated to develop an advanced one. But DMD did it, the D language almost satisfied what I need. Yes, you see, I am trying to use it to develop an operating system in D language, and maybe it will be the first one written in D language. 
> 
> While I was using C++ developing an os, the compiler can output the platform-independent code. But DMD compiler can not do this, because it needs a runtime library based on the present platform. 
> 
> I have tried gdc, but I failed too. It prints the error below when I link:
> 
> ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
> hello.o(.text+0x18):hello.d: undefined reference to `_Dmodule_ref'
> hello.o(.text+0x23):hello.d: undefined reference to `_Dmodule_ref'
> hello.o(.data+0x0):hello.d: undefined reference to `_D10ModuleInfo6__vtblZ'
> hello.o(.data+0x30):hello.d: undefined reference to `_D6object12__ModuleInfoZ'
> 
> Now I am wondering how can I link a platform-independent executable file? 
> Do I need to rewrite the runtime library? 
> Or just I need to write a tiny runtime library like gc, moduleinit, object?
> 
> I hope you can help me solve these puzzles, thanks!
> 

If you take a closer look at OCD's or Titan's build process, you'll 
eventually find out how to build your kernel. First thing: if you load 
your kernel with Grub, you need an entry point in an Assembly file (or 
at least I didn't succeed creating a valid Multiboot header inside a D 
file), like here:

http://trac.brainsware.org/ocd/browser/branches/ocd-take2/ocd/nucleus/entry.asm

This file is proven to work. If you want to use it, please go ahead.. as 
well as with 'all the other' (isn't so much yet, eh) OCD code, of course. :)

Anyways, your D entry point has to be extern(C) to remove the D name 
mangling, afterwards you can operate in a D environment as much as you 
please. Be sure to use structs where you can, as (dynamically 
instantiated) classes can lead to GC invocations. Also avoid dynamic 
arrays or associative arrays.. but Frits mentioned that all already I think.

Would be nice if you keep us informed about your progress!

Kind regards,
Alex



More information about the Digitalmars-d mailing list