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

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

问题描述

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

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,并有一个测试应用程序在2之间切换并进行一些测试。

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天全站免登陆