Object file has too many sections

前端 未结 4 1073
滥情空心
滥情空心 2020-12-01 07:28

We am making heavy use of boost::serialization and templates in general. All seems to be going well.

Except, we\'ve hit a snag on our Windows builds. It seems to cau

相关标签:
4条回答
  • 2020-12-01 08:00

    The solution is to add the option -Wa,-mbig-obj if your version of GCC supports that option. You probably only need it during the compilation step, not the linker step.

    If your compiler does not support that option, you should look into using mingw-w64 and MSYS2.

    0 讨论(0)
  • 2020-12-01 08:00

    The error "%B: too many sections (%d)" comes from the function coff_compute_section_file_positions() located in bfd/coffcode.h. It's produced when the output .obj file (in COFF format) contains more than 32766 sections. There is no way to avoid this error, at least not if you want to use Windows' PE/COFF object format; COFF files use only two bytes for "NumberOfSections" in the file header.

    It's not clear to me why as (the GNU assembler) caps the number of sections at 32768-minus-2, instead of 65536-minus-1 (section 0 is reserved); but either way, that might not be enough if you're making heavy use of templates and your compiler implements templates via COMDAT sections.

    As you've already noticed, passing /bigobj to Microsoft's compiler causes it to output a munged COFF format with up to 231 sections, which "should be enough for anybody." However, the munged format is formally undocumented, and I don't see any informal documentation (blog posts or what-have-you) on the subject, so until someone with a copy of MSVC can write up a specification for /bigobj, it doesn't stand much chance of getting into the GNU tools.

    IMHO, if you're trying to make a Windows build, you should just bite the bullet and use MSVC. Nobody besides Microsoft is particularly motivated to waste time wrestling with the PE/COFF format.

    0 讨论(0)
  • 2020-12-01 08:00

    I found some updates in this matter, it seems to be fixed in new binutils for x64 windows, see https://sourceware.org/ml/binutils/2014-03/msg00114.html and http://sourceforge.net/p/mingw-w64/bugs/341/. However, I did not test it as this fix does not apply to 32 bit versions I need.

    0 讨论(0)
  • 2020-12-01 08:17

    I faced the same problem when I compiled Poco library with MinGW-w64, it turned out that debug object was huge for one implementation file.

    As you mentioned before you can split up cpp files and it will work, but when you face with someone's source code you can't do that without breaking something.

    As a solution you can turn on compiler optimisations: start with -O1 up to -O3, with each step it will build smaller object file, it may solve the problem, it did in my case. Yes, for debug builds it may be undesirable, you can try -Og as well

    0 讨论(0)
提交回复
热议问题