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.         


猜你喜欢

转载自blog.csdn.net/lcxhjg/article/details/80938350
今日推荐