Clarify parameter save area requirements for variadic function calls #77

Closed
opened 7 years ago by wschmidt-ibm · 4 comments
wschmidt-ibm commented 7 years ago (Migrated from github.com)

From the syssw-elfv2abi mailing list, Tulio Magno Machado writes:

Hi Florian,

Florian Weimer fweimer@redhat.com writes:

I'm not sure to whom I should write this.

I'm Cc'ing Bill Schmidt and the syssw-elfv2abi mailing list [1].

The ELFv2 ABI is ambiguous when it describes the Parameter Save Area.
It is unclear whether it is the responsibility of the caller of a
variadic function which does not receive any variadic arguments (i.e.,
only named arguments) to provide a Parameter Save Area.

GCC seems to assume that the caller always allocates the Parameter Save
Area, and does so in the caller, but I don't think the ABI is entirely
explicit about this requirement. For example, section 2.24 (Variable
Argument Lists) has this in my copy:

That part has been elaborated previously in section 2.2.2.3 Optional Save
Areas, under "Parameter Save Area" [2]:

The Parameter Save Area shall be allocated by the caller for function
calls unless a prototype is provided for the callee indicating that all
parameters can be passed in registers. (This requires a Parameter Save
Area to be created for functions where the number and type of parameters
exceeds the registers available for parameter passing in registers, for
those functions where the prototype contains an ellipsis to indicate a
variadic function, and functions declared without a prototype.)

Do you think it clarifies what allocates the Parameter Save Area?


The parameter list may be zero length and is only allocated when
parameters are spilled, when a function has unnamed parameters, or when
no prototype is provided. When the Parameter Save Area is allocated, the
Parameter Save Area must be large enough to accommodate all parameters,
including parameters passed in registers.

Maybe it's possible to reference the previous text from here?

This suggests that the Parameter Save Area is not allocated if a
variadic function is called without supplying any variadic arguments.

All this matters to glibc to some extent, where functions such as fcntl
and open can be implemented in a reasonable way in C only if it is safe
to call va_arg on a non-existing parameter.

I agree it's ambiguous with the previous text for prototyped functions with
variadic arguments that says:

Under these circumstances, a minimum of 8 doublewords are always reserved.

References:

[1] http://lists.mailinglist.openpowerfoundation.org/mailman/listinfo/syssw-elfv2abi

[2] http://openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240_15141.html

--
Tulio Magno

From the syssw-elfv2abi mailing list, Tulio Magno Machado writes: Hi Florian, Florian Weimer <fweimer@redhat.com> writes: >I'm not sure to whom I should write this. I'm Cc'ing Bill Schmidt and the syssw-elfv2abi mailing list [1]. >The ELFv2 ABI is ambiguous when it describes the Parameter Save Area. It is unclear whether it is the responsibility of the caller of a variadic function which does not receive any variadic arguments (i.e., only named arguments) to provide a Parameter Save Area. >GCC seems to assume that the caller always allocates the Parameter Save Area, and does so in the caller, but I don't think the ABI is entirely explicit about this requirement. For example, section 2.24 (Variable Argument Lists) has this in my copy: That part has been elaborated previously in section 2.2.2.3 Optional Save Areas, under "Parameter Save Area" [2]: The Parameter Save Area shall be allocated by the caller for function calls unless a prototype is provided for the callee indicating that all parameters can be passed in registers. (This requires a Parameter Save Area to be created for functions where the number and type of parameters exceeds the registers available for parameter passing in registers, for those functions where the prototype contains an ellipsis to indicate a variadic function, and functions declared without a prototype.) Do you think it clarifies what allocates the Parameter Save Area? >“ The parameter list may be zero length and is only allocated when parameters are spilled, when a function has unnamed parameters, or when no prototype is provided. When the Parameter Save Area is allocated, the Parameter Save Area must be large enough to accommodate all parameters, including parameters passed in registers. ” Maybe it's possible to reference the previous text from here? >This suggests that the Parameter Save Area is not allocated if a variadic function is called without supplying any variadic arguments. >All this matters to glibc to some extent, where functions such as fcntl and open can be implemented in a reasonable way in C only if it is safe to call va_arg on a non-existing parameter. I agree it's ambiguous with the previous text for prototyped functions with variadic arguments that says: Under these circumstances, a minimum of 8 doublewords are always reserved. References: [1] http://lists.mailinglist.openpowerfoundation.org/mailman/listinfo/syssw-elfv2abi [2] http://openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240_15141.html -- Tulio Magno
wschmidt-ibm commented 7 years ago (Migrated from github.com)

