'object file not PIC showing relocatable?
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
Solution 1:[1]
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
Solution 2:[2]
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
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | secret squirrel |
Solution 2 | Aqib Javed |