Elf 文件常用工具



1.        Size

2.        Nm

3.        Readelf

 



 

 


4.        Attribute of the Function

以下是常用的几个attribute

a)        __attribute__ format

The format attribute specifies that a function takes printf, scanf stylearguments which should be type-checked against a format string. For example,the declaration:

          extern int

          my_printf (void*my_object, const char *my_format, ...)

                __attribute__((format (printf, 2, 3)));

causes the compiler to check the arguments in callsto my_printf for consistency with the printf style formatstring argument my_format.

b)       __attribute__ noreturn

The noreturn keyword tells the compiler to assumethat function cannot return.

extern void exitnow() __attribute__((noreturn));

c)        __attribute__ const

d)       __attribute__ weak

The weak attribute causes the declaration to be emitted asa weak symbol rather than a global. This is primarily useful in defininglibrary functions which can be overridden in user code, though it can also beused with non-function declarations.

e)        __attribute__ constructor

The constructor attribute causes the function to be calledautomatically before execution enters main ().

f)         __attribute__ destructor

The destructor attribute causes the function to be calledautomatically after main () has completed or exit () hasbeen called.

 

extern void die(const char *format, ...)
  __attribute__((noreturn))
             __attribute__((format(printf, 1, 2)));
 
/*or*/
 
extern void die(const char *format, ...)
  __attribute__((noreturn, format(printf, 1, 2)));
 

g)        __attribute__ alias

定义别名, 可以定义一个函数的别名, 如下可以使用函数fsl_memset代替glibc中的函数memset,

void * memset(void *dst, int val, size_t n) __attribute__((alias ("fsl_memset")));

 

 

http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html

https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/

https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Variable-Attributes.html#Variable-Attributes

 

 

5.         


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值