当前位置:网站首页>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.
边栏推荐
- 结构体函数练习
- Basic characteristics of TL431 and oscillator circuit
- Bolb analysis of image processing (1)
- SQL interview Questions
- 2022 software test interview questions The latest ByteDance 50 real interview questions, 15k have been won after brushing, with explanation + Q&A
- 软件测试如何系统规划学习呢?
- How to automatically export or capture abnormal login ip and logs in elastic to the database?
- 商城系统APP如何开发 都有哪些步骤
- 商城App开发都有哪些功能呢
- JVM笔记
猜你喜欢
For Qixi Festival, I made a confession envelope with code
There is an 8 hour difference between the docker installation of mysql and the host.
Implementing a server-side message active push solution based on SSE
Towards Real-Time Multi-Object Tracking(JDE)
企业直播风起:目睹聚焦产品,微赞拥抱生态
深度学习环境配置
7-3 LVS+Keepalived集群叙述与部署
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
系统设计.如何设计一个秒杀系统(完整版 转)
10 Convolutional Neural Networks for Deep Learning 3
随机推荐
软件测试如何系统规划学习呢?
结构体指针知识要点总结
解决问题遇到的问题
获取单选框选中内容
商城App开发都有哪些功能呢
7-2 LVS+DR概述与部署
商城系统APP如何开发 都有哪些步骤
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
8. Haproxy builds a web cluster
[C language advanced] program environment and preprocessing
Hangdian Multi-School-Slipper- (tree map conversion + virtual point mapping)
Introduction to mq application scenarios
7-1 LVS+NAT 负载均衡群集,NAT模式部署
劝退背后。
机器学习之视频学习【更新】
7-3 LVS+Keepalived Cluster Description and Deployment
Use serve to build a local server
JVM的内存模型简介
震惊,99.9% 的同学没有真正理解字符串的不可变性
mq应用场景介绍