1. Differences between upper and lower case suffixes
.s assembly language source program; assembly
.S assembly language source program; preprocessing, assembly
Lowercase s files do not perform preprocessing operations in the later stage, so we cannot write preprocessing statements in it.
The S file in capital will also perform preprocessing, assembly and other operations, so we can add preprocessing commands here.
2. Compilation related process
Pre-Processing --> Compiling --> Assembly --> Linking
1. Preprocessor
Modify the original C program according to the commands starting with the character #.
This stage does not check the code errors, but only converts the # statement into C code.
2. Compilation stage
In this stage, Gcc first needs to check the code's standardization, whether there are syntax errors, etc., to determine the actual work of the code. After checking that it is correct, Gcc translates the code into assembly language. Users can use the "-S" option to view, which only compiles and does not assemble and generates assembly code. Assembly language is very useful and provides a common language for different high-level languages and different compilers. For example, the output files generated by the C compiler and the Fortran compiler use the same assembly language.
3. Assembly stage
The assembly stage converts the ".s" file generated in the compilation stage into the target file. Readers can use the option "-c" to see that the assembly code has been converted into the binary object code of ".o".
4. Link stage
Link library functions (used in header files) and so on to the target file.
After successful compilation, the linking stage is entered. An important concept is involved here: the function library
There is only the declaration of this function in "" and no implementation of the function is defined. So, where do we implement the library functions of "printf"? The final answer is: the system has implemented all these function implementations into a library file named .6. When there is no special specification, gcc will search under the system's default search path "/usr/lib", that is, link to the .6 library function, so that the function "printf" can be implemented, and this is the function.
Function libraries are generally divided into static libraries and dynamic libraries. Static libraries refer to adding all the code of the library file to the executable file when compiling and linking, so the generated files are relatively large, but the library files are no longer needed at runtime. The suffix name is generally ".a". In contrast, dynamic libraries do not add the code of the library file to the executable file when compiling and linking, but instead link the library to the runtime link file when the program is executed, which can save system overhead. The dynamic library is generally called ".so". As mentioned above, .6 is the dynamic library. gcc uses dynamic libraries by default when compiling.
After completing the link, gcc can generate an executable file.
The above is the detailed explanation of the analysis of the difference between assembly file suffix.s and .S. For more information about assembly file suffix.s and .S, please pay attention to my other related articles!