attribute的用法
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <ucontext.h>
//写几个优先级函数
static __attribute__((constructor(101))) void before1();
static __attribute__((constructor(102))) void before2();
static __attribute__((constructor(103))) void before3();
static __attribute__((constructor(104))) void before4();
int main()
{
printf("main.c\n");
}
static __attribute__((constructor(101))) void before1()
{
printf("before1\n");
}
static __attribute__((constructor(102))) void before2()
{
printf("before2\n");
}
static __attribute__((constructor(103))) void before3()
{
printf("before3\n");
}
static __attribute__((constructor(104))) void before4()
{
printf("before4\n");
}
执行结果
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s5Vul19C-1616938931536)(C:\Users\11066\AppData\Roaming\Typora\typora-user-images\1616938832808.png)]
最直观的效果就是可以注册一些在main入口之前的一些操作
931536)]
最直观的效果就是可以注册一些在main入口之前的一些操作
比如注册一些信号用于监听段错误