当前位置:网站首页>C Expert Programming Chapter 5 Thinking about Linking 5.1 Libraries, Linking and Loading
C Expert Programming Chapter 5 Thinking about Linking 5.1 Libraries, Linking and Loading
2022-08-04 04:45:00 【weixin_Guest time】
Linker basics: The compiler creates an output file that contains relocatable objects.These objects are the data and machine instructions corresponding to the source program.
The linker is at that stage of the compilation process
The complex form of linking in SRV4 systems.
C preprocessor ---> (stage p) front end (syntax and semantic analysis) ---> (stage o) back end (code generator) --->
(stage c)Optimizer---->(Phase 2) Assembler---->(Phase a) Linker-Loader
Most compilers are not a single monolithic program.They usually consist of as many as six or seven smaller programs called by a control program called a "compiler driver".These separate programs that are easily separated from the compiler include the preprocessor, the syntactic and semantic checker, the code generator, the assembler, and the optimizer., the linker, and of course a driver program that calls all of these programs and passes the correct options to each program.The optimizer can add almost all the stages above.Current SPARC performs most of the optimizations at the intermediate presentation layer between the front-end and back-end of the compiler.
Separate programs are easier to design and maintain.
The rules governing the preprocessing process are unique to the preprocessing phase and have little in common with the rest of the C language.
The C preprocessor is often (but not always) a standalone program.If the code generator (aka "backend") is written
as a separate program, it is likely to be shared by other languages.The tradeoff for this design approach is that running several smaller programs
takes longer than running one large program (because of the overhead of the initialization process and passing information between stages).
The -# option looks at the individual stages of the compilation process.The -V option provides version information.
Pass option information to the various stages by giving the compiler driver a special -W option (meaning to pass this option to which stage).
"W" followed by a character (prompting that stage), a comma, and then the specific option.
Any option passed by the compiler driver to the linker must be prefixed with -W1 before the specific option to tell the compiler driver that this option is intended to be passed to the linker.
cc -W1, -m main.c > main.linker.map
Pass the -m option to the linker-loader, asking it to generate a linker image.
The object file cannot be executed directly, it first needs to be loaded into the linker.Linking confirms that the main function is the initial entry point (where program execution begins), binds symbolic references to memory addresses, lumps all object files together, and adds library files to produce an executable file.
PC's linking mechanisms are vastly different from those of larger systems.The linker of a PC generally provides only a few basic I/O services, a program called the BIOS.They exist in fixed locations in memory and are not part of every executable.If the PC program or program suite requires more advanced services, it can be provided through library functions, but the compiler must link the library functions into each executable file.
In MS-DOS, there is no way to deduce which of the programs the library is commonly used for, and thus install it only once on the PC.
UNIX systems used to be the same.When the program is linked, a copy of each library function that needs to be used is added to the executable.
In recent years, a more modern and superior method called dynamic linking has been adopted.
Dynamic linking allows the system to provide a huge set of function libraries that can provide many useful services.However, the program will look for them at runtime, rather than having the binary code of these libraries as part of its own executable.
If a copy of the library is a physical part of the executable, then we call it static linking: if the executable just contains the filename, it allows the loader to find what the program needs at runtimefunction library, then we call it dynamic linking.
The canonical names for the three phases that the collection module prepares to execute are link-editing, loading, and runtime linking.Statically linked modules are link-edited and loaded to run.Dynamically linked modules are link-edited, loaded, and linked at runtime to run.During program execution, before the main() function is called, the runtime loader loads the shared data object into the process's address space.The runtime loader does not resolve external functions until they are actually called.Therefore, the function library is linked, and if it is not actually called, it will not bring additional overhead.
Even in static linking, the entire libc.a file is not loaded into the executable, only the required functions are loaded.
边栏推荐
猜你喜欢

附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;

Postgresql source code (66) insert on conflict grammar introduction and kernel execution process analysis

文件内容的操作

el-Select 选择器 底部固定

Explain详解与实践

7-1 LVS+NAT load balancing cluster, NAT mode deployment
![[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]](/img/f7/78eea9f14ca97b5e78592c7c2be313.png)
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]

结构体函数练习

Tensors - Application Cases

8.Haproxy 搭建Web集群
随机推荐
DataTable使用Linq进行分组汇总,将Linq结果集转化为DataTable
Hangdian Multi-School-Slipper- (tree map conversion + virtual point mapping)
商城App开发都有哪些功能呢
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
烧录场景下开发如何进行源代码保密工作
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.4 使声明与定义相匹配
图像处理之Bolb分析(一)
How to simplify the automation of modern e-procurement?
文件系统的简单操作
Embedded database development programming MySQL (full)
【21天学习挑战赛】顺序查找
中信证券网上开户怎么开的?安全吗?
Mobile payment online and offline payment scenarios
备份工具pg_dump的使用《postgres》
【一步到位】Jenkins的安装、部署、启动(完整教程)
路网编辑器技术预研
[21 Days Learning Challenge] Image rotation problem (two-dimensional array)
结构体函数练习
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.3 什么是声明,什么是定义
张量篇-应用案例