【问题标题】:gcc -O2 vs. without causes errorgcc -O2 vs. 没有导致错误
【发布时间】:2011-12-13 18:40:01
【问题描述】:

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

【问题讨论】:

  • 您能否提供一个触发此错误的最小但完整的代码示例?
  • 奇怪,你确定它来自这条线?你包括所有需要的东西吗? (对于开放和 O_RDONLY)
  • 那你打电话给g++还是gcc

标签: c linux gcc


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      这里有一个错误报告,不管它值多少钱:

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

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

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

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

      【讨论】:

      • O2 会导致错误,因为在优化时,编译器正在使用这些内置函数。当它不优化时,它正在使用库函数。
      • 一般来说,一些检测错误的代码属于各种优化过程。因此,编译器仅在启用这些通道时才会检测到这些错误。
      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2015-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 2020-01-01
        • 1970-01-01
        相关资源
        最近更新 更多