On Wed, Jul 19, 2017 at 06:30:40PM +0300, Alexander Monakov wrote:
> On Wed, 19 Jul 2017, Jeff Law wrote:
> > > Glibc people were worried that attribute would be lost when taking a
> > > pointer to function
> > > (https://sourceware.org/ml/libc-alpha/2017-01/msg00482.html). I think
> > > their reasoning was that return address is a shadow argument for
> > > dlsym-like functions so this would cause a (most likely inadvertent)
> > > ABI error.
> > Fair enough, but does the right thing happen if the function's
> > definition is decorated?  Can you add a test for that in the testsuite?
> 
> How would passing pointers to dlsym via a 'void *' work after this patch?
> 
> Honestly, if the goal is to assist users of GCC (and not only Glibc users,
> but also people compiling against Bionic/musl/BSD libcs, which probably
> wouldn't adopt this attribute), may I suggest that a clearer course of
> action would be to:
> 
> 1) recognize dlsym by name and suppress tailcalls to it
> 
>    this would solve >99% cases because calling dlsym by pointer would be rare,
>    and has the benefit of not requiring libc header changes;

Recognizing by name is IMNSHO undesirable.  Adding dlsym to builtins.def
with the attribute is certainly possible, and people can use
-fno-builtin-dlsym.  On the other side, does Bionic/musl/BSD dlsym really
need that attribute (i.e. does it similar computation of the return address
and base behavior on that)?

> and
> 2) if we really want to offer some generic solution, can we give the users
> a way to suppress tailcalls via a builtin? That is, introduce
> 
>     foo = __builtin_notailcall (func (args))

We already have that, just do:
  void *volatile foo = dlsym (args);
  return foo;
or
  void *foo = dlsym (args);
  __asm ("" : "+g" (foo));
  return foo;
I think adding yet another way to express that isn't needed.

        Jakub

Reply via email to