This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Fwd: Undefined behaviour code used in sysdeps/unix/sysv/linux/x86_64/makecontext.c
- From: Remus Clearwater <remus dot clearwater at gmail dot com>
- To: Godmar Back <godmar at gmail dot com>
- Cc: libc-help at sourceware dot org
- Date: Mon, 21 May 2018 21:08:59 +0800
- Subject: Fwd: Undefined behaviour code used in sysdeps/unix/sysv/linux/x86_64/makecontext.c
- References: <CAMjELSscx-WZdBTrhhi_jzunQb+cU9_4d3-XBeN17RW1x8XyWg@mail.gmail.com> <CAB4+JYJe0CWFKkYCePR=xiLjnotvAwC8hO-sqmvgf6EcK2-k4A@mail.gmail.com> <CAMjELStuFqCE3iVUR-ju3nZqG89dzfPET9kTWniz+kGPOm12ug@mail.gmail.com>
Sorry for forgot to CC libc-help.
----
Thanks a lot Godmar.
But it didn't say `sizeof(function_pointer)` are must equal or less than
`sizeof(void*)`.
I found this in POSIX.1-2008 http://pubs.opengroup.org/
onlinepubs/9699919799.2008edition/functions/V2_chap02.html#tag_15_12_03:
"All function pointer types shall have the same representation as the type
pointer to void. Conversion of a function pointer to void * shall not alter
the representation. A void * value resulting from such a conversion can be
converted back to the original function pointer type, using an explicit
cast, without loss of information.
Note:
The ISO C standard does not require this, but it is required for POSIX
conformance."
So under POSIX.1-2008 the kinda usage of `function_address = (uintptr_t)
funcfp;` is correct, but in POSIX.1-2017 this section 2.13.3 has been
removed. This means in POSIX.1-2017 that kinda conversition is still not
defined.