This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 0/4] s390 improvements


Richard Henderson wrote:

> The stack frame we install is created with alloca, and so we know for a fact
> that ffi_call_int must be using a frame pointer to hold its own frame.  Since
> we do not adjust %r15 on the way out of ffi_call_SYSV, we leave the stack frame
> chain intact.  If there were another function for ffi_call_int to call after
> ffi_call_SYSV (but there's not), the outgoing 160 byte save area would be present.

Well, even in a function using a frame pointer, we still occasionally
rely on %r15.  One obvious case would be calling a function that needs
an argument save area, after ffi_call_SYSV returned.  (Or if we had
another alloca etc.)

Now, we can probably exclude all those cases by simply not using certain
source-level features in ffi_call_int; that at least needs to be clearly
documented in comments there.   There is still the theoretical possibilty
of a compiler introducing dependencies on %r15 that aren't obvious from
the source.  (One example: some ancient gcc 2.95 compilers would actually
use the backchain value to restore %r15 on function return in some cases.
These would now get the wrong value, since ffi_call_SYSV has installed a
different backchain.)

In the end, it's probably OK for low-level code like libffi to make certain
assumptions on the behavior of the toolchain.  I'm not quite sure whether
this actually gets us any significant benefit in this case.  Does it really
matter whether ffi_prep_args is called from ffi_call_int vs. ffi_call_SYSV?

> It's true that the load of %r15 is now a nop.  It hadn't been at one point in
> my development; ffi_prep_args had had more than 5 parameters, and so there was
> extra stack allocated.  I suppose if ffi_prep_args were inlined, one could be
> certain of this (since there will be no function calls) and document it as such.

If we do use such tricks, this version may actually be preferable.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]