gcvt 或 gcvtf 在 gcc 源代码中的哪里定义?
我正在 m68k 目标上的嵌入式系统上处理一些旧的源代码,并且在调用 gcvtf 格式化浮点数以供显示时有时会看到大量内存分配请求。我可能可以通过编写自己的替代例程来解决这个问题,但错误的本质让我很好奇,因为它只发生在堆从某个地址或高于某个地址开始时,如果我破解 .ld 链接器,它就会消失编写脚本或删除任何一组全局变量(它们放置在我的内存映射中的堆之前),这些变量加起来达到足够的字节大小,以便堆在神秘的关键地址下方开始。
所以,我想我应该在 gcc 源代码中查找我正在使用的编译器版本(m68k-elf-gcc 3.3.2)。我在 http://gcc.petsads 下载了似乎是此版本的源代码.us/releases/gcc-3.3.2/,但我在其中找不到 gcvt 或 gcvtf 的定义。当我搜索它时,grep 只找到一些文档和 .h 引用,但没有找到定义:
$ find | xargs grep gcvt
./gcc/doc/gcc.info: C library functions `ecvt', `fcvt' and `gcvt'. Given va
lid
./gcc/doc/trouble.texi:library functions @code{ecvt}, @code{fcvt} and @code{gcvt
}. Given valid
./gcc/sys-protos.h:extern char * gcvt(double, int, char *);
那么,这个函数在源代码中实际定义在哪里?或者我下载了完全错误的东西?
出于项目稳定性和测试考虑,我不想更改此项目以使用最新的 gcc,并且正如我所说,我可以通过编写自己的格式化例程来解决此问题,但这种行为对我来说非常令人困惑,如果我不找出为什么它表现得如此奇怪,我的大脑就会绞尽脑汁。
I'm working on some old source code for an embedded system on an m68k target, and I'm seeing massive memory allocation requests sometimes when calling gcvtf
to format a floating point number for display. I can probably work around this by writing my own substitute routine, but the nature of the error has me very curious, because it only occurs when the heap starts at or above a certain address, and it goes away if I hack the .ld linker script or remove any set of global variables (which are placed before the heap in my memory map) that add up to enough byte size so that the heap starts below the mysterious critical address.
So, I thought I'd look in the gcc source code for the compiler version I'm using (m68k-elf-gcc 3.3.2). I downloaded what appears to be the source for this version at http://gcc.petsads.us/releases/gcc-3.3.2/, but I can't find the definition for gcvt or gcvtf anywhere in there. When I search for it, grep only finds some documentation and .h references, but not the definition:
$ find | xargs grep gcvt
./gcc/doc/gcc.info: C library functions `ecvt', `fcvt' and `gcvt'. Given va
lid
./gcc/doc/trouble.texi:library functions @code{ecvt}, @code{fcvt} and @code{gcvt
}. Given valid
./gcc/sys-protos.h:extern char * gcvt(double, int, char *);
So, where is this function actually defined in the source code? Or did I download the entirely wrong thing?
I don't want to change this project to use the most recent gcc, due to project stability and testing considerations, and like I said, I can work around this by writing my own formatting routine, but this behavior is very confusing to me, and it will grind my brain if I don't find out why it's acting so weird.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Wallyk 是正确的,它是在 C 库而不是编译器中定义的。然而,GNU C 库(几乎总是)仅与 Linux 编译器和发行版一起使用。您的编译器是“裸机”编译器,几乎肯定会使用 Newlib C 库。
Newlib 的主要网站在这里:http://sourceware.org/newlib/,这个特定的函数是在
newlib/libc/stdlib/efgcvt.c
文件中定义。源代码长期以来一直相当稳定,因此(除非这是错误的结果)当前源代码与您的编译器使用的源代码没有太大不同的可能性很大。与 GNU C 源代码一样,我没有看到任何明显会导致您所看到的奇怪现象的内容,但最终都是围绕基本
sprintf
例程的一堆包装器。Wallyk is correct that this is defined in the C library rather than the compiler. However, the GNU C library is (nearly always) only used with Linux compilers and distributions. Your compiler, being a "bare-metal" compiler, almost certainly uses the Newlib C library instead.
The main website for Newlib is here: http://sourceware.org/newlib/, and this particular function is defined in the
newlib/libc/stdlib/efgcvt.c
file. The sources have been quite stable for a long time, so (unless this is a result of a bug) chances are pretty good that the current sources are not too different from what your compiler is using.As with the GNU C source, I don't see anything in there that would obviously cause this weirdness that you're seeing, but it's all eventually a bunch of wrappers around the basic
sprintf
routines.它位于 GNU C 库中,名称为 glibc/misc/efgcvt.c。为了省去你的麻烦,该函数的代码是:
获取glibc的说明在这里。
It is in the GNU C library as
glibc/misc/efgcvt.c
. To save you some trouble, the code for the function is:The directions for obtain glibc are here.