On Wed, 19 Jul 2017, Jakub Jelinek wrote:
> > 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)?

Bionic and musl certainly do, and I see no other approach for supporting
RTLD_NEXT.

> >     foo = __builtin_notailcall (func (args))
> 
> We already have that, just do:
>   void *volatile foo = dlsym (args);
>   return foo;

(this has a small codesize penalty for round-tripping 'foo' via stack)

> or
>   void *foo = dlsym (args);
>   __asm ("" : "+g" (foo));
>   return foo;
> I think adding yet another way to express that isn't needed.

Well, a builtin as proposed above would also work for functions
that don't return a value.  I think that for dlsym in particular
such a builtin is not very useful, and there the choice is between
the attribute, or no additions at all.

My main concern about the attribute is that the apparent goal is
enforcing that taking the address doesn't lose the attribute.
Forbidding

   void *p = &dlsym;

seems questionable.

Alexander

Reply via email to