object file not PIC showing relocatable?

524 Views Asked by At

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
2

There are 2 best solutions below

0
On

You misunderstood the difference between position independent and relocatable. Position independent shared libraries have relative addresses and can work anywhere in the virtual memory WITHOUT modification of the text segment. However, relocatable shared libraries have absolute addresses, so their text segment is modified every time they are loaded into RAM.

1
On

Because you are looking at the object file, before it is linked into a binary. ELF files are generally one of four types:

CORE core files

DYN Shared object file, for libraries

EXEC Executable file, for binaries

REL Relocatable file, before linked into an executable file

See this link for more info