We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I try to compile an executable as a position independent executable. I have access to all the source code except for libc and crtbegin which are provided as pre-compiled libraries in the arm-none-eabi-gcc directory.
I compile my own libraries with -fPIC compiler and linker argument; and the executable with -fPIE compiler argument and -fPIE -pie linker arguments. But it appears the libc and crtbegin libraries are not compiled as position independent shared libraries i.e. without the -fPIC argument.
Please see the error I get below:
/opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7-a+fp/hard/crtbegin.o: relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7-a+fp/hard/libc.a(lib_a-ctype_.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7-a+fp/hard/libc.a(lib_a-exit.o): relocation R_ARM_THM_MOVW_ABS_NC against `_global_impure_ptr' can not be used when making a shared object; recompile with -fPIC /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7-a+fp/hard/libc.a(lib_a-fini.o): relocation R_ARM_THM_MOVW_ABS_NC against `__fini_array_end' can not be used when making a shared object; recompile with -fPIC /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7-a+fp/hard/libc.a(lib_a-init.o): relocation R_ARM_THM_MOVW_ABS_NC against `__preinit_array_end' can not be used when making a shared object; recompile with -fPIC /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7-a+fp/hard/libc.a(lib_a-__call_atexit.o): relocation R_ARM_THM_MOVW_ABS_NC against `_global_impure_ptr' can not be used when making a shared object; recompile with -fPIC /opt/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../ssbl_bsp//ps7_cortexa9_0/lib/librsa.a(SoftSHA256.o): relocation R_ARM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC collect2: error: ld returned 1 exit status make: *** [ssbl.elf] Erreur 1
Is there any way to get the librairies above compiled as PIC? or shall I compile the gnu toolchain myself with these arguments on?
Any advice is welcome.
Thank you
Hi, I have almost the same problem. I compile my project with -fpic, but my startup code fails when calling `libc_init_array` when I run my firmware from a different location. It seems to be a direct result of the same problem: libc_nano is not compiled with -fpic, thus when my "app2" is starting up, the call to `libc_init_array` redirects to `libc_init_array` linked to "app1" and my app hard faults.
I am also trying to figure out if and how I can recompile libc_nano with -fpic. But haven't found anything useful yet. Did you get passed this stage? Any tips?