gcc __attribute__ ((weak, alias (#name)))
来源:互联网 发布:fanuc pmc编程 编辑:程序博客网 时间:2024/05/16 11:13
本系列文章,着重讲__attribute__的用途
此属性,可以借助uClibc里面的弱符号来对库里符号进行一些更改,可以用于调试,我最近就用
这个功能来调试system,很好用,类似可以实现hook函数的还有LD_PRELOAD,
参见 http://blog.csdn.net/green369258/article/details/7314298
uClibc 库里面的所有accept 等等 符号都是若符号,因为他都是这样定义的
weak_alias(__libc_accept,accept)weak_alias(__libc_connect,connect)
被重新命名的函数原型
int __libc_connect(int sockfd, const struct sockaddr *saddr, socklen_t addrlen)int __libc_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
在编译恰默认搜索路径的头文件中搜索weak_alias ,无法找到,在uClibc中找到它的声明实际上
也很简单
# define weak_alias(name, aliasname) _weak_alias (name, aliasname)# define _weak_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
一个简单的例子
#include <stdio.h>#include <stdlib.h># define weak_alias(name, aliasname) _weak_alias (name, aliasname)# define _weak_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));char* const_foo() __attribute__ ((const));void __foo() { printf("this is foo\n");}void f() __attribute__ ((weak,alias("__foo")));weak_alias(__foo, f1);char* const_foo(){ char* err = (char*)malloc(10*sizeof(char)); sprintf(err,"%s","hello"); return err;}int main(){ char* str; __foo(); f(); f1(); str = const_foo(); free(str); str = NULL; return 0;}
程序输出
this is foothis is foothis is foo
说明函数__foo被重命名了。
0 0
- gcc __attribute__ ((weak, alias (#name)))
- gcc __attribute__ ((weak, alias (#name))) 1
- GCC __attribute__ 之weak,alias属性
- __attribute__ 之weak,alias属性
- __attribute__ 之weak,alias属性
- __attribute__ 之weak,alias属性
- __attribute__ 之weak,alias属性
- __attribute__ 之weak,alias属性
- __attribute__ 之weak,alias属性 .
- gcc: __attribute__ ((weak))
- int main (void) __attribute__ ((weak, alias ("alt_main")));
- 【转】__attribute__ 之weak,alias属性
- gcc之weak,alias属性
- gcc attribute weak & alias应用
- gcc attribute weak & alias应用
- gcc attribute weak & alias应用
- gcc attribute weak & alias应用
- gcc __attribute__关键字举例之alias
- Android事件分发机制
- AndroidStudio快捷键设置
- PHP数组问题
- 程序内存分配
- [LeetCode] 226 Invert a binary tree.
- gcc __attribute__ ((weak, alias (#name)))
- Unix高级环境编程
- JPA 不在 persistence.xml 文件中配置每个Entity实体类的2种解决办法
- Linux debian常用软件与虚拟机的安装配置
- duilib JS与C++的相互调用
- swift学习
- 项目三——单链表的应用(3)
- “No 'Access-Control-Allow-Origin' header is present on the requested resource”
- jQuery源码学习 之 get与eq的区别