The LD_PRELOAD
trick can help for dynamic linking of binaries at runtime, but it will fail for a statically linked binary.
I want to override some c++ startup functions (like changing code for __libc_start_main
, __libc_csu_init
and a few others). I was thinking of changing the code directly from glibc
but I want to be sure that there is no other way to get things worked out.
Is there any other way to override c++ startup functions than to change code from glibc
and building it again?
Depending on what you want to exclude, you'll need -nostartfiles
, -nodefaultlibs
or -nostdlib
. You'll then add your own replacements. If your replacement is incomplete (likely), you'd add the original libraries such as glibc
after your own. The linker uses them in the listed order, so your overrides now get preference.
Implictly-linked libraries act as if they appeared first, which is why you need to specifically exclude them and then add them back. See also g++, static initialization and -nostdlib