In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What are the knowledge points of the redhat 6.5 gcc compiler? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Test conclusion
1 GCC is a compiler, which is divided into four stages
2the four stages are
Pretreatment stage
Compilation phase
Assembly stage
Link Pha
3. The preprocessing stage is to compile the contents of the stdio.h header file.
4. When the compilation phase is GCC, you should first check the standardization of the code and see if there are any syntax errors to determine what the code actually does. After the check is correct,
GCC compiles the code into assembly code
5The third stage of GCC is the assembly stage of GCC, that is, the .s file generated by the second stage of GCC is converted into an object file.
(6) the fourth stage of GCC, that is, entering the link stage of GCC. An important concept is involved here: function library.
We can look at the Mini Program, or helloworld.c, again. There is no implementation of the printf function defined in this program.
And in its precompiled header file stdio.h, there is only the declaration of this function, but without the implementation of this function, where on earth is it implemented?
The printf function. The answer is: the operating system will put all these function implementations into a library file called libc.so.6, if not specified
GCC will go to the default path of the operating system, that is, / USR/LIB, that is to say, it will link to the LIBC.SO.6 library function of this path, so that the function PRINTF can be realized finally.
7. Function libraries are generally divided into 2 types:
Static library and dynamic library
Static library means that when compiling a link, all the code of the library file will be added to the executable file, so the generated file will be larger, but the library file is not needed at run time, and its suffix is generally .a.
The dynamic library, contrary to the static library, does not add the code of the library file to the executable file when compiling the link, but links the file loading library when the program is executed, which can save the overhead of the system.
Dynamic libraries are generally suffixed with. So, as mentioned above, LIBC.SO.6 is a dynamic library.
GCC uses dynamic libraries by default when compiling.
Test details
1, operating system version
[root@mygirl ~] # more / etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@mygirl ~] #
2, write a helloworld.c source code file
[root@mygirl ~] # pwd
/ root
[root@mygirl ~] #
Clude
Int main () {
Printf ("hello world!\ n")
Return 0
}
[root@mygirl ~] #
3. Carry out the four stages of gcc, the first stage of preprocessing, that is, compile the contents of the stdio.h header file.
[root@mygirl] # gcc-E helloworld.c-o helloworld.i
[root@mygirl ~] #
[root@mygirl ~] # ll hel*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
4. Check the files generated in the preprocessing phase of GCC. You can see that this file contains a lot of content.
[root@mygirl ~] # more helloworld.i | more
# 1 "helloworld.c"
# 1 ""
# 1 ""
# 1 "helloworld.c"
# 1 "/ usr/include/stdio.h" 1 3 4
# 28 "/ usr/include/stdio.h" 3 4
# 1 "/ usr/include/features.h" 1 3 4
# 361 "/ usr/include/features.h" 3 4
# 1 "/ usr/include/sys/cdefs.h" 1 3 4
# 365 "/ usr/include/sys/cdefs.h" 3 4
# 1 "/ usr/include/bits/wordsize.h" 1 3 4
# 366 "/ usr/include/sys/cdefs.h" 2 3 4
# 362 "/ usr/include/features.h" 2 3 4
# 385 "/ usr/include/features.h" 3 4
# 1 "/ usr/include/gnu/stubs.h" 1 3 4
# 1 "/ usr/include/bits/wordsize.h" 1 3 4
# 5 "/ usr/include/gnu/stubs.h" 2 3 4
# 1 "/ usr/include/gnu/stubs-64.h" 1 3 4
# 10 "/ usr/include/gnu/stubs.h" 2 3 4
# 386 "/ usr/include/features.h" 2 3 4
# 29 "/ usr/include/stdio.h" 2 3 4
5. After checking that the stdio.h header file is added to the file produced by its preprocessing through the GCC preprocessing stage.
[root@mygirl ~] # locate stdio.h
/ oracle/product/11.2.0/db_1/perl/lib/5.10.0/x86_64-linux-thread-multi/CORE/nostdio.h
/ usr/include/stdio.h
/ usr/include/bits/stdio.h
[root@mygirl ~] # more / usr/include/stdio.h | more
/ * Define ISO C stdio on top of C++ iostreams.
Copyright (C) 1991, 1994-2008, 2009, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
Version 2.1of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful
But WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. , /
/ *
* ISO C99 Standard: 7.19 Input/output
, /
# ifndef _ STDIO_H
# if! defined _ _ need_FILE & &! defined _ _ need___FILE
# define _ STDIO_H 1
# include
6. Proceed to the compilation phase of the second phase of gcc, in which GCC first checks the specification of the code for syntax errors to determine what the code is actually going to do.
GCC compiles the code into assembly code
[root@mygirl ~] # ll helloworld.*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
[root@mygirl] # gcc-S helloworld.i-o helloworld.s
[root@mygirl ~] #
[root@mygirl ~] # ll helloworld.*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
-rw-r--r--. 1 root root 448 Jun 30 06:38 helloworld.s
[root@mygirl ~] # more helloworld.s
.file "helloworld.c"
.section .rodata
.LC0:
.string "hello world!"
.text
.globl main
.type main, @ function
Main:
.LFB0:
.cfi _ startproc
Pushq rbp
.cfi _ def_cfa_offset 16
.cfi _ offset 6,-16
Movq rsp, rbp
.cfi _ def_cfa_register 6
Movl $.LC0,% edi
Call puts
Movl $0,% eax
Leave
.cfi _ def_cfa 7, 8
Ret
.cfi _ endproc
.LFE0:
.size main,.-main
.ident GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-4) "
.section. Note.GNU-stack, "", @ progbits
7, proceed to the third stage of GCC, that is, the assembly phase of GCC, that is, convert the .s file generated by the second stage of GCC into the target file.
/ root
[root@mygirl ~] # ll helloworld.*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
-rw-r--r--. 1 root root 448 Jun 30 06:38 helloworld.s
[root@mygirl ~] #
[root@mygirl ~] #
8, proceed to the fourth stage of GCC, that is, enter the link phase of GCC. An important concept is involved here: function library.
We can look at the Mini Program, or helloworld.c, again. There is no implementation of the printf function defined in this program.
And in its precompiled header file stdio.h, there is only the declaration of this function, but without the implementation of this function, where on earth is it implemented?
The printf function. The answer is: the operating system will put all these function implementations into a library file called libc.so.6, if not specified
GCC will go to the default path of the operating system, that is, / USR/LIB, that is to say, it will link to the LIBC.SO.6 library function of this path, so that the function PRINTF can be realized finally.
[root@mygirl] # gcc-c helloworld.s-o helloworld.o
[root@mygirl ~] #
[root@mygirl ~] #
[root@mygirl ~] # ll helloworld.*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
-rw-r--r--. 1 root root 1504 Jun 30 06:46 helloworld.o
-rw-r--r--. 1 root root 448 Jun 30 06:38 helloworld.s
[root@mygirl ~] # strings helloworld.o
Hello world!
[root@mygirl ~] #
nine,
Function libraries are generally divided into two types:
Static library and dynamic library
Static library means that when compiling a link, all the code of the library file will be added to the executable file, so the generated file will be larger, but the library file is not needed at run time, and its suffix is generally .a.
The dynamic library, contrary to the static library, does not add the code of the library file to the executable file when compiling the link, but links the file loading library when the program is executed, which can save the overhead of the system.
Dynamic libraries are generally suffixed with. So, as mentioned above, LIBC.SO.6 is a dynamic library.
GCC uses dynamic libraries by default when compiling.
[root@mygirl ~] # ll helloworld.*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
-rw-r--r--. 1 root root 1504 Jun 30 06:46 helloworld.o
-rw-r--r--. 1 root root 448 Jun 30 06:38 helloworld.s
[root@mygirl ~] #
[root@mygirl] # gcc helloworld.o-o helloworld
[root@mygirl ~] #
[root@mygirl ~] #
[root@mygirl ~] # ll helloworld.*
-rw-r--r--. 1 root root 76 Jun 30 06:20 helloworld.c
-rw-r--r--. 1 root root 16751 Jun 30 06:22 helloworld.i
-rw-r--r--. 1 root root 1504 Jun 30 06:46 helloworld.o
-rw-r--r--. 1 root root 448 Jun 30 06:38 helloworld.s
[root@mygirl ~] #
[root@mygirl ~] # ll helloworld
-rwxr-xr-x. 1 root root 6430 Jun 30 06:58 helloworld
[root@mygirl ~] #
10. Take a look at the fourth stage of GCC, that is, the link phase of GCC, which produces file names that do not have the extension.
[root@mygirl ~] # strings helloworld
/ lib64/ld-linux-x86-64.so.2
_ _ gmon_start__
Libc.so.6
Puts
_ _ libc_start_main
GLIBC_2.2.5
Fff.
Fffff.
L $L
T $(L
| | $0H |
Hello world!
[root@mygirl ~] #
11, execute the execution files generated by the fourth phase of the GCC
[root@mygirl ~] #. / helloworld
Hello world!
[root@mygirl ~] #
12, view dynamic library files
[root@mygirl ~] # locate libc.so.6
/ lib/libc.so.6
/ lib/i686/nosegneg/libc.so.6
/ lib64/libc.so.6
/ oracle/product/11.2.0/db_1/lib/stubs/libc.so.6
[root@mygirl ~] # strings / lib/libc.so.6 | grep-I-color printf
Vswprintf
_ _ obstack_vprintf_chk
Vasprintf
Printf_size
_ _ vfprintf_chk
Vfwprintf
_ _ vsprintf_chk
[root@mygirl ~] # more / oracle/product/11.2.0/db_1/lib/sysliblist
-ldl-lm-lpthread-lnsl-lirc-lipgo-lsvml
After reading the above, do you have any methods to master the knowledge points of the redhat 6.5 gcc compiler? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.