Prayer

在一般中寻求卓越
posts - 1256, comments - 190, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理
https://blog.csdn.net/giantpoplar/article/details/46485649


首先,原文地址如下:

http://www.quora.com/Systems-Programming/What-is-the-exact-difference-between-Dynamic-loading-and-dynamic-linking

翻译内容如下:

动态装入(Dynamic loading) 指的是当一个进程启动后,将一个可执行的文件(原文是executable,我理解为磁盘上的文件 或者驻留在内存中的例程)或库映射到(或者不常发生的复制)到进程内存空间。动态链接 (dynamic linking)指的是在编译(汇编)之后,分解字符(resolving symbols)——把名字和地址或者偏移量联系起来。这两者难以区分的原因是,大约在进程启动后,编译(汇编)之后这两个过程,通常对二者的微妙区别不加区分地一起完成。大概最清晰的方式来解释这二者的区别就是分别展示二者的各种组合在实践中意味着什么。

动态装入,静态链接。

可执行的文件拥有一个在编译时生成的 地址/偏移量表,但是实际的代码/数据在进程刚启动时没有装到内存中。这并不是大多数现在的操作系统的处理方式,但是它可能描述了一些老式的overlay systems.如果现在的嵌入式系统也使用这种方式,我一点也不感觉到奇怪。无论是哪种情况,其目的都是给予程序员内存控制的自由同时避免运行时的链接花费。

静态装入,动态链接

这通常是在编译时确定动态库的工作方式。可执行文件包含动态/共享库的引用,但是字符表(symbol table)没有或者不完整。装入和链接都在进程启动时进行,被认为是“动态的”链接但不是“动态的”装入。

动态装入,动态链接

这是你调用dlopen或其他系统里的等价调用的时候发生的事情。object(.obj)文件在程序的控制下动态装入(也就是开始之后),包括调用程序和库里的字符都根据那个时刻进程的可能独一无二的内存布局进行解析(把名字和地址/偏移量联系起来).

静态装入,静态链接

所有的东西都在编译时解析完成。进程开始的时候所有东西都立即加载到内存中,不需要其他的解析(链接linking)。概括地说,加载发生自单个文件是不必要的,但是我认为实际的格式或者实现并不能够在不使用动态链接的情况下实现多文件的装入。


原文内容如下

Dynamic loading refers to mapping (or less often copying) an executable or library into a process's memory after is has started.  Dynamic linking refers to resolving symbols - associating their names with addresses or offsets - after compile time.  The reason it's hard to make a distinction is that the two are often done together without recognizing the subtle distinctions around the parts I put in bold.  Perhaps the clearest way to explain is to go through what the different combinations would mean in practice.

  • Dynamic loading, static linking.  The executable has an address/offset table generated at compile time, but the actual code/data aren't loaded into memory at process start.  This is not the way things tend to work in most systems nowadays, but it would describe some old-fashioned overlay systems.  I'd also be utterly unsurprised if some current embedded systems work this way too.  In either case, the goal is to give the programmer control over memory use while also avoiding the overhead of linking at runtime.
  • Static loading, dynamic linking.  This is how dynamic libraries specified at compile time usually work.  The executable contains a reference to the dynamic/shared library, but the symbol table is missing or incomplete.  Both loading and linking occur at process start, which is considered "dynamic" for linking but not for loading.
  • Dynamic loading, dynamic linking.  This is what happens when you calldlopen or its equivalent on other systems.  The object file is loaded dynamically under program control (i.e. after start), and symbols both in the calling program and in the library are resolved based on the process's possibly-unique memory layout at that time.
  • Static loading, static linking.  Everything is resolved at compile time.  At process start everything is loaded into memory immediately and no extra resolution (linking) is necessary.  In the abstract it's not necessary for the loading to occur from a single file, but I don't think the actual formats or implementations (at least those I'm familiar with) can do multi-file loading without dynamic linking.

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理