gcc -O2 vs.无原因错误

时间:2021-08-29 04:55:06

When compiling file containing open("FILENAME", O_RDONLY); without -O2 flag everything is fine. But when -O2 is turned on I get:

编译包含open的文件时(“FILENAME”,O_RDONLY);没有-O2标志一切都很好。但是当-O2打开时,我得到:

/usr/include/x86_64-linux-gnu/bits/fcntl2.h: In function ‘open’:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:44:7: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:45:26: error: call to ‘__open_too_many_args’ declared with attribute error: open can be called either with 2 or 3 arguments, not more
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:42:1: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:60:3: error: invalid use of ‘__builtin_va_arg_pack ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h: In function ‘open64’:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:76:7: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:77:28: error: call to ‘__open64_too_many_args’ declared with attribute error: open64 can be called either with 2 or 3 arguments, not more
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:74:1: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:92:3: error: invalid use of ‘__builtin_va_arg_pack ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h: In function ‘openat’:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:120:7: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:121:28: error: call to ‘__openat_too_many_args’ declared with attribute error: openat can be called either with 3 or 4 arguments, not more
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:118:1: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:136:3: error: invalid use of ‘__builtin_va_arg_pack ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h: In function ‘openat64’:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:154:7: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:155:30: error: call to ‘__openat64_too_many_args’ declared with attribute error: openat64 can be called either with 3 or 4 arguments, not more
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:152:1: error: invalid use of ‘__builtin_va_arg_pack_len ()’
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:170:3: error: invalid use of ‘__builtin_va_arg_pack ()’

Where can be the problem? It's mixed C/C++ project but this is in the C part. gcc 4.6.1, kernel 3.0.0

哪里可以问题?它是混合的C / C ++项目,但这是在C部分。 gcc 4.6.1,内核3.0.0

Edit: It turns out that commeting out those line gives another "type" of errors like:

编辑:事实证明,纪念这些行给出了另一种类型的错误,例如:

/usr/include/x86_64-linux-gnu/bits/stdio2.h: In function ‘sprintf’:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:34:3: error: invalid use of ‘__builtin_va_arg_pack ()’

4 个解决方案

#1


2  

Try compiling with -fno-builtins. If that fixes it then you've obviously got some sort of problem, but it's probably not in your source.

尝试使用-fno-builtins进行编译。如果修复了它,那么你显然遇到了一些问题,但它可能不在你的来源中。

#2


2  

I'd simply download a different (slightly older?) kernel build:

我只是下载一个不同的(略长的?)内核版本:

Here's a bug report, for whatever it's worth:

这是一个错误报告,无论它值多少:

https://bugs.archlinux.org/task/27100

And no, I have no idea why "-O2" would have anything to do with this particular error...

不,我不知道为什么“-O2”会与这个特殊错误有关...

ADDENDUM: This link might give you more explanation about the error message itself. But again - I'd suggest trying a different kernel build as your first step:

ADDENDUM:此链接可能会为您提供有关错误消息本身的更多说明。但同样 - 我建议尝试不同的内核构建作为您的第一步:

http://gcc.gnu.org/ml/gcc-patches/2007-09/msg00675.html

#3


1  

If you want to ignore this error, consider removing the flag -Wp,-D_FORTIFY_SOURCE=2 . For example, if you use rpmbuild, this flag is introduced by RPM_OPT_FLAGS

如果要忽略此错误,请考虑删除标志-Wp,-D_FORTIFY_SOURCE = 2。例如,如果使用rpmbuild,则此标志由RPM_OPT_FLAGS引入

%build
export CFLAGS="$RPM_OPT_FLAGS"
export CXXFLAGS="$RPM_OPT_FLAGS"
./configure …

Here is a simple way to keep everything but the mentioned flag

这是一个简单的方法来保持除了提到的标志之外的一切

OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed 's/-Wp,-D_FORTIFY_SOURCE=2 //'`
export CFLAGS="$OPT_FLAGS"
export CXXFLAGS="$OPT_FLAGS"

#4


1  

I hit this when trying to compile https://www.spec.org/cpu2017/Docs/benchmarks/602.gcc_s.html with GCC.

我在尝试使用GCC编译https://www.spec.org/cpu2017/Docs/benchmarks/602.gcc_s.html时遇到了这个问题。

Ironically, the bootstrap process would fail due to GCC appearently not understanding GNU extensions.

具有讽刺意味的是,由于GCC显然不理解GNU扩展,因此引导过程将失败。

Turning on -fgnu89-inline got rid of any problems I was having. Alternatively, use -std=gnu89.

打开-fgnu89-inline摆脱了我遇到的任何问题。或者,使用-std = gnu89。

#1


2  

Try compiling with -fno-builtins. If that fixes it then you've obviously got some sort of problem, but it's probably not in your source.

尝试使用-fno-builtins进行编译。如果修复了它,那么你显然遇到了一些问题,但它可能不在你的来源中。

#2


2  

I'd simply download a different (slightly older?) kernel build:

我只是下载一个不同的(略长的?)内核版本:

Here's a bug report, for whatever it's worth:

这是一个错误报告,无论它值多少:

https://bugs.archlinux.org/task/27100

And no, I have no idea why "-O2" would have anything to do with this particular error...

不,我不知道为什么“-O2”会与这个特殊错误有关...

ADDENDUM: This link might give you more explanation about the error message itself. But again - I'd suggest trying a different kernel build as your first step:

ADDENDUM:此链接可能会为您提供有关错误消息本身的更多说明。但同样 - 我建议尝试不同的内核构建作为您的第一步:

http://gcc.gnu.org/ml/gcc-patches/2007-09/msg00675.html

#3


1  

If you want to ignore this error, consider removing the flag -Wp,-D_FORTIFY_SOURCE=2 . For example, if you use rpmbuild, this flag is introduced by RPM_OPT_FLAGS

如果要忽略此错误,请考虑删除标志-Wp,-D_FORTIFY_SOURCE = 2。例如,如果使用rpmbuild,则此标志由RPM_OPT_FLAGS引入

%build
export CFLAGS="$RPM_OPT_FLAGS"
export CXXFLAGS="$RPM_OPT_FLAGS"
./configure …

Here is a simple way to keep everything but the mentioned flag

这是一个简单的方法来保持除了提到的标志之外的一切

OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed 's/-Wp,-D_FORTIFY_SOURCE=2 //'`
export CFLAGS="$OPT_FLAGS"
export CXXFLAGS="$OPT_FLAGS"

#4


1  

I hit this when trying to compile https://www.spec.org/cpu2017/Docs/benchmarks/602.gcc_s.html with GCC.

我在尝试使用GCC编译https://www.spec.org/cpu2017/Docs/benchmarks/602.gcc_s.html时遇到了这个问题。

Ironically, the bootstrap process would fail due to GCC appearently not understanding GNU extensions.

具有讽刺意味的是,由于GCC显然不理解GNU扩展,因此引导过程将失败。

Turning on -fgnu89-inline got rid of any problems I was having. Alternatively, use -std=gnu89.

打开-fgnu89-inline摆脱了我遇到的任何问题。或者,使用-std = gnu89。