侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Linux下查看.so和可执行文件是否debug编译的方法(必看)

linux  /  管理员 发布于 7年前   374

今天同事问我,如何判断一个.so是否是debug编译的。

我记得以前自己是用file来查看一个.so,根据是否包含"not stripped"来判断该.so是否是debug编译的,于是就没做实验就回答。

然而,stripped/not stripped并不是debug/release编译的判断标准. 我对debug和release的.so运行file后,得出几乎相同的输出, 都是not stripped. 所以我算是误导同事了。

根据<Computers Systems - A Programmer's Perspective>所言, debug/release的区别更多的表现在.so和可执行程序所拥有的段上。debug编译出来的。so和可执行程序拥有很多附加的段来包含哪些debug的信息。 所以查看段信息是一种判断的方式。

我在Ubuntu 11.04上分别对同一个开源软件进行debug和release编译,并且查看某个.so的段(readelf -S),发现release编译的只有29个段:

There are 29 section headers, starting at offset 0x1b7d78:Section Headers:[Nr] Name Type Address OffsetSize EntSize Flags Link Info Align[ 0] NULL 0000000000000000 000000000000000000000000 0000000000000000 0 0 0[ 1] .note.gnu.build-i NOTE 00000000000001c8 000001c80000000000000024 0000000000000000 A 0 0 4[ 2] .gnu.hash GNU_HASH 00000000000001f0 000001f00000000000003430 0000000000000000 A 3 0 8[ 3] .dynsym DYNSYM 0000000000003620 00003620000000000000b400 0000000000000018 A 4 2 8[ 4] .dynstr STRTAB 000000000000ea20 0000ea2000000000000083e2 0000000000000000 A 0 0 1[ 5] .gnu.version VERSYM 0000000000016e02 00016e020000000000000f00 0000000000000002 A 3 0 2[ 6] .gnu.version_r VERNEED 0000000000017d08 00017d080000000000000080 0000000000000000 A 4 2 8[ 7] .rela.dyn RELA 0000000000017d88 00017d880000000000009570 0000000000000018 A 3 0 8[ 8] .rela.plt RELA 00000000000212f8 000212f800000000000080d0 0000000000000018 A 3 10 8[ 9] .init PROGBITS 00000000000293c8 000293c80000000000000018 0000000000000000 AX 0 0 4[10] .plt PROGBITS 00000000000293e0 000293e000000000000055f0 0000000000000010 AX 0 0 4[11] .text PROGBITS 000000000002e9d0 0002e9d00000000000144658 0000000000000000 AX 0 0 16[12] .fini PROGBITS 0000000000173028 00173028000000000000000e 0000000000000000 AX 0 0 4[13] .rodata PROGBITS 0000000000173040 00173040000000000001e9a0 0000000000000000 A 0 0 32[14] .eh_frame_hdr PROGBITS 00000000001919e0 001919e0000000000000427c 0000000000000000 A 0 0 4[15] .eh_frame PROGBITS 0000000000195c60 00195c600000000000017d7c 0000000000000000 A 0 0 8[16] .ctors PROGBITS 00000000003ae1e8 001ae1e80000000000000010 0000000000000000 WA 0 0 8[17] .dtors PROGBITS 00000000003ae1f8 001ae1f80000000000000010 0000000000000000 WA 0 0 8[18] .jcr PROGBITS 00000000003ae208 001ae2080000000000000008 0000000000000000 WA 0 0 8[19] .data.rel.ro PROGBITS 00000000003ae220 001ae2200000000000005b38 0000000000000000 WA 0 0 32[20] .dynamic DYNAMIC 00000000003b3d58 001b3d5800000000000001a0 0000000000000010 WA 4 0 8[21] .got PROGBITS 00000000003b3ef8 001b3ef800000000000010e8 0000000000000008 WA 0 0 8[22] .got.plt PROGBITS 00000000003b4fe8 001b4fe80000000000002b08 0000000000000008 WA 0 0 8[23] .data PROGBITS 00000000003b7b00 001b7b000000000000000158 0000000000000000 WA 0 0 32[24] .bss NOBITS 00000000003b7c58 001b7c580000000000000010 0000000000000000 WA 0 0 8[25] .comment PROGBITS 0000000000000000 001b7c58000000000000002a 0000000000000001 MS 0 0 1[26] .shstrtab STRTAB 0000000000000000 001b7c8200000000000000f5 0000000000000000 0 0 1[27] .symtab SYMTAB 0000000000000000 001b84b8000000000000fdb0 0000000000000018 28 788 8[28] .strtab STRTAB 0000000000000000 001c8268000000000000b8b0 0000000000000000 0 0 1Key to Flags:W (write), A (alloc), X (execute), M (merge), S (strings), l (large)I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)O (extra OS processing required) o (OS specific), p (processor specific)

而debug编译的则有38个段, 且所有比release编译多出来的段,都是以.debug_作为开始字符串来命名的:

