Defect report from : Matthew Seitz , Individual
(Please direct followup comments direct to yyyyyyyyyyyyyy@xxxxxxxxxxxxx)
@ page 0 line 0 section dlsym comment {0}
Problem:
Defect code : 2. Omission
The "dlsym()" function is defined as returning "the address of a symbol".
According to the Example, "dlsym ()can be used to access either function or
data objects". The return type of dlsym is a "void *".
In order to actually call a function using the pointer returned by "dlsym()",
the pointer must be converted from a "void *" type to a pointer to function
type. However, the ISO C Standard says that converting a "void *" type to a
pointer to function type results in undefined behavior. At least one major
compiler reports a warning when attempting such a conversion, even with an
explicit cast.
Action:
I would like a new function added that returns the address of a function object
symbol and whose return type is a function pointer. For example:
fptr_t dlsym_f(void *restrict handle, const char *restrict name);
Standard C requires that a pointer to a function of one type may be converted
to a pointer to a function of another type and back again, and the result shall
compare equal to the original pointer. Therefore, "fptr_t" can be defined as
any pointer to function type.
The "dlsym()" function could continue to be used for data objects. As an
extension, implementations that allow converting from "void *" to pointer to
function types could continue to allow using "dlsym()" in addition to
"dlsym_f()" for function objects. This would allow backwards compatability,
while offering a more portable option for new code.
|