Florian Weimer responds:

On 10/10/2017 03:48 PM, Tulio Magno Quites Machado Filho wrote:

Hi Florian,
Florian Weimer fweimer@redhat.com writes:

I'm not sure to whom I should write this.
I'm Cc'ing Bill Schmidt and the syssw-elfv2abi mailing list [1].

Thanks.

The ELFv2 ABI is ambiguous when it describes the Parameter Save Area.
It is unclear whether it is the responsibility of the caller of a
variadic function which does not receive any variadic arguments (i.e.,
only named arguments) to provide a Parameter Save Area.

GCC seems to assume that the caller always allocates the Parameter Save
Area, and does so in the caller, but I don't think the ABI is entirely
explicit about this requirement. For example, section 2.24 (Variable
Argument Lists) has this in my copy:

That part has been elaborated previously in section 2.2.2.3 Optional Save
Areas, under "Parameter Save Area" [2]:
>The Parameter Save Area shall be allocated by the caller for function
calls unless a prototype is provided for the callee indicating that all
parameters can be passed in registers. (This requires a Parameter Save
Area to be created for functions where the number and type of parameters
exceeds the registers available for parameter passing in registers, for
those functions where the prototype contains an ellipsis to indicate a
variadic function, and functions declared without a prototype.)
Do you think it clarifies what allocates the Parameter Save Area?

“unless a prototype […] indicating all parameters can be passed in registers” is still ambiguous because it could still be a decision for individual call sites.

The parenthetical remark is the place which comes closest to saying that a variadic functions are always called with a parameter save area. I think the ABI should say so explicitly, not just as an side remark.


The parameter list may be zero length and is only allocated when
parameters are spilled, when a function has unnamed parameters, or when
no prototype is provided. When the Parameter Save Area is allocated, the
Parameter Save Area must be large enough to accommodate all parameters,
including parameters passed in registers.

Maybe it's possible to reference the previous text from here?

Sure, if it's clarified a bit.

Thanks,
Florian

Florian Weimer responds: On 10/10/2017 03:48 PM, Tulio Magno Quites Machado Filho wrote: >Hi Florian, >Florian Weimer <fweimer@redhat.com> writes: >>I'm not sure to whom I should write this. >I'm Cc'ing Bill Schmidt and the syssw-elfv2abi mailing list [1]. Thanks. >>The ELFv2 ABI is ambiguous when it describes the Parameter Save Area. It is unclear whether it is the responsibility of the caller of a variadic function which does not receive any variadic arguments (i.e., only named arguments) to provide a Parameter Save Area. >>GCC seems to assume that the caller always allocates the Parameter Save Area, and does so in the caller, but I don't think the ABI is entirely explicit about this requirement. For example, section 2.24 (Variable Argument Lists) has this in my copy: >That part has been elaborated previously in section 2.2.2.3 Optional Save Areas, under "Parameter Save Area" [2]: >The Parameter Save Area shall be allocated by the caller for function calls unless a prototype is provided for the callee indicating that all parameters can be passed in registers. (This requires a Parameter Save Area to be created for functions where the number and type of parameters exceeds the registers available for parameter passing in registers, for those functions where the prototype contains an ellipsis to indicate a variadic function, and functions declared without a prototype.) >Do you think it clarifies what allocates the Parameter Save Area? “unless a prototype […] indicating all parameters can be passed in registers” is still ambiguous because it could still be a decision for individual call sites. The parenthetical remark is the place which comes closest to saying that a variadic functions are always called with a parameter save area. I think the ABI should say so explicitly, not just as an side remark. >>“ The parameter list may be zero length and is only allocated when parameters are spilled, when a function has unnamed parameters, or when no prototype is provided. When the Parameter Save Area is allocated, the Parameter Save Area must be large enough to accommodate all parameters, including parameters passed in registers. ” >Maybe it's possible to reference the previous text from here? Sure, if it's clarified a bit. Thanks, Florian
wschmidt-ibm commented 7 years ago (Migrated from github.com)

