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

Reply via email to