繁体   English   中英

gcc -O2 与无原因错误

[英]gcc -O2 vs. without causes error

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

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

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

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

尝试使用-fno-builtins编译。 如果这解决了它,那么您显然遇到了某种问题,但它可能不在您的来源中。

我只是下载一个不同的(稍微旧的?)内核版本:

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

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

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

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

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

如果您想忽略此错误,请考虑删除标志-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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM