让 GCC 编译而不插入对 memcpy 的调用 [英] Getting GCC to compile without inserting call to memcpy

查看:34
本文介绍了让 GCC 编译而不插入对 memcpy 的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用为 PowerPC 440 编译的 GCC 4.5.3,并且正在编译一些不需要 libc 的代码.我没有直接调用 memcpy(),但编译器似乎在构建过程中插入了一个.

I'm currently using GCC 4.5.3, compiled for PowerPC 440, and am compiling some code that doesn't require libc. I don't have any direct calls to memcpy(), but the compiler seems to be inserting one during the build.

有 -nostdlib、-nostartfiles、-nodefaultlibs 等链接器选项,但我无法使用它们,因为我没有进行链接阶段.我只是在编译.像这样:

There are linker options like -nostdlib, -nostartfiles, -nodefaultlibs but I'm unable to use them as I'm not doing the linking phase. I'm only compiling. With something like this:

$ powerpc-440-eabi-gcc -O2 -g -c -o output.o input.c

如果我用 nm 检查 output.o,我会看到对 memcpy 的引用:

If I check the output.o with nm, I see a reference to memcpy:

$ powerpc-440-eabi-nm output.o | grep memcpy
     U memcpy
$ 

GCC 手册页清楚地说明了如何使用链接器删除对 memcpy 的调用和其他 libc 调用,但我不希望编译器首先插入它们,因为我使用的是完全不同的链接器(不是 GNU 的 ld,它不知道 libc).

The GCC man page makes it clear how to remove calls to memcpy and other libc calls with the linker, but I don't want the compiler to insert them in the first place, as I'm using a completely different linker (not GNU's ld, and it doesn't know about libc).

感谢您提供的任何帮助.

Thanks for any help you can provide.

推荐答案

您需要使用 -fno-builtin 禁用该优化.在尝试为 C 库编译 memcpy 时,我遇到过这个问题.它自称.糟糕!

You need to disable a that optimization with -fno-builtin. I had this problem once when trying to compile memcpy for a C library. It called itself. Oops!

这篇关于让 GCC 编译而不插入对 memcpy 的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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