在 MinGW / MSYS 上编译 GCC 4.xx 失败

发布于 2024-09-11 08:52:23 字数 1688 浏览 6 评论 0原文

上周左右我一直在尝试编译任何 GCC 4 系列编译器以在 MinGW 5.1.6 / MSYS 1.0.11(来自 Sourceforge.org 的自动安装程序)中运行,该编译器随 GCC 版本 3.4.5 一起提供。最终目标是安装 GCC 4.5,但我无法构建任何 4.xx 编译器。

我已将其范围缩小到一系列会导致一些异常行为的构建指令。编译器执行:

build/genmodes.exe > tmp-modes.c
/bin/sh ../../gcc-4.2.4/gcc/../move-if-change tmp-modes.c insn-modes.c
echo timestamp > s-modes
gcc -c   -g -fkeep-inline-functions -DIN_GCC   -W -Wall -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute
-fno-common   -DHAVE_CONFIG_H -I. -I. -I../../gcc-4.2.4/gcc -I../../gcc-4.2.4/gcc/.
-I../../gcc-4.2.4/gcc/../include -I./../intl -I../../gcc-4.2.4/gcc/../libcpp/include
-I../../gcc-4.2.4/gcc/../libdecnumber -I../libdecnumber    insn-modes.c -o insn-modes.o

cc1.exe: out of memory allocating 2239725803 bytes
make[3]: *** [insn-modes.o] Error 1
make[3]: Leaving directory `/home/root/gcc-4.2.4-build/gcc'
make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory `/home/root/gcc-4.2.4-build'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/root/gcc-4.2.4-build'
make: *** [all] Error 2

主要问题似乎是对 genmodes.exe 的调用。它构建了一个大小约为 2GB 的 C 文件 (insn-modes.c),据我所知,该文件大部分由空格填充(尽管偶尔有几行 C 代码)。 GCC 3.4.5 被卡住了,构建就这样结束了。我尝试过的所有版本都表现出类似的行为,除了 4.5 之外,它由于其他原因而失败,我希望通过使用编译器的中间版本来解决这个问题。

所以,三个问题:

  1. 其他人也经历过这种情况吗?
  2. 是什么原因造成的?
  3. 如果存在解决方法怎么办?

我正在尝试在 64 位 Windows 7 计算机上执行此操作。

谢谢。

更新:我已将两个可疑文件的压缩副本上传到此位置。事实证明,min-insn-modes.c 也比应有的大。这两个文件(总计超过 3GB)压缩至 121KB。

I've been attempting for the last week or so to compile any of the GCC 4 series of compilers to run in MinGW 5.1.6 / MSYS 1.0.11 (automated installers both from Sourceforge.org) which ships with GCC version 3.4.5. The end goal is to get GCC 4.5 to install, but I haven't been able to get any of the 4.x.x compilers to build.

I've narrowed it down to a sequence of build instructions that result in some unusual behavior. The compiler executes:

build/genmodes.exe > tmp-modes.c
/bin/sh ../../gcc-4.2.4/gcc/../move-if-change tmp-modes.c insn-modes.c
echo timestamp > s-modes
gcc -c   -g -fkeep-inline-functions -DIN_GCC   -W -Wall -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute
-fno-common   -DHAVE_CONFIG_H -I. -I. -I../../gcc-4.2.4/gcc -I../../gcc-4.2.4/gcc/.
-I../../gcc-4.2.4/gcc/../include -I./../intl -I../../gcc-4.2.4/gcc/../libcpp/include
-I../../gcc-4.2.4/gcc/../libdecnumber -I../libdecnumber    insn-modes.c -o insn-modes.o

cc1.exe: out of memory allocating 2239725803 bytes
make[3]: *** [insn-modes.o] Error 1
make[3]: Leaving directory `/home/root/gcc-4.2.4-build/gcc'
make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory `/home/root/gcc-4.2.4-build'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/root/gcc-4.2.4-build'
make: *** [all] Error 2

The main problem seems to be the call to genmodes.exe. It builds a C file (insn-modes.c) that's about 2GB in size and which, as far as I can tell is filled mostly with whitespace (though there are scattered here and there the occassional line of C code). GCC 3.4.5 chokes on it and that's how the build ends. Similar behavior is exhibited in all of the versions I've tried, except 4.5, which fails for other reasons I was hoping would be cured by using an intermediate version of the compiler.

