[uclibc-ng-devel] ucontext on PowerPC, broken header logic?

Thomas Petazzoni thomas.petazzoni at free-electrons.com
Thu Aug 11 22:55:57 CEST 2016


Hello,

According to getcontext(3), the *context functions and the ucontext_t
structure are defined in <ucontext.h>.

If you take this simple program:

"""
#define _GNU_SOURCE
#include <ucontext.h>

int main(void)
{
        ucontext_t *ucontext;
        return ucontext->uc_mcontext.uc_regs->gregs[0];
}
"""

and build it with a uClibc-ng PowerPC toolchain, it will fail with:

"""
foo.c: In function 'main':
foo.c:5:2: error: unknown type name 'ucontext_t'
  ucontext_t *ucontext;
...
"""

And indeed <ucontext.h> in uClibc-ng only includes <sys/ucontext.h> if
__UCLIBC_HAS_CONTEXT_FUNCS__ is defined, which is not the case on
PowerPC. And since <sys/ucontext.h> is where ucontext_t is defined, the
build failure is expected.

However, now, change the program to:

"""
#define _GNU_SOURCE
#include <ucontext.h>
#include <signal.h>

int main(void)
{
        ucontext_t *ucontext;
        return ucontext->uc_mcontext.uc_regs->gregs[0];
}
"""

i.e with just <signal.h> included. And now, it builds fine!

Indeed <signal.h> includes <sys/ucontext.h> unconditionally, without
taking care of __UCLIBC_HAS_CONTEXT_FUNCS__. This seems broken to me,
as-is the fact that some ucontext structures are defined in a header
file even if the platform doesn't support context functions.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


More information about the devel mailing list