[Vm-dev] __builtin_extract_return_addr

Eliot Miranda eliot.miranda at gmail.com
Fri Sep 18 04:20:30 UTC 2020


Hi David,

On Thu, Sep 17, 2020 at 9:58 AM stes at PANDORA.BE <stes at telenet.be> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
>
> Hi,
>
> Originally when I compiled on Solaris, I had both the "Cog" and "Stack" VM
> working.
>
> Unfortunately there was a change in april which breaks the "Cog" build.
>
> The "Stack" build continues to work fine for me.
>
> Since early april there is in the following file the following definition :
>
> platforms/Cross/vm/sq.h
>
> #       define getReturnAddress()
> __builtin_extract_return_addr(__builtin_return_address(0))
>
> Eliot Miranda wrote in the thread:
>
> http://forum.world.st/Broken-5-3-downloads-need-fixing-td5115132.html
>
> "Things are pretty stable. There was one major change to how the VM moves
> from machine code into the interpreter, replacing a setjmp/longjmp pair
> with a much lighter-weight "jump-call with substituted return address". But
> this "just works".  We're able to perform experments without disturbinf=g
> trunk.  SO for example, adding makefiles to allow building of the VM under
> clang-cl.exe on Windows was done without affecting the other builds at all."
>
> Is there a compiler flag (#define) to re-enable the old code with
> setjmp/longjmp ?
>
> Or is there code in the 'platforms/Cross/vm/sqCog*' files
> that could help to implement the required function for 'return address',
> if that is not provided by the compiler ... ?
>
> I am hoping to re-enable the old setjmp/longjmp code.
>
> Also note that this may be useful for other users as well,
> to be able to 'revert' to the legacy old code.
>

Nah, it's trivial to implement.  The new scheme is much cheaper and hence
faster than setjmp/longjmp.  So I'd much rather spread it further than
support two versions.  The compiler supports gcc's inline extended
assembler right?  In a normal frame on x86/x86_64 the frame pointer points
to the word below the return address, so would look like this:

#if __GNUC__ || __clang__
# if defined(_X86_) || defined(i386) || defined(__i386) || defined(__i386__)
#   define getretaddr() ({ register usqIntptr_t retpc;                  \
                      asm volatile ("movl 4(%%ebp),%0" : "=r"(retpc) : ); \
                      retpc; })
# elif defined(x86_64) || defined(__x86_64) || defined(__x86_64__) ||
defined(__amd64) || defined(__amd64__) || defined(x64) || defined(_M_AMD64)
|| defined(_M_X64) || defined(_M_IA64)
#   define getretaddr() ({ register usqIntptr_t retpc;                  \
                      asm volatile ("movl 8(%%rbp),%0" : "=r"(retpc) : ); \
                      retpc; })
#endif

To make this convenient we need to decide whether to put it in
sqPlatformSpecific.h (easy) or to perhaps
rename platforms/Cross/vm/sqCogStackAlignment.h
to platforms/Cross/vm/sqCogStackAccess.h and put it there.  That feels
better than putting it in sq.h.  But in any case can you try adding the
above definitions to the relevant sqPlatformSpecific.h?



> Regards,
> David Stes
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
>
> iQEcBAEBCAAGBQJfY5VfAAoJEAwpOKXMq1Ma9y8H/15hLjTf3aMfdFaPH1aoXNRK
> T61XZtbrOuykLH4IqLZpr85bQgtqdAdZqZ4tYtl8H00B4opoKZ+CVfruCDUoQEIJ
> uUYpJ9R8bp60DqQ147VakZaBzl7P9z2yn9mq6BGnb4sh/tSS743AIinURt+jqoKM
> MKxPf6cQn6r+fsvRNN+N5By9AIGco9t61SUqIcNzrdGRNwoaMOzc/4DfMYhPs6JT
> qyP3sJ0/LlJA7nhLSWmRNbkC2aJuYT4WCBTdEyNbs9lkv4CO8OOska8Y5YINgvpl
> FbwnyTABZzMdYuBIJevlB3RKPMTsn+ceFDfqcrDC7YzeVVWaZhhzV5wosjHenck=
> =bl73
> -----END PGP SIGNATURE-----
>


-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20200917/e8b465db/attachment.html>


More information about the Vm-dev mailing list