I need to add members to task_struct in Linux kernel 4.8.0. However, when I did it and tried to build the kernel, the error message shows:
In file included from linux-hwe-4.8.0/include/uapi/linux/stddef.h:1:0,
from linux-hwe-4.8.0/include/linux/stddef.h:4,
from linux-hwe-4.8.0/include/uapi/linux/posix_types.h:4,
from linux-hwe-4.8.0/include/uapi/linux/types.h:13,
from linux-hwe-4.8.0/include/linux/types.h:5,
from linux-hwe-4.8.0/include/linux/compat.h:8,
from linux-hwe-4.8.0/arch/x86/include/asm/fpu/internal.h:13,
from linux-hwe-4.8.0/arch/x86/kernel/fpu/init.c:4:
In function ‘fpu__init_task_struct_size’,
inlined from ‘fpu__init_system’ at linux-hwe-4.8.0/arch/x86/kernel/fpu/init.c:390:2:
linux-hwe-4.8.0/include/linux/compiler.h:491:38: error: call to ‘__compiletime_assert_192’ declared with attribute error: BUILD_BUG_ON failed: sizeof(struct task_struct) != ALIGN(offsetofend(struct task_struct, thread), TYPE_ALIGN(struct task_struct))
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
How to get rid of such errors and build my kernel successfully?
Advertisement
Answer
The assertion you’re encountering is triggered by a macro (CHECK_MEMBER_AT_END_OF) that checks that the thread member of struct task_struct is its last field.
As per the kernel source, linux/sched.h:
/* CPU-specific state of this task */
struct thread_struct thread;
/*
* WARNING: on x86, 'thread_struct' contains a variable-sized
* structure. It *MUST* be at the end of 'task_struct'.
*
* Do not put anything below here!
Simply add your new fields before it.