如何main()函数的共享对象(的.so)内部通过连接照顾 [英] How main() function inside a shared object (.so) is taken care of by linker

查看:125
本文介绍了如何main()函数的共享对象(的.so)内部通过连接照顾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有没有主要(source.o)对象文件的,也是我有一个主要功能(libmain.so)的共享对象。

Suppose I have an object file without main (source.o), and also I have a shared object with a main function (libmain.so).

如何当两个动态链接到创建source.bin二进制链接会照顾切入点?

How Linker will take care of the entry point when both are linked dynamically to create a source.bin binary ?

推荐答案

只要你有一个动态链接程序,有几个切入点参与。首先是动态连接器本身的切入点,如 /lib/ld-linux.so.2 (在Linux / x86平台)或类似。动态链接程序第一次运行,解决所有的符号名称及其定义(无论该定义是否在主程序或库),然后通过执行在主程序二进制第二个切入点。这不是但C运行时(因此 crt.o 及类似名称)的一部分需要照顾一些pre的 - 的东西(如C ++构建函数,指针设置环境变量,构建正确的论据)。这code。与(相当于)退出结束(主(ARGC,ARGV)); 这将同时使用的重新定位(由动态链接程序)地址退出

Whenever you have a dynamic linked program, there are several "entry points" involved. The first is in entry point of the dynamic linker itself, e.g. /lib/ld-linux.so.2 (on Linux/x86) or similar. The dynamic linker runs first, resolving all symbol names to their definitions (regardless of whether the definitions are in the main program or a library), then passes execution to the second entry point in the main program binary. This is not main but part of the "C runtime" (thus crt.o and similar names) that takes care of some pre-main stuff (like C++ ctors, setting up the pointer to the environment variables, and constructing the right arguments for main). This code ends with (the equivalent of) exit(main(argc, argv)); which will use the relocated (by the dynamic linker) addresses of both exit and main.

这篇关于如何main()函数的共享对象(的.so)内部通过连接照顾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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