cpointersmemory-corruption

How to debug Segmentation fault due to "Jump to the invalid address"?


I am working on an application which runs on am335x arm processor. I am defining following structure which contains function pointer to "Command" function. "Command" function is defined below in same file

ObjectDef BPObjectDef = { CCR_COMMS, 1, ATTRIBUTES, "BP", Command };

static BYTE Command( ObjectPtr Obj, BYTE Command)
{
<not writing code because function is big>
}

I cross complied above code and binary is generated. With objdump -t I can see that "Command" function got following address

00013f0d l     F .text  0000016c              Command

But when I run the binary on target machine I get following address for "Command" function

address of BPObjectDef.Command = 0x3f0d0000

as we can see that last two bytes of addressed are swapped with first two bytes. This leads to segmentaion fault while accessing this function. Anybody has faced similar issue before? How to debug in this case? I guess I cannot use address sanitizer as it is an arm platform.Thanks


Solution

  • @Yunnosch you are genius! As you've mentioned in comments, address was getting altered because of structure padding. Using #pragma pack(1) before structure declaration solved the problem. Thank you very much