去掉调试信息

go build -ldflags "-w"  

 

o链接器有一个标志-w,它禁用DWARF调试信息生成.您可以提供链接器标志来进行工具构建命令,如下所示:

go build -ldflags '-w'

Linux / Unix平台上的另一种方法是对编译的二进制文件使用命令条.这似乎产生比上述链接器选项更小的二进制文件

 

strip -s  /usr/bin/helloworld

 

 

$gcc -o a.out main.c

$nm a.out

查看ELF信息,利用readelf:

//读取ELF header

$readelf -Wh a.out

 

Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

 

Class: ELF32

 

Data: 2's complement, little endian

 

Version: 1 (current)

 

OS/ABI: UNIX - System V

 

ABI Version: 0

 

Type: EXEC (Executable file)

 

Machine: Intel 80386

 

Version: 0x1

 

Entry point address: 0x8048320

 

Start of program headers: 52 (bytes into file)

 

Start of section headers: 4436 (bytes into file)

 

Flags: 0x0

 

Size of this header: 52 (bytes)

 

Size of program headers: 32 (bytes)

 

Number of program headers: 9

 

Size of section headers: 40 (bytes)

 

Number of section headers: 30

 

Section header string table index: 27

 

 

//读取section header

$readelf -Ws a.out

 

//读取program header

$readelf -Wl a.out

 

利用objdump -s,查看elf section内容

$objdump -s a.out

利用gdb,也可以查看符号表

详见gdb手册。https://sourceware.org/gdb/current/onlinedocs/gdb/Symbols.html#Symbols
 

 

 

ELF 文件:

https://paper.seebug.org/papers/Archive/refs/elf/Understanding_ELF.pdf

 

转载摘录:

https://blog.csdn.net/zliangzliang/article/details/19439201


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部