关于地址绑定的问题

发布于 2025-01-19 14:10:53 字数 297 浏览 1 评论 0原文

存在三种不同的地址绑定技术:

编译时绑定 加载时间绑定 运行时绑定

我有很多关于它们的问题: 1-根据我的理解,每个操作系统都使用某种地址绑定技术来实现。现代操作系统使用运行时绑定,MS-DOS 使用编译时绑定。是这样吗?或者程序员可以选择使用哪个地址绑定?

2- 如果编译器事先知道程序将驻留在主内存中的位置,则在编译时使用绑定。编译器如何知道这个未来的信息?是程序员给的吗?

3-如果程序在执行期间总是改变其位置,则使用运行时绑定。例如,交换和分段压缩是程序在执行过程中改变其位置的例子,还是它们在这里是不同的概念?

There are three different address binding techniques :

Compile time binding
Load time binding
Run time binding

I have many questions regarding them :
1- According to my understanding, every OS uses a certain address binding technique to implement. Modern OSes uses run time binding and MS-DOS uses Compile time binding. Is that right ? Or the programmer can select which address binding to use ?

2- At compile time binding is used if the compiler knows in advance where the program will resides in main memory. How do the compiler know this future information ? Is it given by the programmer ?

3- Run time binding is used if the program will always change his location during execution time . Is for example swapping and segmentation compaction are examples why the programs will change their location during execution , or they are different concepts here ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2025-01-26 14:10:53

1-根据我的理解,每个操作系统都使用某种地址绑定技术来实施。现代OS使用运行时间绑定,MS-DOS使用编译时间绑定。那对吗?或程序员可以选择要使用的地址绑定?

实际上,即使是最新的操作系统也使用所有绑定/链接类型。这并不是真正的操作系统问题,但主要是用户模式实现的问题。主要是程序员,将决定使用哪种链接类型,但不是明确的选择。它是由程序员通过高级代码编程的方式隐式选择的。例如,如果程序员决定在C ++中使用虚拟功能,则将根据引用的对象的类型而不是参考的类型确定要跳到的地址。有关链接以及如何编写更有效的代码并了解您在做什么,它是有用的/建议的。

2-在编译时间绑定时,如果编译器事先知道程序将位于主内存中的位置。编译器如何知道未来的信息?它是由程序员给出的吗?

这很复杂,对此有很多话要说。今天,您的分页始终正在使用。程序可以访问整个地址空间。这意味着编译器不必太在乎可执行的位置。它主要关心起始地址,其余的是独立或绝对的位置。位置独立代码甚至不太关心起始地址。起始地址主要提供了找到_start符号的位置,仅此而已。该代码的其余部分将使用相对跳跃到文本段中的某个位置,并使用RIP相关地址来访问全局/静态数据。

该程序将居住的位置并不多。该功能是否存在并在您自己的代码中或另一个库中实现。如果在另一个库中存在一个函数,则编译器将在可执行文件中留下未解决的符号,以便在执行前链接器解决。这称为动态链接负载时间绑定的示例。动态链接器会发现动态库,并将其放在RAM中。动态链接器将解决跳转以达到该功能的位置。

3-如果程序在执行时间内始终更改其位置,则使用运行时间绑定。例如,交换和分割压实是示例为什么程序在执行过程中会更改其位置,否则它们在这里是不同的概念?

没有“总是会改变他的位置的程序”。运行时绑定主要存在于C ++中,只是虚拟函数的问题。除虚拟功能外,所有链接均在编译时或加载时间进行。虚拟函数允许通过确定引用的对象的类型而不是使用引用本身的类型来调用对象中的函数。这用于提供多态性,因为相同的函数签名可以具有多个实现,并且将根据引用的对象的类型确定一个实现。 (有关更多信息,请参见: https:https:// cs。 stackexchange.com/questions/145444/what-attributes-are-bound-statationally-vs-dynamily/145470#145470

1- According to my understanding, every OS uses a certain address binding technique to implement. Modern OSes uses run time binding and MS-DOS uses Compile time binding. Is that right ? Or the programmer can select which address binding to use ?

Actually, even the most recent OS uses all the binding/linking types. It isn't really a matter of the OS but mostly a matter of user mode implementation. It is mostly the programmer which will decide which linking type to use but it isn't an explicit choice. It is chosen by the programmer implicitly by the way it programs in high level code. For example, if the programmer decides to use virtual functions in C++ then the address to jump to will be determined at runtime based on the type of the object referenced instead of the type of the reference. It is useful/recommended to know about linking and how it works to write more efficient code and to know what you are doing.

2- At compile time binding is used if the compiler knows in advance where the program will resides in main memory. How do the compiler know this future information ? Is it given by the programmer ?

It is quite complex and there is a lot to say about that. Today, you have paging that is always in use. A program has access to the whole address space. This means that a compiler doesn't have to care much about the position of an executable. It cares mostly about the start address and the rest is position independent or absolute. Position independent code doesn't even care all that much about the start address. The start address mostly provides a position to find the _start symbol but that's it. The rest of the code is using relative jumps to some position in the text segment and RIP-relative addressing to access global/static data.

It isn't that much about where the program will reside. It is a matter of if the function is present and implemented within your own code or in another library. If a function is present in another library, then the compiler will leave an unresolved symbol in the executable for the linker to resolve before execution. This is called dynamic linking an example of load time binding. The dynamic linker will find that dynamic library and place it somewhere in RAM. The dynamic linker will resolve where to jump to get to that function.

3- Run time binding is used if the program will always change his location during execution time . Is for example swapping and segmentation compaction are examples why the programs will change their location during execution , or they are different concepts here ?

There is no "program that will always change his location". Run-time binding is mostly present in C++ and is only a matter of virtual functions. All linking is done at compile time or at load time except for virtual functions. Virtual functions allow to call a function in an object by determining the type of the object referenced instead of using the type of the reference itself. This is used to provide polymorphism because the same function signature can have several implementations and which one to call will be determined based on the type of the object referenced. (For more info see: https://cs.stackexchange.com/questions/145444/what-attributes-are-bound-statically-vs-dynamically/145470#145470)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文