当前位置:网站首页>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.
边栏推荐
猜你喜欢
This Thursday evening at 19:00, the fourth live broadcast of knowledge empowerment丨The realization of equipment control of OpenHarmony smart home project
The video of machine learning to learn [update]
leetcode 12. 整数转罗马数字
2003. 每棵子树内缺失的最小基因值 DFS
manipulation of file contents
Basic characteristics of TL431 and oscillator circuit
企业直播风起:目睹聚焦产品,微赞拥抱生态
Oracle与Postgresql在PLSQL内事务回滚的重大差异
将xml标签转换为txt(voc格式转换为yolo方便进行训练)
七夕节,我用代码制作了表白信封
随机推荐
Embedded database development programming MySQL (full)
42. 接雨水
7-3 LVS+Keepalived Cluster Description and Deployment
Take care of JVM performance optimization (own note version)
2003. 每棵子树内缺失的最小基因值 DFS
2022 software test interview questions The latest ByteDance 50 real interview questions, 15k have been won after brushing, with explanation + Q&A
Implementing a server-side message active push solution based on SSE
2023年PMP考试会用新版教材吗?回复来了!
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
centos 安装postgresql13 指定版本
将xml标签转换为txt(voc格式转换为yolo方便进行训练)
PHP高级开发案例(1):使用MYSQL语句跨表查询无法导出全部记录的解决方案
八年软件测试工程师带你了解-测试岗进阶之路
manipulation of file contents
2.15 keil使用电脑端时间日期
解决问题遇到的问题
企业直播风起:目睹聚焦产品,微赞拥抱生态
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.4 使声明与定义相匹配
结构体指针知识要点总结
大型连锁百货运维审计用什么软件好?有哪些功能?