gcc: Forwarding hook

1 
1 8.10.2 Forwarding Hook
1 ----------------------
1 
1 The GNU Objective-C runtime provides a hook, called
1 '__objc_msg_forward2', which is called by 'objc_msg_lookup()' when it
1 cannot find a method implementation in the runtime tables and after
1 calling '+resolveInstanceMethod:' and '+resolveClassMethod:' has been
1 attempted and did not succeed in dynamically registering the method.
1 
1  To configure the hook, you set the global variable
1 '__objc_msg_forward2' to a function with the same argument and return
1 types of 'objc_msg_lookup()'.  When 'objc_msg_lookup()' can not find a
1 method implementation, it invokes the hook function you provided to get
1 a method implementation to return.  So, in practice
1 '__objc_msg_forward2' allows you to extend 'objc_msg_lookup()' by adding
1 some custom code that is called to do a further lookup when no standard
1 method implementation can be found using the normal lookup.
1 
1  This hook is generally reserved for "Foundation" libraries such as
1 GNUstep Base, which use it to implement their high-level method
1 forwarding API, typically based around the 'forwardInvocation:' method.
1 So, unless you are implementing your own "Foundation" library, you
1 should not set this hook.
1 
1  In a typical forwarding implementation, the '__objc_msg_forward2' hook
1 function determines the argument and return type of the method that is
1 being looked up, and then creates a function that takes these arguments
1 and has that return type, and returns it to the caller.  Creating this
1 function is non-trivial and is typically performed using a dedicated
1 library such as 'libffi'.
1 
1  The forwarding method implementation thus created is returned by
1 'objc_msg_lookup()' and is executed as if it was a normal method
1 implementation.  When the forwarding method implementation is called, it
1 is usually expected to pack all arguments into some sort of object
1 (typically, an 'NSInvocation' in a "Foundation" library), and hand it
1 over to the programmer ('forwardInvocation:') who is then allowed to
1 manipulate the method invocation using a high-level API provided by the
1 "Foundation" library.  For example, the programmer may want to examine
1 the method invocation arguments and name and potentially change them
1 before forwarding the method invocation to one or more local objects
1 ('performInvocation:') or even to remote objects (by using Distributed
1 Objects or some other mechanism).  When all this completes, the return
1 value is passed back and must be returned correctly to the original
1 caller.
1 
1  Note that the GNU Objective-C runtime currently provides no support for
1 method forwarding or method invocations other than the
1 '__objc_msg_forward2' hook.
1 
1  If the forwarding hook does not exist or returns 'NULL', the runtime
1 currently attempts forwarding using an older, deprecated API, and if
1 that fails, it aborts the program.  In future versions of the GNU
1 Objective-C runtime, the runtime will immediately abort.
1