ELF文件之八——使用链接脚本-2个函数-data-bss-temp-call-debug信息
gcc编译选项可以设置生成调试信息,
debug信息格式有stabs,coff,xcoff,dwarf。
常用的有两种格式,stab和dwarf,stab较早,dwarf较新。两种格式介绍:https://www.ibm.com/developerworks/cn/opensource/os-debugging/
单独-g可以生成只有gdb能识别的额外辅助信息,如果不想生成这些辅助信息,可以使用-gstabs等选项,只生成stabs调试信息,不生成额外辅助信息。
调试选项-g和优化选项-O一起使用的话,可能会导致调试信息与最终不一致,比如,定义的变量被优化掉了等,因此,-g时最好不用-O。
-g生成操作系统固有的格式,对于sparc来说,使用-g会生成stab格式。
如果使用-g -gdwarf-2,则会生成dwarf-2格式的调试信息,不再生成stab格式的。这两个选项允许同时存在。
如果使用-gstabs -dwarf-2,则后一个-dwarf-2会并忽略,因为和stabs冲突,即生成stabs格式的调试信息。这两个是同时存在是不允许的。
- -g
- Produce debugging information in the operating system's native format (stabs, COFF,
- XCOFF, or DWARF). GDB can work with this debugging information.
- On most systems that use stabs format, `-g' enables use of extra debugging information
- that only GDB can use; this extra information makes debugging work better in GDB but
- will probably make other debuggers crash or refuse to read the program. If you want to
- control for certain whether to generate the extra information, use `-gstabs+' , `-gstabs' ,
- `-gxcoff+' , `-gxcoff' , `-gdwarf-+' , or `-gdwarf-1' (see below).
- Unlike most other C compilers, GCC allows you to use `-g' with `-O' . The shortcuts taken
- by optimized code may occasionally produce surprising results: some variables you
- declared may not exist at all; flow of control may briefly move where you did not expect it;
- some statements may not be executed because they compute constant results or their values
- were already at hand; some statements may execute in different places because they were
- moved out of loops.
添加-g选项后,生成的elf文件节头表如下:stab长度为0x240=576,stabstr长度为0x4de=1246,共1822字节
原来的elf为839字节,新elf为2787字节。增加的debug信息比原来的全部elf还多,1822>839。
- Section Headers:
- [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
- [ ] NULL
- [ ] .text PROGBITS AX
- [ ] .data PROGBITS 0000a4 WA
- [ ] .bss NOBITS 0000a8 WA
- [ ] .stab PROGBITS 0000a8 0c
- [ ] .comment PROGBITS 0002e8
- [ ] .stabstr STRTAB 0002fa 0004de
- [ ] .shstrtab STRTAB 0007d8
- [ ] .symtab SYMTAB 0009ac c
- [ ] .strtab STRTAB 000abc
没有-g的节头表
- Section Headers:
- [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
- [ ] NULL
- [ ] .text PROGBITS AX
- [ ] .data PROGBITS 0000a4 WA
- [ ] .bss NOBITS 0000a8 WA
- [ ] .comment PROGBITS 0000a8
- [ ] .shstrtab STRTAB 0000ba
- [ ] .symtab SYMTAB 0000f0 a
- [ ] .strtab STRTAB
shstrtab symtab section hdr
旧elf,839 0x35=53 0xf0=240 320
新elf,2787 0x44=68 0x110=272 400
增加量, 15 32 80
debug 1822+15+32+80=1949
2787-839=1948
stab大小为0x240=578,每个项目12字节,如下,共48个项目
- struct internal_nlist {
- unsigned long n_strx; /* index into string table of name */
- unsigned char n_type; /* type of symbol */
- unsigned char n_other; /* misc info (usually empty) */
- unsigned short n_desc; /* description field */
- bfd_vma n_value; /* value of symbol */
- };
stab段,0x8a开始,12字节一个项目,看不明白。
The “stabs” debug format: http://www.sm.luth.se/csee/courses/smd/D0013E/doc/stabs.pdf
链接:https://pan.baidu.com/s/1Fv3zcqNhScUdaHp4PyAYsQ
提取码:by76
增加-gdwarf选项后,生成的dwarf格式的节多了5个。
- Section Headers:
- [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
- [ ] NULL
- [ ] .text PROGBITS AX
- [ ] .data PROGBITS 0000f8 WA
- [ ] .bss NOBITS 0000fc WA
- [ ] .rodata PROGBITS A
- [ ] .line PROGBITS 0000fc 00009e
- [ ] .debug_pubnames PROGBITS 00019a 00002d
- [ ] .debug_aranges PROGBITS 0001c7
- [ ] .debug PROGBITS 0001f8 00025c
- [ ] .comment PROGBITS
- [] .shstrtab STRTAB
- [] .symtab SYMTAB 0006d8 f
- [] .strtab STRTAB
可以用objdump输出stab信息,以下是某个elf文件输出的stab信息,但有一堆看着没用的东西,使用如下命令
objdump -G main.elf > debug.txt
- main.elf: file format elf32-sparc
- Contents of .stab section:
- Symnum n_type n_othr n_desc n_value n_strx String
- - HdrSym
- SO ../src/main.c
- OPT gcc2_compiled.
- LSYM int:t(,)=r(,);-;;
- LSYM char:t(,)=r(,);;;
- LSYM long int:t(,)=r(,);-;;
- LSYM unsigned int:t(,)=r(,);;-;
- LSYM long unsigned int:t(,)=r(,);;-;
- LSYM long long int:t(,)=r(,);;-;
- LSYM long long unsigned int:t(,)=r(,);;-;
- LSYM short int:t(,)=r(,);-;;
- LSYM short unsigned int:t(,)=r(,);;;
- LSYM signed char:t(,)=r(,);-;;
- LSYM unsigned char:t(,)=r(,);;;
- LSYM float:t(,)=r(,);;;
- LSYM double:t(,)=r(,);;;
- LSYM long double:t(,)=r(,);;;
- LSYM complex int:t(,)=s8real:(,),,;imag:(,),,;;
- LSYM complex float:t(,)=R3;;;
- LSYM complex double:t(,)=R4;;;
- LSYM complex long double:t(,)=R4;;;
- LSYM __builtin_va_list:t(,)=*(,)=(,)
- LSYM _Bool:t(,)=eFalse:,True:,;
- BINCL 00000ce2 ../src/main.c
- FUN main:F(,)
- SLINE
- SLINE
- SLINE
- LSYM fffffff0 d:(,)
- LBRAC
- RBRAC
- GSYM var_data:G(,)
- GSYM var_bss:G(,)
- SO
ELF文件之八——使用链接脚本-2个函数-data-bss-temp-call-debug信息的更多相关文章
- ELF文件之四——使用链接脚本-2个函数-data
main.c ; int main() { ; } int add() { ; } main.o 反汇编可以看到多了.text节的反汇编,存储的是全局变量的初始化数值 main.o对比,text段后面 ...
- ELF文件之七——使用链接脚本-2个函数-data-bss-temp-call
main.c int enable; ; int main() { int temp; add(); ; } int add() { ; } o反汇编的地址都是0起始,elf的地址都是映射后的地址. ...
- ELF文件之三——使用链接脚本-2个函数
main.c int main() { ; } int add() { ; } main.o的比较 与之二相比,section header offset由0x90变为0xA4,增加0x14,即add ...
- ELF文件之六——使用链接脚本-2个函数-data-bss-temp
main.c int enable; ; int main() { int temp; ; } int add() { ; } elf反汇编结果如下,可以看出main函数中的栈多开了8字节,虽然局部变 ...
- ELF文件之五——使用链接脚本-2个函数-data-bss
main.c int enable; ; int main() { ; } int add() { ; } bss段在elf中虽然size是4,但并不占filesize,节头表如下图所示 程序头中,项 ...
- ELF文件之九——使用链接脚本-2个函数-data-bss-temp-call-debug信息-struct
main.c int enable; ; struct aaa { int membera; char memberb; }s_aaa; int main() { int temp; add(); d ...
- 裸板驱动总结(makefile+lds链接脚本+裸板调试)
在裸板2440中,当我们使用nand启动时,2440会自动将前4k字节复制到内部sram中,如下图所示: 然而此时的SDRAM.nandflash的控制时序等都还没初始化,所以我们就只能使用前0~40 ...
- arm裸板驱动总结(makefile+lds链接脚本+裸板调试)
在裸板2440中,当我们使用nand启动时,2440会自动将前4k字节复制到内部sram中,如下图所示: 然而此时的SDRAM.nandflash的控制时序等都还没初始化,所以我们就只能使用前0~40 ...
- 四、u-boot 链接脚本
4.1 C语言中的段 编译器在编译程序的时候,将程序中的所有的元素分成了一些组成部分,各部分构成一个段,所以说段是可执行程序的组成部分. 代码段:代码段就是程序中的可执行部分,直观理解代码段就是函数堆 ...
随机推荐
- Asp.Net Core 3.0 Kestrel服务器下 高性能 WebSocket Server
最近研究.net core 的各种高性能类型,内存池之类的东西,基于kestrel 服务器的websocket ,写个例子练下手 把原生的Websocket用ArrayPool<T>,Me ...
- 怎么将文件夹上传到GitHub上
1. 在GitHub上新建一个仓库地址: http://github.com/......git 2. 在需要上传的文件夹目录下,运行 git init 初始化git: 3. 运行git ad ...
- ntelliJ IDEA添加注释常用的快捷键
IDEA可以使用快捷键添加行注释Ctrl+/.块注释Ctrl+Shift+/,还可以快速生成类注释.方法注释等,下面就介绍这几种快捷键的用法
- Office系列(2)---提取Office文件(Word、PPT)中的所有图片
回顾一下上文结尾的问题:如何给文档设置一个合适的封面图?其中一个解决方案就是,获取Office文件内部的图片作为封面.这里就详细介绍下获取图片的几种方式,以及他们各自的优缺点. PS:因为之前用VST ...
- SpringMvc简单使用
SpringMvc框架的简单使用 第一步:导入依赖 <dependencies> <dependency> <groupId>org.springframework ...
- pip install 清华源加速
经常要通过pip install安装需要的包,但是每当下载的文件比较大时,网速不够快,会导致报错.所以采用清华源来加速 清华大学开源软件镜像站 https://mirrors.tuna.tsinghu ...
- 使用doxygen
Getting started with Doxygen 可执行文件doxygen是解析源文件并生成文档的主程序. 另外, 也可以使用可执行文件doxywizard, 是用于编辑配置文件, 以及在图形 ...
- [HNOI2008]Cards(dp,Burnside引理)
Burnside引理: 参考自 某大佬对Burnside引理和Polya定理的讲解 相关概念 群:在数学中,群表示一个拥有满足封闭性.满足结合律.有单位元.有逆元的二元运算的代数结构. 置换群:由有限 ...
- [Java] The imoprt XXX cannot be resolved
不知道为什么突然报错,但是可以成功编译. 通过import一个未使用的包来消除error,猜测是插件的问题,具体原因未知. import 未使用的包后,error消失.
- Educational Codeforces Round 80 (Rated for Div. 2)部分题解
A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题 ...