Re: How to force gcc to blackhole registers so that things maybe garbage collected?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/20/19 3:13 PM, Florian Weimer wrote:
> * 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).

True.

> The above kludge does not clear those pointers, obviously.

Yep. There are no guarantees.

-- 
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux