主函数必须是汇编语言,其它C函数只要不调用libc即可。 给你个最小的例子:
root@vc:~# gcc -m32 -s -nostdlib tiny.s root@vc:~# ls -la a.out -rwxr-xr-x 1 root root 356 Mar 7 02:59 a.out root@vc:~# ./a.out root@vc:~# gcc -m64 -s -nostdlib tiny.s root@vc:~# ls -la a.out -rwxr-xr-x 1 root root 512 Mar 7 02:59 a.out root@vc:~# ./a.out root@vc:~# cat tiny.s .global _start .text _start: xorl %eax, %eax incl %eax movb $42, %bl int $0x80 2012/3/7 晓磊任 <julycl...@gmail.com>: > main函数的入口地位是由标准库决定的 > > -- > 冷静认真,稳定运行;随时候命,宠辱不惊 > > 在 2012年3月7日,7:25,Plain_Text <resat...@gmail.com> 写道: > >> >> >> glibc 并不仅仅是一套库,似乎跟系统结合得非常紧密。有无办法让应用程序 >> 绕过它?当然这并没有多大的实际意义,只是想通过这个问题稍微深入了解一下系 >> 统。比如下面简单的示例程序: >> >> int main(void) >> { >> return 0; >> } >> >> 并不使用任何的 C 库函数和变量,按理来说不需要使用到 glibc. 如果不加 >> 任何编译选项直接编译,用 ldd 发现它依赖 glibc. 但用编译选项 -nostartfiles >> -nodefaultlibs -nostdlib 试过,根本就编译不过。 >> >> >> >> >> -- >> To UNSUBSCRIBE, email to debian-chinese-gb-requ...@lists.debian.org >> with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org >> Archive: http://lists.debian.org/20120306232524.GA2678@localhost.localdomain >>