This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add no_tail_call attribute
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Yuri Gribov <tetra2005 at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 29 May 2017 11:14:23 +0300 (MSK)
- Subject: Re: [PATCH] Add no_tail_call attribute
- Authentication-results: sourceware.org; auth=none
- References: <CAJOtW+6eFn6zT0=RnJ_s7ivnCijtNkOawkhyP7375=H5S-1JyQ@mail.gmail.com>
Hi,
On Mon, 29 May 2017, Yuri Gribov wrote:
> Hi all,
>
> As discussed in
> https://sourceware.org/ml/libc-alpha/2017-01/msg00455.html , some
> libdl functions rely on return address to figure out the calling
> DSO and then use this information in computation (e.g. output of dlsym
> depends on which library called it).
>
> As reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66826 this
> may break under tailcall optimization i.e. in cases like
>
> return dlsym(...);
>
> Carlos confirmed that they would prefer to have GCC attribute to
> prevent tailcalls
> (https://sourceware.org/ml/libc-alpha/2017-01/msg00502.html) so there
> you go.
A few comments:
- the new attribute will need documentation
- as mentioned earlier, calls to dlsym via a function pointer may still lead to
the same issue (so the documentation should mention that)
- this suppresses tailcalls for all dlsym calls, although only those with
RTLD_NEXT are magic and need such suppression
Are there any other possible uses for this attribute? Given the issue of
calls-via-pointers, I don't understand why Glibc needs it, because for direct
calls Jakub pointed out a simpler solution that works with existing compilers:
#define dlsym(h, s) \
({ \
void *__r = dlsym (h, s); \
asm ("" : "+r" (__r)); \
__r; })
(I think life would be easier for everyone if instead of making RTLD_NEXT magic,
there was simply a way to look up a handle of the "next" dso...)
Alexander