/********************************************************************** * elfutils cc1: all warnings being treated as errors * 說明: * 在Ubuntu 18.04上編譯Yocto,elfutils的Makefile中出現沒有識別到一些配置, * 需要在Makefile中去掉-Werror選項。 * * 2018-6-14 深圳 寶安西鄉 曾劍鋒 *********************************************************************/ 一、參考文檔: 1. How to compile without warnings being treated as errors? https://stackoverflow.com/questions/11561261/how-to-compile-without-warnings-being-treated-as-errors 2. all warnings being treated as errors https://wizardforcel.gitbooks.io/100-gcc-tips/content/warnings-treated-as-errors.html 二、報錯現象: 1. 現象: x86_64-linux/usr/include -O2 -pipe -c -o dwfl_report_elf.o ../../elfutils-0.164/libdwfl/dwfl_report_elf.c | ../../elfutils-0.164/libdwfl/dwfl_report_elf.c: In function '__libdwfl_elf_address_range': | ../../elfutils-0.164/libdwfl/dwfl_report_elf.c:172:19: error: this statement may fall through [-Werror=implicit-fallthrough=] | add_p_vaddr = true; | ^ | ../../elfutils-0.164/libdwfl/dwfl_report_elf.c:174:5: note: here | case ET_DYN: | ^~~~ | cc1: all warnings being treated as errors | Makefile:576: recipe for target 'dwfl_report_elf.o' failed 2. 現象: imx6q-x11/tmp/sysroots/x86_64-linux/usr/include -O2 -pipe -c -o dwarf_next_cfi.o ../../elfutils-0.164/libdw/dwarf_next_cfi.c | In file included from ../../elfutils-0.164/libdw/dwarf_next_cfi.c:34:0: | ../../elfutils-0.164/libdw/encoded-value.h: In function 'encoded_value_size': | ../../elfutils-0.164/libdw/encoded-value.h:60:10: error: this statement may fall through [-Werror=implicit-fallthrough=] | if (p != NULL) | ^ | ../../elfutils-0.164/libdw/encoded-value.h:68:5: note: here | default: | ^~~~~~~ | cc1: all warnings being treated as errors | Makefile:708: recipe for target 'dwarf_next_cfi.o' failed | make[3]: *** [dwarf_next_cfi.o] Error 1 3. 現象: inux/usr/include -O2 -pipe -c -o i386_disasm.o ../../elfutils-0.164/libcpu/i386_disasm.c | ../../elfutils-0.164/libcpu/i386_disasm.c: In function 'i386_disasm': | ../../elfutils-0.164/libcpu/i386_disasm.c:789:9: error: this statement may fall through [-Werror=implicit-fallthrough=] | if (data[1] == 0xc2) | ^ | ../../elfutils-0.164/libcpu/i386_disasm.c:823:4: note: here | default: | ^~~~~~~ | cc1: all warnings being treated as errors | Makefile:441: recipe for target 'i386_disasm.o' failed 三、解決方法: 1. 原因: cc1: all warnings being treated as errors 2. 修改對應的Makefile,去掉-Werror: 3. 手動處理示例: /home/zengjf/zengjf/fsl-release-bsp/imx6q-x11/tmp/work/x86_64-linux/elfutils-native/0.164-r0/build/libdwfl/Makefile [...省略] # Warn about stack usage of more than 256K = 262144 bytes. STACK_USAGE_WARNING = -Wstack-usage=262144 AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \ -Wold-style-definition -Wstrict-prototypes \ $(if $($(*F)_no_Werror),,-Werror) \ # remove this line $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \ $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \ $($(*F)_CFLAGS) [...省略] 4. 獲取Makefile生成信息: zengjf@zengjf:~/zengjf/fsl-release-bsp/imx6q-x11/tmp/work/x86_64-linux/elfutils-native/0.164-r0$ grep _no_Werror * -r build/tests/Makefile: $(if $($(*F)_no_Werror),,-Werror) \ build/libdwfl/Makefile.bak: $(if $($(*F)_no_Werror),,-Werror) \ build/backends/Makefile: $(if $($(*F)_no_Werror),,-Werror) \ build/libdwelf/Makefile: $(if $($(*F)_no_Werror),,-Werror) \ build/lib/Makefile: $($(*F)_no_Werror),,-Werror) $(if \ build/libasm/Makefile: $(if $($(*F)_no_Werror),,-Werror) \ build/libelf/Makefile: $($(*F)_no_Werror),,-Werror) $(if \ build/libebl/Makefile: $($(*F)_no_Werror),,-Werror) $(if \ build/src/Makefile: $(if $($(*F)_no_Werror),,-Werror) \ build/src/Makefile:ldlex_no_Werror = yes build/libcpu/Makefile:i386_lex_no_Werror = yes elfutils-0.164/tests/Makefile.in: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/libdwfl/Makefile.in: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/backends/Makefile.in: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/config/eu.am: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/libdwelf/Makefile.in: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/libdw/Makefile.in: $($(*F)_no_Werror),,-Werror) $(if \ elfutils-0.164/lib/Makefile.in: $($(*F)_no_Werror),,-Werror) $(if \ elfutils-0.164/libasm/Makefile.in: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/libelf/Makefile.in: $($(*F)_no_Werror),,-Werror) $(if \ elfutils-0.164/libebl/Makefile.in: $($(*F)_no_Werror),,-Werror) $(if \ elfutils-0.164/src/Makefile.in: $(if $($(*F)_no_Werror),,-Werror) \ elfutils-0.164/src/Makefile.in:ldlex_no_Werror = yes elfutils-0.164/src/Makefile.am:ldlex_no_Werror = yes elfutils-0.164/libcpu/Makefile.in: $($(*F)_no_Werror),,-Werror) $(if \ elfutils-0.164/libcpu/Makefile.in:i386_lex_no_Werror = yes elfutils-0.164/libcpu/Makefile.am:i386_lex_no_Werror = yes elfutils-0.164/.pc/dso-link-change.patch/src/Makefile.am:ldlex_no_Werror = yes elfutils-0.164/.pc/uclibc-support.patch/libcpu/Makefile.am:i386_lex_no_Werror = yes zengjf@zengjf:~/zengjf/fsl-release-bsp/imx6q-x11/tmp/work/x86_64-linux/elfutils-native/0.164-r0$ 5. 一個一個文件修改比較麻煩,依據第4點,修改對應的yes為no就可以比較快捷的一次性全部解決問題,然而實際情況是沒有識別到ldlex和i386_lex,乖乖的手動刪除或者制作Shell腳本處理; 6. 自動化shell命令: 1. grep _no_Werror\) * -r | cut -d":" -f1 | xargs sed -i "s/[$](if [$]([$]([*F]*)_no_Werror),,-Werror)//" 2. grep _no_Werror\) * -r | cut -d":" -f1 | xargs sed -i "s/[$]([$]([*F]*)_no_Werror),,-Werror) [$](if//"