wide function pointer type

Martin Uecker ma.uecker@gmail.com
Tue Oct 19 12:13:12 GMT 2021


Am Dienstag, den 19.10.2021, 12:15 +0200 schrieb Florian Weimer:
> * Martin Uecker:
> 
> > > For GCC's nested function extension, there are no ABI concerns
> > > because the nested function definition and the thunk generation are
> > > always built from the same translation unit.  So GCC can just pick a
> > > custom calling convention, similar to what it does for other local,
> > > non-escaping functions.
> > 
> > Yes, but there are many other languages that make use of the
> > static chain.  So it would be good to have a standardized ABI
> > for this.
> 
> What's the exact use case for this?  These other languages do not
> usually have stable ABIs that inter-operate across different
> implementations.

One (of several) use cases is for language interoperability.

A common problem is to pass a function of a high-level
language as a callback to an C API.  This now often
requires special boiler plate code for each case and
there is no automatic way to do this. The fundamental
problem is that the C type can not express that a data
pointer belongs to a function pointer.

void foo(
  void (cb1)(void* data, int a), void* data1,
  void* other_data);  

Here a human (and maybe also a machine) could guess
that data1 belongs to cb1 but not other_data.  But
it is not clear and in more complicated cases
even less so.

void foo(void (_Wide cb1)(int a), void* other_data);


With the new type that would be unambiguous (and 
wrappers could then often be created automatically).
At least for the C API one would also expect ABI
stability.


Martin




More information about the Libffi-discuss mailing list