Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I got 'duplicate section' errors when compiling boost_regex with size optimization (-Os)

compiler: http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.2/32-bit/threads-posix/sjlj/x32-4.7.2-release-posix-sjlj-rev6.7z

boost: http://sourceforge.net/projects/boost/files/boost/1.52.0/boost_1_52_0.7z

(both on D: drive)

boost_regex compiled with:

b2 --prefix=D:\boost toolset=gcc --with-regex --layout=tagged release

code:

#include <boost\regex.hpp>
int main() {
  boost::regex reg("[a-z]+");
}

compiled with parameters:

g++ -I "d:\boost" -Os -o test.exe test.cpp -static -L d:\boost\stage\lib -lboost_regex-mt

error:

d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_baseE[__ZTSN5boost16exception_detail10clone_baseE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size

It compiles ok, but I haven't yet tested if it will be working in more complex code. Removing the -Os switch clears the error but app size is 2x bigger then.

Maybe I should build Boost with size optimization too also but I don't know where to pass this option in b2 command line.

like image 841
rsk82 Avatar asked Jan 06 '13 10:01

rsk82


2 Answers

In my case boost 1.58 was internally compiling with "-march=i686", but my code wasn't. Adding "-march=i686" to my project got rid of all "duplicate section".

lesson learned: always make painstakingly sure that all libraries and the main project are compiled with identical compiler options.

like image 105
user4808204 Avatar answered Oct 10 '22 17:10

user4808204


I believe this is a compiler bug. The workaround in my case was to add -fno-tree-vectorize.

like image 21
Lorenzo Pistone Avatar answered Oct 10 '22 17:10

Lorenzo Pistone