当前位置:网站首页>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.
边栏推荐
- JVM的内存模型简介
- C专家编程 第5章 对链接的思考 5.3 函数库链接的5个特殊秘密
- 看DevExpress丰富图表样式,如何为基金公司业务创新赋能
- 7-1 LVS+NAT load balancing cluster, NAT mode deployment
- Mini program + e-commerce, fun new retail
- 【21天学习挑战赛】直接插入排序
- 如何动态添加script依赖的脚本
- Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
- 八年软件测试工程师带你了解-测试岗进阶之路
- Eight guiding principles to help businesses achieve digital transformation success
猜你喜欢
随机推荐
See how DevExpress enriches chart styles and how it empowers fund companies to innovate their business
【一步到位】Jenkins的安装、部署、启动(完整教程)
7-2 LVS+DR概述与部署
【21天学习挑战赛】顺序查找
基于 SSE 实现服务端消息主动推送解决方案
小程序 + 电商,玩转新零售
mq应用场景介绍
This Thursday evening at 19:00, the fourth live broadcast of knowledge empowerment丨The realization of equipment control of OpenHarmony smart home project
详解八大排序
某母婴小程序加密参数解密
How class only static allocation and dynamic allocation
Use serve to build a local server
OpenGL绘制圆
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.3 什么是声明,什么是定义
类如何只能静态分配和只能动态分配
7-3 LVS+Keepalived Cluster Description and Deployment
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.2 我的代码为什么无法运行
How to dynamically add script dependent scripts
8.Haproxy 搭建Web集群
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.4 使声明与定义相匹配









