alloca without runtime?

岩倉 澪 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 29 22:07:31 PDT 2017


I've been playing around with using D with no runtime on Linux, 
but recently I was thinking it would be nice to have an alloca 
implementation. I was thinking I could just bump the stack 
pointer (with alignment considerations) but from what I 
understand compilers sometimes generate code that references 
variables relative to RSP instead of RBP? I've seen people saying 
that a proper alloca can't be implemented without help from the 
compiler...

I took a peek in druntime and found rt.alloca which has __alloca 
implemented with inline asm. I tried throwing that in my project 
and calling it but it segfaults on rep movsq. The comments in the 
code suggest it is trying to copy temps on the stack but I seem 
to get a really large garbage RCX, I don't fully follow what is 
going on yet.

Is there any way I can get a working alloca without using 
druntime, c runtime, etc?


More information about the Digitalmars-d-learn mailing list