C语言编译过程--编译过程探索

Posted 胡刚2021

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言编译过程--编译过程探索相关的知识,希望对你有一定的参考价值。

gcc -S hello.c > hello.s


可以看到 .s 文件比预处理后的 .e 文件小了很多
hello.s文件全部内容如下:

	.file	"hello.c"
	.text
	.section	.rodata
.LC0:
	.string	"hello world"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$123, -4(%rbp)
	leaq	.LC0(%rip), %rdi
	call	puts@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 9.3.0-10ubuntu2) 9.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	 1f - 0f
	.long	 4f - 1f
	.long	 5
0:
	.string	 "GNU"
1:
	.align 8
	.long	 0xc0000002
	.long	 3f - 2f
2:
	.long	 0x3
3:
	.align 8
4:

可以看出来这就是一个汇编文件

可以根据这个汇编文件看出来,已经没有printf函数了,只有调用 puts 函数

call	puts@PLT

以上是关于C语言编译过程--编译过程探索的主要内容,如果未能解决你的问题,请参考以下文章

C语言笔记1-编译过程

梦开始的地方—— C语言预处理+编译过程

C编译过程

ESP8266编译过程探索

如何编译C/Fortran动态/静态链接库

c语言学习笔记|编译过程|数据类型|scanf|运算符|选择与循环|指针的传递