可重定向文件生成
文件的格式與操作系統和編譯器密切相關,linux的可執行文件是基於COFF的ELF格式,可重定向文件(也叫做目標文件.o)與可執行文件格式很接近,只是沒有經過鏈接調整符號和地址。
源代碼:
/*
* SimpleSection.c
*
* Linux:
* gcc -c SimpleSection.c
*
* Windows:
* cl SimpleSection.c /c /Za
*/
int printf(const char* format, ...);
int global_init_var = 84; //存儲在.data section
int global_uninit_var; //.bss section 實際上先放在COMM符號表中,在鏈接時確定地址後放入.bss
void func1(int i) //.text section
{
printf("%d\n", i);
}
int main(void) //.text section
{
static int static_var = 85; //.data section
static int static_var2; //.bss section
int a = 1;
int b;
func1(static_var + static_var2 + a + b);
return a;
}
gcc -c Simplesection.c //生成可重定位文件,如果加上-o選項,會生成可共享文件
使用file查看文件類型
可重定向文件類型
liyumin@liyumin-B250M