With gcc, you can tag a function with the constructor attribute (which causes the function to be run before main
). In the following function, premain
will be called before main
:
#include <stdio.h>
void premain() __attribute__ ((constructor));
void premain()
{
fputs("premain
", stdout);
}
int main()
{
fputs("main
", stdout);
return 0;
}
So, if there is a crashing bug in premain
you will crash before main
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…