So, three questions:

  1. Has anybody else experienced this?
  2. What's causing it?
  3. What, if any workaround exists?

I'm trying to do this on a 64-bit Windows 7 machine.

Thanks.

Update: I've uploaded a compressed copy of two suspect files to this location. It turns out that min-insn-modes.c is also larger than it should be. The two files (over 3GB total) compress to 121KB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后彩虹 2024-09-18 08:52:23

我有同样的问题;我已将范围缩小到 genmodes.c 中的 tagged_printf。我仍然不知道为什么它失败了,但是用以下内容替换 tagged_printf 的定义(从 do 到包括 while)解决了问题:

#define tagged_printf(FMT, ARG, TAG) printf(" " FMT ",\n", ARG)

I have the same problem; I have narrowed it down to tagged_printf in genmodes.c. I still don't know why it failed, but replacing the define of tagged_printf (from the do to and including the while) with the following solved the problem:

#define tagged_printf(FMT, ARG, TAG) printf(" " FMT ",\n", ARG)

夢归不見 2024-09-18 08:52:23

insn-modes.c 不应太大或充满空格; genmodes 出现故障。我不知道为什么它会这样失败,但我很好奇看看 insn-modes.c (如果你把它放在一个 .zip 文件中,它应该将它缩小到你可以合理地将其上传到某个地方并将 URL 编辑到您的问题中)。

手动删除文件中的所有额外空格 (tr -s ' \r\n\t\v\f' ' ') 可能会得到可以编译的东西。

编辑:我查看了您上传的 min-insn-modes.c,我认为 Bryan 是对的,tagged_printf 中存在一个错误:每次调用它时,它都会发出大约 700 万个空格字符。 Bryan 的更改应该可以帮助您克服这个障碍,或者您可以通过将定义更改为以下内容来帮助进一步调查:

#define tagged_printf(FMT, ARG, TAG) do { \
    int count_ = printf (" " FMT ",", ARG); \
    printf ("\t/* %s [%d], */\n", TAG, count_); \
} while (0)

这也应该使您的构建成功,并且我希望看到 min-insn-modes.c 所做的更改。 (也不需要 insn-modes.c。)

添加:
请查看 emit_insn_modes_h() 函数。它还包含带有 %n 说明符的 printf,需要与上面类似地进行修改:

int count_ = printf ("  %smode,", m->name);

如果没有此更改,insn-modes.h 也会填充大量空格。

insn-modes.c should not be gigantic or filled with whitespace; genmodes is malfunctioning. I don't know why it would fail that way, but I'd be very curious to have a look at insn-modes.c (if you put it in a .zip file that should shrink it down to the point where you can reasonably upload it somewhere and edit the URL into your question).

Manually stripping all the extra whitespace out of the file (tr -s ' \r\n\t\v\f' ' ') may get you something that can be compiled.

EDIT: I looked at the min-insn-modes.c you uploaded, and I think Bryan is right, there's a bug in tagged_printf: every time it's called, it's emitting something like 7 million space characters. Bryan's change should get you past this hurdle, or you could help investigate a little further by changing the definition to this:

#define tagged_printf(FMT, ARG, TAG) do { \
    int count_ = printf (" " FMT ",", ARG); \
    printf ("\t/* %s [%d], */\n", TAG, count_); \
} while (0)

That should also make your build succeed, and I'd like to see min-insn-modes.c with that change made. (No need for insn-modes.c as well.)

ADDITION:
Please take a look into emit_insn_modes_h() function. It also contains printf with %n specifier which needs to be modified similarly to above:

int count_ = printf ("  %smode,", m->name);

Without this change insn-modes.h is also gets filled with a huge amount of spaces.

守不住的情 2024-09-18 08:52:23

MSDN 文档是这样说的:

安全说明 %n 格式本质上是不安全的,默认情况下处于禁用状态;如果在格式字符串中遇到 %n,则将调用无效参数处理程序,如参数验证中所述。要启用 %n 支持,请参阅_set_printf_count_output

所以 _set_printf_count_output(1) 应该可以解决这个问题。
是的,这很糟糕。

MSDN documentation says this:

Security Note The %n format is inherently insecure and is disabled by default; if %n is encountered in a format string, the invalid parameter handler is invoked as described in Parameter Validation. To enable %n support, see _set_printf_count_output.

So _set_printf_count_output(1) should fix the problem.
Yes, this sucks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文