There are 38 section headers, starting at offset 0xdacc00:Section Headers:[Nr] Name Type Address OffsetSize EntSize Flags Link Info Align[ 0] NULL 0000000000000000 000000000000000000000000 0000000000000000 0 0 0[ 1] .note.gnu.build-i NOTE 00000000000001c8 000001c80000000000000024 0000000000000000 A 0 0 4[ 2] .gnu.hash GNU_HASH 00000000000001f0 000001f00000000000003620 0000000000000000 A 3 0 8[ 3] .dynsym DYNSYM 0000000000003810 00003810000000000000c000 0000000000000018 A 4 2 8[ 4] .dynstr STRTAB 000000000000f810 0000f8100000000000008ccb 0000000000000000 A 0 0 1[ 5] .gnu.version VERSYM 00000000000184dc 000184dc0000000000001000 0000000000000002 A 3 0 2[ 6] .gnu.version_r VERNEED 00000000000194e0 000194e00000000000000070 0000000000000000 A 4 2 8[ 7] .rela.dyn RELA 0000000000019550 000195500000000000009b40 0000000000000018 A 3 0 8[ 8] .rela.plt RELA 0000000000023090 000230900000000000008388 0000000000000018 A 3 10 8[ 9] .init PROGBITS 000000000002b418 0002b4180000000000000018 0000000000000000 AX 0 0 4[10] .plt PROGBITS 000000000002b430 0002b43000000000000057c0 0000000000000010 AX 0 0 4[11] .text PROGBITS 0000000000030bf0 00030bf000000000001d2428 0000000000000000 AX 0 0 16[12] .fini PROGBITS 0000000000203018 00203018000000000000000e 0000000000000000 AX 0 0 4[13] .rodata PROGBITS 0000000000203040 0020304000000000000276b8 0000000000000000 A 0 0 32[14] .eh_frame_hdr PROGBITS 000000000022a6f8 0022a6f800000000000059dc 0000000000000000 A 0 0 4[15] .eh_frame PROGBITS 00000000002300d8 002300d8000000000001715c 0000000000000000 A 0 0 8[16] .ctors PROGBITS 0000000000448018 002480180000000000000010 0000000000000000 WA 0 0 8[17] .dtors PROGBITS 0000000000448028 002480280000000000000010 0000000000000000 WA 0 0 8[18] .jcr PROGBITS 0000000000448038 002480380000000000000008 0000000000000000 WA 0 0 8[19] .data.rel.ro PROGBITS 0000000000448040 002480400000000000005b38 0000000000000000 WA 0 0 32[20] .dynamic DYNAMIC 000000000044db78 0024db7800000000000001a0 0000000000000010 WA 4 0 8[21] .got PROGBITS 000000000044dd18 0024dd1800000000000012d0 0000000000000008 WA 0 0 8[22] .got.plt PROGBITS 000000000044efe8 0024efe80000000000002bf0 0000000000000008 WA 0 0 8[23] .data PROGBITS 0000000000451be0 00251be00000000000000160 0000000000000000 WA 0 0 32[24] .bss NOBITS 0000000000451d40 00251d400000000000000040 0000000000000000 WA 0 0 16[25] .comment PROGBITS 0000000000000000 00251d400000000000000054 0000000000000001 MS 0 0 1[26] .debug_aranges PROGBITS 0000000000000000 00251d9400000000000030c0 0000000000000000 0 0 1[27] .debug_pubnames PROGBITS 0000000000000000 00254e54000000000000b8cb 0000000000000000 0 0 1[28] .debug_info PROGBITS 0000000000000000 0026071f000000000097f69b 0000000000000000 0 0 1[29] .debug_abbrev PROGBITS 0000000000000000 00bdfdba0000000000028211 0000000000000000 0 0 1[30] .debug_line PROGBITS 0000000000000000 00c07fcb0000000000075fbf 0000000000000000 0 0 1[31] .debug_str PROGBITS 0000000000000000 00c7df8a0000000000019789 0000000000000001 MS 0 0 1[32] .debug_loc PROGBITS 0000000000000000 00c977130000000000043528 0000000000000000 0 0 1[33] .debug_pubtypes PROGBITS 0000000000000000 00cdac3b00000000000d1c97 0000000000000000 0 0 1[34] .debug_ranges PROGBITS 0000000000000000 00dac8d200000000000001c0 0000000000000000 0 0 1[35] .shstrtab STRTAB 0000000000000000 00daca92000000000000016e 0000000000000000 0 0 1[36] .symtab SYMTAB 0000000000000000 00dad5800000000000014688 0000000000000018 37 1437 8[37] .strtab STRTAB 0000000000000000 00dc1c08000000000000e5a1 0000000000000000 0 0 1Key to Flags:W (write), A (alloc), X (execute), M (merge), S (strings), l (large)I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)O (extra OS processing required) o (OS specific), p (processor specific)

对于可执行文件也有类似的区别。

所以这应当是判断debug/release的一个比较正确的方法了。

===================================

命令

readelf -S libxxx.so |grep debug

以上这篇Linux下查看.so和可执行文件是否debug编译的方法(必看)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。


  • 上一条:
    linux下批量删除utf8 bom的实现方法
    下一条:
    判断Linux Shell环境变量是否存在
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客