I have a small library, and I build it with gcc without -fPIC option, I think this would mean that the generated object file will not be relocatable, but when I issued file command, it shows relocatable, why?
build command:
gcc -DNDEBUG -g -o module.o -c module.c
file module.o
module.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
You misunderstood the difference between position
independentandrelocatable. Positionindependentsharedlibrarieshave relative addresses and can work anywhere in the virtual memory WITHOUT modification of the text segment. However,relocatableshared libraries haveabsoluteaddresses, so their text segment is modified every time they are loaded intoRAM.