0

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

ASmith
  • 21
  • 2
  • 1
    The option `-fPIC` of course creates position independent data. It's just that strings are placed in a special section to save memory. Perhaps you could post some sample assembly to outline your problem? – fuz Feb 07 '16 at 09:54
  • You need to create a custom linker script and put `.rodata` where you think it is needed. Also, the option `-mpic-data-is-text-relative` might be useful. As well, you could provide some sample code and point out where the issue is. Ie, `printf("October\n");` A full example is helpful. – artless noise Feb 07 '16 at 18:55

0 Answers0