I'm using QEMU to simulate an ARM11 CPU.
My program is too complicated to explain here, so i'll project the issue into a simpler program. So my program contains 2 c files:
I'm compiling some_code.c (into some_code.o) and then i convert it to an HEX array variable, which represents the code of some_code.c.
Now i'm linking both object files (main.o & some_code.o). This variable (HEX array variable) is located at the DATA segment.
Now I’m calling from the code in main.c to the HEX array variable (my intention is that at this point the code of some_code.c will start executing). When the Program Counter (PC) reach the HEX array variable, it gets an exception (i don't have more details about the exception).
If i copy this HEX array variable from DATA section to CODE section, now when the PC reach this line, it is successfully able to step it without exception.
So my questions are:
Thanks in advanced,
Omri
It will be a combination of the linker and the operating system. It is likely that the linker marks the data section as "data" and the loader will then create an area of memory without execute privilege on it to contain the data. This is a feature of the hardware QEMU is emulating, not QEMU itself i.e. if you were running this on a real machine, you would see the same problem.
It will be possible to change the data section to be executable, but the details will depend on which OS you are running and what compiler toolchain you are using. Any interpreter that has a JIT compiler must do something similar.
Note that, in general, it is considered to be bad practice to make the data section executable because that can lead to all sorts of security exploits.