I would like to write a position relative code that includes data.
that means, a function that gets the absolute address of printf and prints a simple string.
I have managed to achieve this by compiling an ELF using arm-none-eabi-gcc with the parameter -fPIC. The problem is converting the ELF file into a flat binary using objcopy.
objcopy places the string on the top of the file, thus makes the data no more position independent, instead of leaving the string at the end of the function, to be addressed by the program counter.
Am I missing something? Is it possible for objcopy to create a flat binary with position independent data?
EDIT:
It is possible to see in the attached image that the string is in an absolute address above my function instead of at the end of it and pointed to by PC