LLVM Build Error: Target object too big

While trying to assemble a particular input file, my build system failed because
the target object was too big. I calculated that the input source file after
preprocessing would be about 3.91Mb.

system: CYGWIN_NT-10.0 x86_64 Cygwin
file: llvm-master/lib/Passes/PassBuilder.cpp

build output:
    Scanning dependencies of target LLVMPasses
    [ 84%] Building CXX object
CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o: too many sections (55165)
    /tmp/cc9ADbCA.s: Assembler messages:
    /tmp/cc9ADbCA.s: Fatal error: can't write
CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o: File too big
CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o: too many sections (55165)
    /tmp/cc9ADbCA.s: Fatal error: can't close
CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o: File too big
    make[2]: *** [lib/Passes/CMakeFiles/LLVMPasses.dir/build.make:63:
lib/Passes/CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o] Error 1
    make[1]: *** [CMakeFiles/Makefile2:17896:
lib/Passes/CMakeFiles/LLVMPasses.dir/all] Error 2
    make: *** [Makefile:150: all] Error 2

compiler version:
    $ gcc -v
    Using built-in specs.
    Target: x86_64-pc-cygwin
    Configured with:
--prefix=/usr --exec-prefix=/usr --localstatedir=/var
--sysconfdir=/etc --docdir=/usr/share/doc/gcc
--htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin
--host=x86_64-pc-cygwin --target=x86_64-pc-cygwin
--without-libiconv-prefix --without-libintl-prefix
--libexecdir=/usr/lib --enable-shared --enable-shared-libgcc
--enable-static --enable-version-specific-runtime-libs
--enable-bootstrap --enable-__cxa_atexit --with-dwarf2
--enable-graphite --enable-threads=posix --enable-libatomic
--enable-libcilkrts --enable-libgomp --enable-libitm
--enable-libquadmath --enable-libquadmath-support --enable-libssp
--enable-libada --enable-libgcj-sublibs --disable-java-awt
--disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld
--with-gnu-as --with-cloog-include=/usr/include/cloog-isl
--without-libiconv-prefix --without-libintl-prefix --with-system-zlib
--enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible
    Thread model: posix
    gcc version 5.4.0 (GCC)

    $ as -v
    GNU assembler version 2.25.2 (x86_64-pc-cygwin) using BFD version
(GNU Binutils) 2.25.2

    $ make -v
    GNU Make 4.2.1
    Built for x86_64-unknown-cygwin
    Copyright (C) 1988-2016 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    $ cmake --version
    cmake version 3.6.2

    CMake suite maintained and supported by Kitware (kitware.com/cmake).

What I've tried so far:
    CFLAGS="-Wa,-mbig-obj" make

But still same error.

I tried -Wa

I think this is the correct solution, but putting CFLAGS into the environment while running make or re-running cmake isn’t enough to get flags through to the compiler. I’d recommend doing something like make VERBOSE=1 lib/Passes/CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o to extract the single failing compile command, manually add -Wa,-mbig-obj, rerun, and see if the problem goes away.

Lastly, assuming that fixes PassBuilder.cpp.o, you’ll need to enable it globally. We already enable it for mingw here:
We can definitely tweak those conditions to include Cygwin as the FIXME says, but you can see that obviously nobody has built LLVM this way for quite some time. Expect to run into more issues. Consider switching to mingw or mvsc if possible.

It has been a good number of years here since running Cygwin or Mingw (better) under Windows. Eventually used a free copy of VMWare (there are likely other options now) to create a Linux VM under Windows. You can then choose most any Linux distribution and click back and forth between Windows and Linux.

Regards, Neil Nelson