加载时动态链接和运行时动态链接之间的区别 [英] Difference between load-time dynamic linking and run-time dynamic linking

查看:20
本文介绍了加载时动态链接和运行时动态链接之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将程序加载到内存时,加载时动态链接和运行时动态链接有什么区别?

When loading programs into memory, what is the difference between load-time dynamic linking and run-time dynamic linking?

推荐答案

加载时链接是指可执行文件(或其他库)引用的库中的符号在可执行文件/库加载到内存时被处理,通过操作系统.

load-time linking is when symbols in the library, referenced by the executable (or another library) are handled when the executable/library is loaded into memory, by the operating system.

运行时链接是当您使用操作系统提供的 API 或通过库在需要时加载 DLL 或 DSO,然后执行符号解析.

Run-time linking is when you use an API provided by the OS or through a library to load a DLL or DSO when you need it, and perform the symbol resolution then.

我比 Windows DLL 更了解 Linux DSO,但原理应该是相同的..NET 库可能会有所不同.

I know more about Linux DSOs than Windows DLL's but the principle should be the same. .NET libraries may differ.

在 linux 中,插件架构是这样完成的.您的程序将使用运行时链接来加载库并调用一些函数.然后也许卸载它.它还允许加载具有相同符号的多个库而不会发生冲突.我认为 DLL 将以几乎相同的方式工作.

In linux, plugin architectures are done this way. Your program will use runtime linking to load up a library and call some functions. Then maybe unload it. It also allows multiple libraries with the same symbols exported to be loaded without clashing. I think DLLs will work in much the same manner.

可执行文件的符号表中有空格",需要一些库来填充.这些空格通常在加载时或编译时填充.您可以使用运行时链接来消除符号表中对空格"的需求.

Executables have "blank spaces" in their symbol tables that need filling by some library. These blank-spaces are usually filled in at load-time, or compile time. You can negate the need for "blank spaces" in the symbol table by using runtime linking.

运行时链接有用的另一个场景是调试库,或在运行时从多个 ABI/API 兼容库中进行选择.我经常有一个库,比如foo"和一个名为foo_unstable"的库,并且有一个测试应用程序可以在两者之间切换并进行一些测试.

Another scenario where runtime linking is useful is for debugging libraries, or selecting from multiple, ABI/API compatible libraries at runtime. I often have a library, say "foo" and one called "foo_unstable" and have a test app that switches between the 2 and does some testing.

在 linux 下,要查看可执行文件在加载时链接到哪些库,请运行 ldd 命令并获取输出,例如 (on/bin/ls):

Under linux, to see what libraries an executable links to at load-time you run the ldd command and get output such as (on /bin/ls):

linux-vdso.so.1 =>  (0x00007fff139ff000)
librt.so.1 => /lib64/librt.so.1 (0x0000003c4f200000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003c4fa00000)
libcap.so.2 => /lib64/libcap.so.2 (0x0000003c53a00000)
libacl.so.1 => /lib64/libacl.so.1 (0x0000003c58e0000

操作系统将在加载时尝试加载库(.so 文件).它可能已经在内存中拥有该库.

The operating system will attempt to load the libraries (the .so files) at load-time. It may already have the library in memory.

这篇关于加载时动态链接和运行时动态链接之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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