How minimal I can go using D on GDC?
Benjamin Thaut
code at benjamin-thaut.de
Sun May 12 02:20:58 PDT 2013
Am 11.05.2013 17:51, schrieb Rel:
> hello! I used to have a bit unusual task: writing pure binary code
> (without runtime/os dependency, just native x86 and x64 code). Quite
> similar to the OS kernel development I may say, if it makes the problem
> clearer for you. I usually wrote such code in C++ with GCC (using
> '-nostdlib', '-fno-exceptions', '-fno-rtti' and etc), but now I need a
> good metaprogramming features and complex metaprogramming in C++ makes a
> brain explode. D metaprogramming and the language in general looks
> awesome, so I decided to give it a try.
>
> I looked at the XOMB and a few other projects, but it seems they
> reimplemented quite big part of druntime to make their project work, in
> fact a lot of stuff reimplemented by them I would consider being
> actually useless. So my question is: how much of the runtime features I
> could disable?
>
> for testing purposes I made a little programm (I'm building it with
> '-nophoboslib', '-nostdlib', '-fno-exceptions', '-emain'):
>
> module main;
>
> extern (C) void* _Dmodule_ref = null;
> extern (C) void puts(const char*);
> extern (C) void exit(int);
>
> extern (C) void main() {
> scope(exit) {
> puts("Exiting!");
> exit(0);
> }
>
> puts("Hello World!");
> }
>
> I had to include '_Dmodule_ref' in the source, it seems that it is used
> for calling module constructors, I'm not going to use them, can I
> disable it somehow?
>
> when I added 'scope(exit)' part I got links to exception handling code
> in object files, I'm not going to use exceptions, so I added
> '-fno-exceptions' flag, and it seems to work pretty fine. but when I try
> to add some primitive classese I got a lot of links to the code that
> seems to be connected with runtime type information, I don't need it so
> I tried to add '-fno-rtti' flag, but it doesn't work. Is there a way to
> get rid of runtime type information?
GDC has -nodefaultlib flag which will disable linking against the
standard library. This is as bare metal as it gets, just start writing
all functions you will get linker errors for. Be warned a lot of
language features will break that way, eg:
- Everything that relies on the GC (closures, array literals, etc)
- Module Constructors / Destructors
- Thread local storage
I've also seen that there is a minmal druntime somewhere on the web, but
I can't find it right now.
Kind Regards
Benjamin Thaut
More information about the D.gnu
mailing list