
环境环境Ubuntu 18.04 (官方推荐)Ubuntu 24.04我的wslGCC7.x13.3binutils2.302.42glibc2.272.39Linux-xlnx2020.22020.2现象minglieming:/home/wpf/workspace/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2$makeHOSTLD scripts/dtc/dtc /usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss0x20): multiple definition of yylloc;scripts/dtc/dtc-lexer.lex.o:(.bss0x0): first defined here collect2: error: ld returned1exitstatus make[1]: ***[scripts/Makefile.host:116: scripts/dtc/dtc]Error1make: ***[Makefile:1263: scripts_dtc]Error2旧版 Linux 内核5.4 Xilinx 2020.2和新版 Ubuntu/WSL 的 flex/bison 不兼容yylloc 全局变量被定义了两次dtc-parser.tab.o 定义了一次 yyllocdtc-lexer.lex.o 又定义了一次 yyllocGCC 10 有个编译选项-fcommon 和 -fno-common对比项-fcommonGCC 10 以前默认-fno-commonGCC 10 以后默认默认版本GCC 10GCC ≥ 10对未初始化全局变量int x;的处理生成 Common Symbol生成真正的全局变量定义多个源文件都有int x;链接器自动合并链接时报错nm查看符号CCommonBBSS或DData是否容易隐藏 Bug是否是否符合现代 C 工程规范较宽松更严格、更推荐Linux 新版本支持情况已逐渐淘汰官方推荐gcc编译选项minglieming$ gcc-Q--helpcommon|grepcommon-fcommon[disabled]-fpredictive-commoning[disabled]-funconstrained-commons[disabled]修改scripts/dtc/dtc-lexer.l重新编译# scripts/dtc/dtc-lexer.l 的 26行# YYLTYPE yylloc; 改为 extern YYLTYPE yylloc;$vimscripts/dtc/dtc-lexer.l# 重新编译makemrpropermakexilinx_zynq_defconfigmake-j$(nproc)# 或者# 删除 dtc 的生成文件rm-fscripts/dtc/dtcrm-fscripts/dtc/*.orm-fscripts/dtc/*.tab.*rm-fscripts/dtc/*.lex.c# 重新编译make-j$(nproc)