C Program Compilation Process

refer to for more details:

https://medium.com/@earthtojhuang/gcc-main-c-9f6ee2e6894b

https://www.geeksforgeeks.org/compiling-a-c-program-behind-the-scenes/

Compiling, linking, loading:

  • Preprocessor takes C source code (ASCII text), expands #include etc, produces C source code
  • Compiler takes C source code (ASCII text), produces assembly language (also ASCII text)
  • Assembler takes assembly language (ASCII text), produces .o file (binary, machine-readable!)
  • Linker takes multiple '.o's, produces a single program image (binary)
  • Loader loads the program image into memory at run-time and starts it executing

// tst.c

#include <stdio.h>

main()
{
        printf("hello world\n");
}

$ gcc -S tst.c  # the output is tst.s

$ gcc -c tst.c  # the output is tst.o

$ file tst.*
tst.c: C source, ASCII text
tst.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
tst.s: assembler source, ASCII text
gcc -S  --> Compile but don't assemble
gcc -c  --> Preprocess, compile, and assemble, but don't link

disassembly/反汇编

objdump -S a.out > tst.asm

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值