编译没有的libc [英] Compiling without libc

查看:149
本文介绍了编译没有的libc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编译我的C code无(G)的libc。我怎样才能将其停用,哪些功能取决于它?

I want to compile my C-code without the (g)libc. How can I deactivate it and which functions depend on it?

我试过-nostdlib但它没有帮助:code是编译和运行,但我仍然可以找到自己的可执行文件的hexdump都libc中的名称

I tried -nostdlib but it doesn't help: The code is compilable and runs, but I can still find the name of the libc in the hexdump of my executable.

推荐答案

如果您编译code。与-nostdlib,你将无法调用任何C库函数(当然),但你也不要得到的,常规的C引导code。特别是,在Linux的节目的实际进入点是不main()中,而是一个函数调用_start()。该标准库通常提供一个版本,这个运行一些初始化code,然后调用的main()。

If you compile your code with -nostdlib, you won't be able to call any C library functions (of course), but you also don't get the regular C bootstrap code. In particular, the real entry point of a program on linux is not main(), but rather a function called _start(). The standard libraries normally provide a version of this that runs some initialization code, then calls main().

尝试用gcc编译-nostdlib这样的:

Try compiling this with gcc -nostdlib:

void _start() {

    /* main body of program: call main(), etc */

    /* exit system call */
    asm("movl $1,%eax;"
        "xorl %ebx,%ebx;"
        "int  $0x80"
    );
}

在_start()函数应始终以呼叫结束退出(或其他非返回系统调用,如执行)。上面的例子直接与内联汇编调用系统调用,因为通常的出口()不可用。

The _start() function should always end with a call to exit (or other non-returning system call such as exec). The above example invokes the system call directly with inline assembly since the usual exit() is not available.

这篇关于编译没有的libc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