libc library compiled with PIC

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

More questions in this forum