1

I am trying to locate the address of task_struct of a thread. First of all, I need to get the address of task_struct of the init_task, then I iterate the whole list and finally get the task_struct of a specific thread. The task_struct of the init_task can be easily obtained from /proc/kallsyms by the command

grep "\<init_task\>" /proc/kallsyms.

This worked when I use older kernel version (3.12). But when I switched to newer version (4.5), this idea failed at the very beginning. Because the symbol init_task disappears from /proc/kallsyms. But when I checked the source code, I can see that the symbol init_task is exported (http://lxr.free-electrons.com/source/init/init_task.c?v=4.5#L18). Why it doesn't show up in the /proc/kallsyms? Or is there any other approach to get the address of init_task from user space programs?

6
  • What is the architecture of your machine? Is there any chance it's IA64? Also, look if CONFIG_ARCH_INIT_TASK is set to y in your kernel .config. Commented Jun 9, 2016 at 17:44
  • No, my machine is x86_64. And my current version (4.5) of kernel config file has no CONFIG_ARCH_INIT_TASK option. I also checked the .config file of the old kernel version (3.12) which has init_task symbol exported, there is also no such option. It seems that the problem is not because of the .config file -:((
    – B.S.Gao
    Commented Jun 10, 2016 at 9:52
  • Can you check next two options in your .config for new kernel: CONFIG_UNUSED_SYMBOLS and TRIM_UNUSED_KSYMS? It's unlikely some of them is enabled, but if yes -- it can be the cause. Commented Jun 10, 2016 at 11:28
  • Yes, the new kernel has the CONFIG_UNUSED_SYMBOLS=y, but no TRIM_UNUSED_KSYMS option was found. To my understanding, enabling the CONFIG_UNUSED_SYMBOLS option will export unused symbols, that means if the init_task is not used, it will be exported anyway. So this doesn't seem to be the cause. Or am I misunderstanding ?
    – B.S.Gao
    Commented Jun 11, 2016 at 15:28
  • Yes, your understanding is correct. I see only 2 possible reasons why you are missing init_task() symbol: 1. If CONFIG_ARCH_INIT_TASK=y 2. CONFIG_TRIM_UNUSED_KSYMS=y and symbol is not used in kernel. Probably there is some another mechanism in place that strips unused symbols out, but I'm not aware of it. Commented Jun 11, 2016 at 16:19

1 Answer 1

0

Try compiling with CONFIG_KALLSYMS_ALL option set. Without it kallsyms seems to include only symbols from .text and init.text sections: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/link-vmlinux.sh#n152, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kallsyms.c#n250

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.