Overriding C library functions, calling original

后端 未结 4 1255
野性不改
野性不改 2020-12-03 11:00

I am a bit puzzled on how and why this code works as it does. I have not actually encountered this in any project I\'ve worked on, and I have not even thought of doing it my

4条回答
  •  执笔经年
    2020-12-03 11:43

    What you see is expected behaviour if you linking with shared libraries. Linker will just assign it to your function, as it was first. It will also be correctly called from any other external libraries functions, - because linker will make your function exportable when it will scan linking libraries.

    But - if you, say, have no external libraries that links to your function (so it isn't marked exportable, and isn't inserted to symbol table), and then dlopen() some library that want to use it during runtime - it will not find required function. Furthermore, if you first dlopen(RTLD_NOW|RTLD_GLOBAL) original library, every subsequent dlopen()'d library will use this library code, not yours. Your code (or any libraries that you've linked with during compilation phase, not runtime) will still stick with your function, no matter what.

提交回复
热议问题