Elf文件解析
目标文件格式
Elf文件头
大端小端Inter               摩托罗拉
节头结构
字符串表
符号表项
重定位项结构
1. Upload Sky shell with exec command and symbols (requiresseveral recompilations to generate correct symbols):> make sky-...
Symbols怎么生成• Makefile.msp430中ifdef COREsymbols.c:#        @${CONTIKI}/tools/msp430-make-symbols $(CORE)         $(NM) $(CO...
命令• Msp430-nm - list symbols from object files• awk [options] -f scriptfile var=value file(s)awk是一种编程语言,用于在linux/unix下对文本和...
mknmlist                                                      /^[0123456789abcdef]+ [ABCDGRSTUVW] / {                     ...
Elf文件解析
Upcoming SlideShare
Loading in...5
×

Elf文件解析

669

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
669
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Elf文件解析

  1. 1. Elf文件解析
  2. 2. 目标文件格式
  3. 3. Elf文件头
  4. 4. 大端小端Inter 摩托罗拉
  5. 5. 节头结构
  6. 6. 字符串表
  7. 7. 符号表项
  8. 8. 重定位项结构
  9. 9. 1. Upload Sky shell with exec command and symbols (requiresseveral recompilations to generate correct symbols):> make sky-shell-exec.sky 编译内核> make sky-shell-exec.sky CORE=sky-shell-exec.sky 生成symbols> make sky-shell-exec.upload CORE=sky-shell-exec.sky 再次编译内核如果直接执行第二条命令,可以生成sky-shell-exec.sky ,symbols为空,
  10. 10. Symbols怎么生成• Makefile.msp430中ifdef COREsymbols.c:# @${CONTIKI}/tools/msp430-make-symbols $(CORE) $(NM) $(CORE) | awk -f $(CONTIKI)/tools/mknmlist > symbols.celsesymbols.c symbols.h: @${CONTIKI}/tools/make-empty-symbolsEndif
  11. 11. 命令• Msp430-nm - list symbols from object files• awk [options] -f scriptfile var=value file(s)awk是一种编程语言,用于在linux/unix下对文本和数据进行处理。数据可以来自标准输入、一个或多个文件,或其它命令的输出。它支持用户自定义函数和动态正则表达式等先进功能,是linux/unix下的一个强大编程工具。它在命令行中使用,但更多是作为脚本来使用。awk的处理文本和数据的方式是这样的,它逐行扫描文件,从第一行到最后一行,寻找匹配的特定模式的行,并在这些行上进行你想要的操作。如果没有指定处理动作,则把匹配的行显示到标准输出(屏幕),如果没有指定模式,则所有被操作所指定的行都被处理。
  12. 12. mknmlist /^[0123456789abcdef]+ [ABCDGRSTUVW] / { if ($3 != "symbols" && $3 != "symbols_nelts") { name[nname] = $3; nname++;function sort(V, N, tmp, i, j) { } V[-1] = ""; # Used as a sentinel before V[0]. } for (i = 1; i < N; i++) for (j = i; V[j - 1] > V[j]; j--) { END { tmp = V[j]; sort(name, nname); V[j] = V[j - 1]; V[j - 1] = tmp; } print "#include "loader/symbols.h"n"; return;} # Must deal with compiler builtins etc. for (x = 0; x < nname; x++) {BEGIN { if (builtin[name[x]] != "") nname = 0; print builtin[name[x]] ";"; builtin["printf"] = "int printf(const char *, ...)"; else builtin["sprintf"] = "int sprintf(char *, const print "extern int " name[x]"();";char *, ...)"; } builtin["malloc"] = "void *malloc()"; print "n"; builtin["calloc"] = "void *calloc()"; builtin["memcpy"] = "void *memcpy()"; # nname++: An { 0, 0 } entry is added at the end of the vector. builtin["memset"] = "void *memset()"; print "const int symbols_nelts = " nname+1 ";"; builtin["memmove"] = "void *memmove()"; print "const struct symbols symbols[" nname+1 "] = {"; builtin["strcpy"] = "char *strcpy()"; for (x = 0; x < nname; x++) builtin["strchr"] = "char *strchr()"; print "{ "" name[x] "", (void *)&"name[x]" },"; builtin[""] = ""; print "{ (const char *)0, (void *)0} };";} }

×