A collection of DIPs

Edmund Smith via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 12 05:55:56 PDT 2015


On Saturday, 12 September 2015 at 06:25:45 UTC, NX wrote:
> On Friday, 11 September 2015 at 19:30:56 UTC, ponce wrote:
>> Some of us use and need @nogc all the time. The other parts of 
>> an application can use the GC: best of both worlds.
>
> Is there even a compiler switch to disable GC altogether so the 
> program doesn't have a GC thread? No, I can't see it...

There are a few levels of 'everything @nogc' you can go - make 
`main` @nogc but still have the runtime initalised, link to 
`_start @nogc` and intercept it so that it doesn't even start the 
runtimes, or (for minimising the binary/going bare metal) 
providing a custom null runtime and not linking the D runtime at 
all.

 From when I tried to make the smallest PE hello world I could for 
2.066:

     //Level 1
     void main() @nogc
     {
         //Do stuff
     }

     //Level 2 - no runtime initialisation, runtime still there 
though
     extern(C) void _start() @nogc
     {
         //Runtime not started yet - must be initialised before 
using much of the standard library
     }

     //Level 3 - no runtime, trick the linker (it expects runtime 
hooks)
     extern(C)
     {
         @nogc:

         //Custom runtime/moduleinfo stuff - not very portable in 
my experience - YMMV
         //Provided so the linker doesn't have any 'runtimeFnHook 
missing' errors, but we don't actually include the runtime
         __gshared void* _Dmodule_ref;
         //Depending on compiler/version, these may have to exist 
for the linker
         //__gshared void* _d_arraybounds;
         //__gshared void* _d_assert;
         //__gshared void* _d_unittest;
         //May want to provide empty bodies instead if your linker 
can remove unused
         // / garbage functions
         void _d_dso_registry(void* ignore){}

         void _start()
         {
             //Bare metal ready
         }
     }

I needed a few runtime-affecting compiler (and linker) switches 
too, depending on which compiler I was using, although it was 
mostly obvious stuff listed in `$(compiler) --help`.


More information about the Digitalmars-d mailing list