3 ms·
If you're using shared libraries in your program, you already have this extra indirection - at compilation/link time the compiler/linker doesn't know where in m
by nteon 11y ago
If you're using shared libraries in your program, you already have this extra indirection - at compilation/link time the compiler/linker doesn't know where in memory the shared library will be when the program is run, so every call into a library goes through the procedure linkage table (PLT), which works by looking up the 'real' function pointer in the global offset table (GOT).
So yea, populating this at runtime depending on the CPU features supported by your CPU is possible, and the linux dynamic linker does this: http://man7.org/linux/man-pages/man8/ld.so.8.html http://man7.org/linux/man-pages/man8/ld.so.8.html (check out the section on hardware capabilities).
- nteon 11y agofor an example, checkout this: http://pasky.or.cz/dev/glibc/ifunc.c http://pasky.or.cz/dev/glibc/ifunc.c Two implementations are compiled (one is optimized using instructions only available on certain processors), and the decision of which one to use is made at program startup.
- pjc50 11y agoWe should bring this point out next time there's a wave of comments saying that static linking is the one true way.
- qu4z-2 11y agoIf you need to redirect all your function calls through a giant array, you can technically do that with static linking too. Just sayin'...