* Andrew Haley: > On 5/19/19 9:45 AM, Andrew Haley wrote: >> On 5/18/19 8:45 PM, Hamad Ahmed wrote: >>> How do I do that? >> >> Seriously? Go find the ABI for your processor and find out which >> registers are call clobbered. Write a subroutine in assembly language >> that zeroes those registers. > > And actually, you can go one better than that: write a bunch of inline asms > that zero all of the registers, one at a time. > > #define CLOBBER(reg) \ > asm volatile("sub %%" #reg ", %%" #reg ::: #reg, "memory") > > static inline void foo() { > CLOBBER(rax); > CLOBBER(rbx); > CLOBBER(rcx); > CLOBBER(rdx); > CLOBBER(rbp); > CLOBBER(rax); > CLOBBER(rsi); > CLOBBER(rdi); > CLOBBER(r8); > CLOBBER(r9); > CLOBBER(r10); > CLOBBER(r11); > CLOBBER(r12); > CLOBBER(r13); > CLOBBER(r14); > CLOBBER(r15); > } > > This will mostly work, I think, but even then it's not 100% guaranteed. With most ABIs, there's also an issue with callee-saved registers, which could leave dead pointers on the stack (because the callee will save the register even if it is dead in the caller). The above kludge does not clear those pointers, obviously. > But I still think you're making a mistake: garbage collection -- any > kind -- is only guaranteed to happen eventually, sometimes only when > the system is running low on memory, and if you really need to control > storage lifetime in a precise way you have to do so explicitly. Some languages have more stringent space safety requirements, and compiler transformations must reflect them. The only way to implement that using current GCC (without precise stack traversal) probably involves not using the native stack for pointer values at all. Thanks, Florian