As far as I know, x86 assembly code is very much constrained by the limited amount of registers.
When I learnt that on Linux, to create a .so file, one has to specify the -fPIC command line argument to gcc in order to create position independent code, I couldn't believe it first.
As far as I know, the elf file format supports relocations, just like the - in my eyes much better - Windows DLL system works: On Windows the linker relocates all the offsets in the DLLs, if this is necessary.
I think that the time needed to load a SO-file or DLL-file, and also the amount of memory used to keep differently relocated .so-files around is not as bad as the lack of a whole register all the time which points to the GOT and having all this indirect jumps.
I also don't care at all for ALSR etc. for the applications I have in mind were I only care about having code in a library to be optimized as much as possible.
1) Why does Linux not support more dynamic library loading like Windows which should produce much much more performant code?
So far I have found no real explanation for it. Just some things like that it would be so very bad and slow to relocate code (Of course, for loading a word processor on a desktop machine, it matters how fast it loads, I fully accept that. But for a computationally intensive server process (not processing malicious data from the internet), I'd like to have all the performance and registers I can get!
2) Is it possible for me to create NOT -fPIC compiled SO-files on Linux? Can I just leave the -fPIC away? Is there any howto, manual or project which works on this topic and makes it possible to not waste a whole register and still load libraries dynamically?
What happens if I just drop the -fPIC when compiling a .so-file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…