将动态链接的可执行文件与ld链接 [英] Linking a dynamically linked executable with ld

查看:262
本文介绍了将动态链接的可执行文件与ld链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建没有gcc的动态链接的可执行文件(elf_i386).该程序非常简单(只有一个printf)...这里的命令:

i'm trying to create a dynamically linked executable (elf_i386) without gcc. The program is very simple (only a printf)...here the commands:

$ gcc -c simple.c
$ ld -o simple -dynamic-linker /lib/ld-linux.so.2 --entry main /usr/lib/crt1.o /usr/lib/crti.o simple.o -lc /usr/lib/crtn.o

创建可执行文件,并且文件命令和ldd命令显示正确的输出... 但是,当我在调用printf之后启动程序时,出现了分段错误...我已经用objdump检查了可执行文件,并且我认为问题出在dtor上...好像是在编译:

The executable is created and also file command and ldd command show the right output... However when i launch the program after the call to printf i get a segmentation fault...i've examined with objdump the executable and i think the problem is about the dtors...seems that compiling with:

$gcc -o simple simple.c

.dtors节存在,而ld:(

a section .dtors is present while it is not present inside the executable created directly with ld :(

有什么想法吗?

推荐答案

丢掉--entry main. main不是您的入口点,_start是.试试这个:

Lose the --entry main. main isn't your entry point, _start is. Try this:

$ gcc -c hello.c
$ ld -o hello -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o hello.o -lc /usr/lib/crtn.o
$ ./hello
hello, world
$ 

这篇关于将动态链接的可执行文件与ld链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