How To Write Shared Libraries(1)

翻译:https://akkadia.org/drepper/dsohowto.pdf

Abstract

Today, shared libraries are ubiquitous. Developers use them for multiple reasons and create them just as they would create application code. This is a problem, though, since on many platforms some additional techniques must be applied even to generate decent code. Even more knowledge is needed to generate optimized code. This paper introduces the required rules and techniques. In addition, it introduces the concept of ABI (Application Binary Interface) stability and shows how to manage it.
当前,共享链接库是普及的。开发者们出于各种原因像创建程序一样频繁创建使用它们。这就带来一个问题,在许多平台上想要正确生成需要的代码需要一些额外的技术。更多的用于生成优化代码。本文介绍需要的规则和技术。另外,介绍ABI稳定性相关内容,同时分析如何管理它。

1 Preface

For a long time, programmers collected commonly used code in libraries so that code could be reused. This saves development time and reduces errors since reused code only has to be debugged once.
With systems running dozens or hundreds of processes at the same time reuse of the code at link-time solves only part of the problem. Many processes will use the same pieces of code which they import for libraries. With the memory management systems in modern operating systems it is also possible to share the code at run-time. This is done by loading the code into physical memory only once and reusing it in multiple processes via virtual memory. Libraries of this kind are called shared libraries.
很长一段时间里,开发者们收集通用的代码到链接库中,这样方便重用。
这样减少开发时间减少错误情况,代码只需要调试一次。
系统同时运行几十上百次共享的功能代码,只需要链接时初一部分问题。
许多进程使用相同的代码块到自己的进程中。
在系统的内存管理中这部分内存也是可以共享的。
这通过加载一次物理内存,通过虚拟地址到不同进程的方式实现。
这种库叫作共享库。

The concept is not very new. Operating system designers implemented extensions to their system using the infras- tructure they used before. The extension to the OS could be done transparently for the user. But the parts the user directly has to deal with created initially problems.
这不是新技术。操作系统设计者使用之前使用的功能实现该扩展。
这个扩展可以为了用户转换一些格式。
但是用户必须处理创建和初始化的问题。

The main aspect is the binary format. This is the for- mat which is used to describe the application code. Long gone are the days that it was sufficient to provide a mem- ory dump. Multi-process systems need to identify differ- ent parts of the file containing the program such as the text, data, and debug information parts. For this, binary formats were introduced early on. Commonly used in the early Unix-days were formats such as a.out or COFF. These binary formats were not designed with shared li- braries in mind and this clearly shows.
主要问题就是二进制格式。
这是用于描述程序的内容。
很长时间里这足够用于内存dump的操作。
多进程的系统需要标记程序的不同部分,例如代码段、数据段、调试信息段。
因此,二进制格式很早就实现。
常用的是类unix的a.out或者COFF。
但这个格式很清楚不是设计用来实现共享库的。

你可能感兴趣的:(How To Write Shared Libraries(1))