Generate PIC for TEXT but absolute addresses for DATA/BSS
Hello,
I am using a Cortex m4 CPU with a flash starting from 0x0 and RAM from 0x2000 0000.
I would like to have several firmware partitions in the flash (e.g. at 0x00000, 0x10000, 0x20000,...) where different versions of the same firmware are written (by jtag or user update), and let the bootloader choose the preferred partition to boot on it.
This would mean having the text section being position independent, but data/ram at a fixed position.
I have been trying many options ( -fpic -fPIC -pie -fPIE -fno-plt -msingle-pic-base -mpic-register=X / even not working -mpic-on v6) but impossible to achieve the right behavior.
The best would be to get rid of any indirection or GOT for data/bss, but I cannot even get correct addressing.
- with -fpiX all static/global variables are relative to PC, so code will point to 0x2000 0000, 0x2001 0000, 0x2002 0000... depending on the partition run.
- with -msingle-pic-base -mpic-register=X, global variables are OK but static still using PC relative.
- the solution working the best is actually to use no flags and compile for partition 0x0 : all calls are PC relative in thumb mode, except when using function pointers (=> BLX reg). I then have to OR these pointers on the fly with the upper part of the PC. I also have to apply the same workaround to all pointers to rodata like literal string, which is quite difficult to maintain.
I can see however that I am not the first with this kind of problems:
https:/
https:/
https:/
Is what I want to do not feasible currently, or am I missing some features? does a new feature enabling this would interest other people?
Global options I am using and GCC version:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mabi=aapcs
gcc version 6.2.1 20161205 (release) [ARM/embedded-
Antoine
Question information
- Language:
- English Edit question
- Status:
- Expired
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: