I have a working prototype of position independent code, where I can copy my binary to any location in flash, and jump to it.
While testing my app on different locations I ran into an issue. When I only deploy "app2" (thus, I do not write the app to flash on the originally linked location, but I upload the app to some offset location), then my application crashes as soon as it calls `__libc_init_array()` in startup code.
When I upload the app on the originally linked location, and again make my bootloader jump to app2, then it works fine.
So it seems that "libc_nano.a" isn't suitable for position independent code. I have the following library dependencies (taken over from the initially generated linker script by mcuxpresso)
GROUP ( "libgcc.a" "libc_nano.a" "libstdc++_nano.a" "libm.a" "libcr_newlib_nohost.a" "crti.o" "crtn.o" "crtbegin.o" "crtend.o" )
The c runtime object files are compatible for both pic and non pic, I understand from reading this oracle page.
When I comment the line `__libc_init_array()` in my startup code, my app2 starts fine, even without having app1 available in flash. So I am sure the only problematic line is this one.
Is there a solution for this? Should I compile libc_nano myself with -fpic? And if that's the way to go, where do I find the sources of the libraries nxp is providing me here? I found this github repo, but not sure if you compiled it from these sources.
I managed to workaround the first issue by copying the implementation of `__libc_init_array` from picolib. The next call I do towards libc_nano, will hard fault the application again.
Is there something I need to do specifically for the included libs? Are they linked against the .got automatically? Can you share an example please?