簡體   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