Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3846210
  • 博文数量: 146
  • 博客积分: 3918
  • 博客等级: 少校
  • 技术积分: 8584
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-17 13:52
个人简介

个人微薄: weibo.com/manuscola

文章分类

全部博文(146)

文章存档

2016年(3)

2015年(2)

2014年(5)

2013年(42)

2012年(31)

2011年(58)

2010年(5)

分类:

2010-10-20 21:01:52

ELF 四种文件类型


1可重定位文件 -------relocatable file Linux 中的*.o文件

2 可执行文件 -------Executable File

3共享目标文件 --------Share object File Linux 中的*.so文件

4核心转储文件 ———Core Dump File core dump


linux下可以用file命令查看文件格式


下面是我的hello.c文件

1 #include

2 #include

3 #include

4

5 int main()

6 {

7       int i;

8         printf("hello world !\n");

9         i = 10;

10       printf("i = %d\n",i);

11       float j;

12       j = sin(i);

13

14       printf("j = %f\n",j);

15       i*=2;

16       printf("i = %d\n", i);

17

18       return 0;

19   }


root@libin:~/project# file hello.c

hello.c: ASCII C program text


root@libin:~/project# gcc -c hello.c

生成了hello.o文件


root@libin:~/project# file hello.o

hello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped


stripped是不太好理解的地方,一些调试信息会在*.o文件中,not stripped表示没有取出调试信息。LINUX中有strip命令可以去除掉相应的调试信息。

root@libin:~/project# ll hello.o

-rw-r--r-- 1 root root 1056 2010-10-20 20:55 hello.o

root@libin:~/project# strip hello.o

root@libin:~/project# ll hello.o

-rw-r--r-- 1 root root 664 2010-10-20 20:55 hello.o

root@libin:~/project# file hello.o

hello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), stripped


我们 发现用strip命令取出掉调试信息,文件大小从1056----->664

经典著作 linker & loader中这样描述


在构建过程中将所有调试信息都放到输出文件中的做法有一个显而易见的好处,就是

调试程序所需要的信息都存放在一个地方。明显的缺点就是这将导致可执行程序体积非常庞

大。同样如果调试信息被分离出去,就很容易构建最终版本的程序,然后出售没有调试信息

的可执行程序。这会减小发布程序的大小并增加逆向工程的难度,但开发者还拥有在调试已

发货软件错误时会用到的调试文件。UNIX 系统有一个 strip 命令,可以将调试符号从一个目

标文件中去除而不改变任何代码。开发者可以保存未 strip 的文件并发布 strip 过的版本。

即使这种情况下两个文件是不同的,但运行代码是一样的,并且调试器可以通过未进行 str

ip 的文件中符号来调试 strip 过版本生成的核心转储(core dump)文件。


阅读(3243) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2010-10-21 10:03:51

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com