Compiler Drivers+Static Linking
Compiler Drivers
Consider the C program in Figure 7.1. It consists of two source files, main.c and swap.c. Function main() calls swap, which swaps the two elements in the external global array buf. Granted, this is a strange way to swap two numbers, but it will serve as a small running example throughout this chapter that will allow us to make some important points about how linking works.
Most compilation systems provide a compiler driver that invokes the language preprocessor, compiler, assembler, and linker, as needed on behalf of the user. For example, to build the example program using the GNU compilation system, we might invoke the gcc driver by typing the following command to the shell:
unix> gcc -O2 -g -o p main.c swap.c
Figure 7.2 summarizes the activities of the driver as it translates the example program from an ASCII source file into an executable object file. (If you want to see these steps for yourself, run gcc with the -v option.)
- The driver first runs the C preprocessor (cpp), which translates the C source file main.c into an ASCII intermediate file main.i:
cpp [other arguments] main.c /tmp/main.i
- Next, the driver runs the C compiler (cc1), which translates main.i into an ASCII assembly language file main.s.
cc1 /tmp/main.i main.c -O2 [other arguments] -o /tmp/main.s
- Then, the driver runs the assembler (as), which translates main.s into a relocatable object file main.o:
as [other arguments] -o /tmp/main.o /tmp/main.s
- The driver goes through the same process to generate swap.o. Finally, it runs the linker program ld, which combines main.o and swap.o, along with the necessary system object files, to create the executable object file p:
ld -o p [system object files and args] /tmp/main.o /tmp/swap.o
- To run the executable p, we type its name on the Unix shell’s command line:
unix> ./p
The shell invokes a function in the operating system called the loader, which copies the code and data in the executable file p into memory, and then transfers control to the beginning of the program.
Static Linking
Static linkers such as the Unix ld program take as input a collection of relocatable object files and command-line arguments and generate as output a fully linked executable object file that can be loaded and run. The input relocatable object files consist of various code and data sections. Instructions are in one section, initialized global variables are in another section, and uninitialized variables are in yet another section.
相關文章
- Android resource linking failedAndroidAI
- Design Compiler(一)Compile
- HTML Compiler 2022HTMLCompile
- Compiler.phpCompilePHP
- COMPILER simplified C programminCompile
- Building OpenNI using a cross-compilerUIROSCompile
- Compiler Explorer(Godbolt) 使用經驗CompileGo
- Use any C++ Compiler with Visual StudioC++Compile
- Design Compiler多時鐘約束Compile
- webpack 流程解析(1):建立compiler之前WebCompile
- 編譯程式(compiler)的簡單分析編譯Compile
- 解決Cannot find module '@angular/compiler-cli'AngularCompile
- cgo: C compiler "gcc" not found 報錯安裝gccGoCompileGC
- Maven 教程(21)— maven-compiler-plugin 外掛詳解MavenCompilePlugin
- maven-compiler-plugin外掛引數配置詳解MavenCompilePlugin
- 程式碼來構建一個簡單的compilerCompile
- Jx.Cms開發筆記(六)-重寫Compiler筆記Compile
- 華為分析+App Linking:一站式解決拉新、留存、促活難APP
- 淺析webpack原始碼之Compiler.js模組(八)Web原始碼CompileJS
- TVM Compiler中文教程:TVM排程原語(Schedule Primitives)CompileMIT
- Swoole Compiler 加密 Drupal 產生的一些問題Compile加密
- 關於MyEclipse中build path和compiler的jre不匹配EclipseUICompile
- You are using the runtime-only build of Vue where the template compiler is not available.UIVueCompileAI
- error: #error This file requires compiler and library support for the ISO C++ 2011 standard.ErrorUICompileC++
- Unable to locate the Javac Compiler in: C:\Java\jre1.8\..\lib\tools.jarJavaCompileJAR
- 鴻蒙NEXT元服務:利用App Linking實現無縫跳轉與二維碼拉起鴻蒙APP
- 使用MATLAB compiler將matlab程式轉成獨立應用程式exeMatlabCompile
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compileAIGoApacheMavenPluginCompile
- Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.C++Compile
- 執行 Laravel-Mix 報錯 vue-template-compiler 與 vue 版本不同LaravelVueCompile
- 白鷺引擎王澤:巧用Webpack與EUI Compiler改善重度小遊戲開發效率WebUICompile遊戲開發
- 解決Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile(default-compile)AIGoApacheMavenPluginCompile
- 開發者狂喜!Meta最新發布的LLM Compiler,實現77%自動調優效率Compile
- vs2017編譯qt project失敗moc:Unknown compiler flavor ‘msvc;msvc‘; valid values are: msvc, unix.編譯QTProjectCompile
- NPM run dev 遇到的報錯!vue 和 vue-template-compiler 版本不一致NPMdevVueCompile
- STS中maven專案打包報錯: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 問題的解決方案MavenCompileIDEJDK
- 為什麼你安裝codeblock 會找不到GNU compiler ,找到了更改後還是原來的vs vc 等編譯器?BloCCompile編譯
- 蒲公英 · JELLY技術週刊 Vol.20: Vue3 極致優化——分析 Vue3 Compiler 告訴你為什麼這麼快Vue優化Compile