gcc -O2 vs.无原因错误

时间:2011-12-13 18:40:02

标签: c linux gcc

编译包含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 ()’

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

编辑:事实证明,纪念这些行会产生另一种“类型”错误,例如:

/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 个答案:

答案 0 :(得分:2)

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

这是一个错误报告,无论它的价值如何:

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

不,我没有想法为什么“-O2”会与这个特定的错误有关...

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

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

答案 1 :(得分:2)

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

答案 2 :(得分:1)

如果您想忽略此错误,请考虑删除标记-Wp,-D_FORTIFY_SOURCE=2。 例如,如果您使用rpmbuild,则此标记由RPM_OPT_FLAGS

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

除了提到的标志之外,这是保存一切的简单方法

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

答案 3 :(得分:1)

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

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

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