doorxp-blog

doorxp.com

shared library is loaded auto run


It's run when a shared library is loaded, typically during program startup.


1. before main

void tmain() __attribute__((constructor(101))){
    printf("abc\n");
}

2.module init


typedef  void (INITFUC)(int argc, char **argv, char **envp);
void myinit(int argc, char **argv, char **envp) {
  printf("%s: %s\n", __FILE__, __FUNCTION__);
  for (int i = 0; i<argc;i++) {
  printf("%d:%s\n",i, argv[i]);
  }
}
__attribute__((section("__DATA,__mod_init_func"))) INITFUC *__init = myinit;


发表评论:

Powered By Z-BlogPHP 1.5.1 Zero

Copyright doorxp.com Rights Reserved.