当前位置: 首页 > news >正文

a multiple definition link error when using gcc10.3.1

1 环境说明

硬件环境:LS1046A   arm64 

系统环境:openEuler release 22.03 (LTS-SP1)   gcc10.3.1

2 问题现象

一个客户在设备上编译 Suricata 3.1.1 时发现链接时有很多  multiple definition 的错误,

类似如下:

/usr/bin/ld: decode-sctp.o:/root/suricata-3.1.1/src/suricata.h:129: multiple definition of `data_queues';alert-debuglog.o:/root/suricata-3.1.1/src/suricata.h:129: first defined here
/usr/bin/ld: decode-sctp.o:/root/suricata-3.1.1/src/suricata.h:127: multiple definition of `trans_q'; alert-debuglog.o:/root/suricata-3.1.1/src/suricata.h:127: first defined here

3 复现步骤

wget http://www.openinfosecfoundation.org/download/suricata-3.1.1.tar.gzyum makecachednf install -y gcc libpcap-devel pcre-devel libyaml-devel file-devel \zlib-devel jansson-devel nss-devel libcap-ng-devel libnet-devel tar make \libnetfilter_queue-devel lua-devel  libmaxminddb-devel rustc cargo \lz4-devel libnfnetlink-devel 修改suricata的一个内核兼容性问题,否则会报错:在文件src/source-af-packet.c 添加 #include <linux/sockios.h>cd suricata-3.1.1
./configure
make -j8--->
问题multiple definition 海量出现/usr/bin/ld: decode-sctp.o:/root/suricata-3.1.1/src/suricata.h:129: multiple definition of `data_queues';alert-debuglog.o:/root/suricata-3.1.1/src/suricata.h:129: first defined here
/usr/bin/ld: decode-sctp.o:/root/suricata-3.1.1/src/suricata.h:127: multiple definition of `trans_q'; alert-debuglog.o:/root/suricata-3.1.1/src/suricata.h:127: first defined here

4 测试和排查

Ubuntu 20.04.6 LTS  +  gcc version 9.4.0  (X86/ARM64)+ suricata-3.1.1  编译测试OK

openEuler release 22.03 (LTS-SP1) 原装系统内核 + gcc-10.3.1   + suricata-3.1.1  编译测试失败

openEuler release 22.03 (LTS-SP1)   + gcc-9.3 + + suricata-3.1.1  编译测试 OK

 关于如何给gcc降低版本,可以参考如下:

dnf search gcc 看不到低版本gcc 所以只能手动安装https://archives.openeuler.openatom.cn/openEuler-20.09/source/Packages/wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/gcc-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/gcc-c%2B%2B-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/gcc-gfortran-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/libquadmath-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/libquadmath-devel-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/libstdc%2B%2B-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/libgomp-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/cpp-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/libstdc%2B%2B-devel-9.3.1-20200922.12.oe1.aarch64.rpm
wget https://archives.openeuler.openatom.cn/openEuler-20.09/OS/aarch64/Packages/libgfortran-9.3.1-20200922.12.oe1.aarch64.rpmdnf remove gccrpm -Uvh --force *.rpm

综上应该是和gcc有关,查看 gcc10的 changelog 

GCC 10 Release Series — Changes, New Features, and Fixes- GNU Project

That documents the change in default behaviour from -fcommon (before 10.1.0) to -fno-common (10.1.0 onwards). 

 GCC now defaults to -fno-common. As a result, global variable accesses are more efficient on various targets. In C, global variables with multiple tentative definitions now result in linker errors. With -fcommon such definitions are silently merged during linking.

关于 gcc 编译选项 -fcommon    -fno-common的解释:

-fcommon
In C code, this option controls the placement of global variables defined without an initializer, known as tentative definitions in the C standard. Tentative definitions are distinct from declarations of a variable with the extern keyword, which do not allocate storage.

The default is -fno-common, which specifies that the compiler places uninitialized global variables in the BSS section of the object file. This inhibits the merging of tentative definitions by the linker so you get a multiple-definition error if the same variable is accidentally defined in more than one compilation unit.

The -fcommon places uninitialized global variables in a common block.This allows the linker to resolve all tentative definitions of the same variable in different compilation units to the same object,  or to a non-tentative definition. This behavior is inconsistent with C++, and on many targets implies a speed and code size penalty on global variable references. It is mainly useful to enable legacy code to link without errors.

 

5 解决方法

编译前执行 export CFLAGS+=-fcommon

相关文章:

  • 关于HTTP劫持,该如何理解、防范和应对
  • 『这世界上有无忧无虑的孩子,和永远焦虑的父母』
  • 使用ESP32和Flask框架实现温湿度数据监测系统
  • AI音乐大模型时代:版权归属与创意产业的新生长点
  • 华为---OSPF单区域配置(一)
  • KaTex在博客中显示数学公式
  • CPU飙升100%怎么办?字节跳动面试官告诉你答案!
  • LeetCode26. 删除有序数组中的重复项题解
  • 【Linux】基础IO_3
  • 【C++11】initializer_list详解!
  • NSSCTF-Web题目14
  • 前端 JS 经典:通用性函数封装思路
  • 常见的创建型设计模式( 一 )
  • 数据结构之探索“队列”的奥秘
  • vue elementui table给表格中满足条件的每一条记录添加计时器
  • JavaScript-如何实现克隆(clone)函数
  • “大数据应用场景”之隔壁老王(连载四)
  • 【跃迁之路】【669天】程序员高效学习方法论探索系列(实验阶段426-2018.12.13)...
  • HTTP--网络协议分层,http历史(二)
  • Java 23种设计模式 之单例模式 7种实现方式
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • JS实现简单的MVC模式开发小游戏
  • k8s 面向应用开发者的基础命令
  • Laravel核心解读--Facades
  • Linux后台研发超实用命令总结
  • MaxCompute访问TableStore(OTS) 数据
  • python 学习笔记 - Queue Pipes,进程间通讯
  • seaborn 安装成功 + ImportError: DLL load failed: 找不到指定的模块 问题解决
  • 构造函数(constructor)与原型链(prototype)关系
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 计算机在识别图像时“看到”了什么?
  • 浅谈Kotlin实战篇之自定义View图片圆角简单应用(一)
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 一文看透浏览器架构
  • 第二十章:异步和文件I/O.(二十三)
  • ​二进制运算符:(与运算)、|(或运算)、~(取反运算)、^(异或运算)、位移运算符​
  • # Java NIO(一)FileChannel
  • #window11设置系统变量#
  • #考研#计算机文化知识1(局域网及网络互联)
  • #知识分享#笔记#学习方法
  • (10)Linux冯诺依曼结构操作系统的再次理解
  • (Oracle)SQL优化技巧(一):分页查询
  • (第27天)Oracle 数据泵转换分区表
  • (附源码)spring boot儿童教育管理系统 毕业设计 281442
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (附源码)spring boot校园拼车微信小程序 毕业设计 091617
  • (函数)颠倒字符串顺序(C语言)
  • (九十四)函数和二维数组
  • (七)Appdesigner-初步入门及常用组件的使用方法说明
  • (提供数据集下载)基于大语言模型LangChain与ChatGLM3-6B本地知识库调优:数据集优化、参数调整、Prompt提示词优化实战
  • (一一四)第九章编程练习
  • (正则)提取页面里的img标签
  • .bat批处理(七):PC端从手机内复制文件到本地
  • .md即markdown文件的基本常用编写语法