I recently worked on a job that required me to get the address of a particular instruction in a code segment of Linux Kernel, , I tried to do this with the Labels as Values provided by gcc. like this:
u64 address;
noinline void foo()
{
address = (u64) && label;
// some code
label: // the virtual address I want
// some code
}
But the value of address
is not correct, it’s given as &foo
. I guess the reason for the error is that address is not a static constant(It’s a global value), and this is an assignment procedure, not an initialization procedure.
I would like to know if there is a way to “get the virtual address of any instruction and store it in a variable” in the linux kernel.