Posted on 2018-11-28 15:42
Prayer 閱讀(2026)
評論(0) 編輯 收藏 引用 所屬分類:
LINUX/UNIX/AIX
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.