This language should be clarified in the next release of the ABI document.

This language should be clarified in the next release of the ABI document.
uweigand commented 7 years ago (Migrated from github.com)

Bill Schmidt notifications@github.com wrote on 10.10.2017 18:06:07:

GCC seems to assume that the caller always allocates the Parameter Save
Area, and does so in the caller, but I don't think the ABI is entirely
explicit about this requirement. For example, section 2.24 (Variable
Argument Lists) has this in my copy:

The parameter list may be zero length and is only allocated when
parameters are spilled, when a function has unnamed parameters, or when
no prototype is provided. When the Parameter Save Area is allocated, the
Parameter Save Area must be large enough to accommodate all parameters,
including parameters passed in registers.

This text in 2.2.4 seems both redundant and outdated. Possibly it's
best to just remove it? Section 2.2.2.3 has the details of when to
create the parameter save area already.

If we do need to keep it, the wording "when a function has unnamed
parameters" should be clarified to "when the function prototype contains
an ellipsis to indicate a variadic function".

Bye,
Ulrich

Bill Schmidt <notifications@github.com> wrote on 10.10.2017 18:06:07: > GCC seems to assume that the caller always allocates the Parameter Save > Area, and does so in the caller, but I don't think the ABI is entirely > explicit about this requirement. For example, section 2.24 (Variable > Argument Lists) has this in my copy: > “ > The parameter list may be zero length and is only allocated when > parameters are spilled, when a function has unnamed parameters, or when > no prototype is provided. When the Parameter Save Area is allocated, the > Parameter Save Area must be large enough to accommodate all parameters, > including parameters passed in registers. > ” This text in 2.2.4 seems both redundant and outdated. Possibly it's best to just remove it? Section 2.2.2.3 has the details of when to create the parameter save area already. If we do need to keep it, the wording "when a function has unnamed parameters" should be clarified to "when the function prototype contains an ellipsis to indicate a variadic function". Bye, Ulrich
uweigand commented 7 years ago (Migrated from github.com)

Bill Schmidt notifications@github.com wrote on 10.10.2017 18:08:29:

“unless a prototype […] indicating all parameters can be passed in
registers” is still ambiguous because it could still be a decision
for individual call sites.

But it can be. If you have a non-variadic function, and one place
calls it with a correct prototype in scope, and another place calls
it without a prototype in scope, then the first caller will not
allocate the parameter save area, while the second will. This is
OK because the definition must then be non-varadic, and therefore
cannot assume the presence of the save area.

Basically, it is supported to call any function (variadic or not)
either without any prototype in scope, or with a correct prototype
in scope. It is not supported (and will not work) to call a function
with a wrong prototype in scope.

Bye,
Ulrich

Bill Schmidt <notifications@github.com> wrote on 10.10.2017 18:08:29: > “unless a prototype […] indicating all parameters can be passed in > registers” is still ambiguous because it could still be a decision > for individual call sites. But it *can* be. If you have a non-variadic function, and one place calls it with a correct prototype in scope, and another place calls it without a prototype in scope, then the first caller will not allocate the parameter save area, while the second will. This is OK because the definition must then be non-varadic, and therefore cannot assume the presence of the save area. Basically, it is supported to call any function (variadic or not) either without any prototype in scope, or with a correct prototype in scope. It is not supported (and will not work) to call a function with a *wrong* prototype in scope. Bye, Ulrich
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: systemsoftware/ELFv2-ABI#77
Loading…
There is no content yet.