当前位置:网站首页>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.
边栏推荐
- 【21 Days Learning Challenge】Direct Insertion Sort
- Introduction to the memory model of the JVM
- day13--postman接口测试
- 7-3 LVS+Keepalived集群叙述与部署
- 商城系统APP如何开发 都有哪些步骤
- Implementing a server-side message active push solution based on SSE
- 7.LVS负载均衡群集之原理叙述
- For Qixi Festival, I made a confession envelope with code
- 八年软件测试工程师带你了解-测试岗进阶之路
- 【C语言进阶】程序环境和预处理
猜你喜欢
随机推荐
杭电多校-Slipper-(树图转化+虚点建图)
Stop behind.
【21天学习挑战赛】直接插入排序
centos 安装postgresql13 指定版本
The video of machine learning to learn [update]
Converts XML tags to TXT format (voc conversion for yolo convenient training)
八年软件测试工程师带你了解-测试岗进阶之路
解决问题遇到的问题
SQL interview Questions
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
技术解析|如何将 Pulsar 数据快速且无缝接入 Apache Doris
拿捏JVM性能优化(自己笔记版本)
2023年PMP考试会用新版教材吗?回复来了!
数据治理平台项目总结和分析
JVM Notes
Cache pool of unity framework
10 Convolutional Neural Networks for Deep Learning 3
XSS related knowledge points
There is an 8 hour difference between the docker installation of mysql and the host.
PHP高级开发案例(1):使用MYSQL语句跨表查询无法导出全部记录的解决方案



![[21 Days Learning Challenge] Image rotation problem (two-dimensional array)](/img/51/fb78f36c71e1eaac665ce9f1ce04ea.png)





