[^July 24, 2015 9:54 PM]
前言
经常编译代码,运行代码,修改Bug,也会遇到各种问题,而且有时更多与编译、链接相关的问题,因此,就想了解一下最基本的编译、链接的原理。(平台为windows7和VS2010,上了微软的贼船了!!!!)
编译
先了解编译出来的东东,而且使用的cmd编译命令,而不是IDE,因为使用IDE就无法知道中间过程了。先上码。
int printf( const char *format,...);
int global_int_val = 84;
int global_uninit_var;
void func1(int i)
{
printf("%d\n",i);
}
int main(void)
{
static int static_var = 85;
static int static_var2;
int a = 1;
int b;
func1( static_var + static_var2+ a + b );
return a;
}
在VS控制台的命令,cl /c /Za SimpleSection.c,产生的文件为SimpleSection.obj,打开后就是一大堆二进制的数据。用 dumpbin工具进行查看,命令dumpbin /ALL SimpleSection.obj > SimpleSection.txt,产生的结果如下:
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file SimpleSection.obj
File Type: COFF OBJECT
FILE HEADER VALUES
14C machine (x86)
5 number of sections
55B240DA time date stamp Fri Jul 24 21:42:50 2015
1F0 file pointer to symbol table
14 number of symbols
0 size of optional header
0 characteristics
SECTION HEADER #1
.drectve name
0 physical address
0 virtual address
18 size of raw data
DC file pointer to raw data (000000DC to 000000F3)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line num