[PATCH] D159404: [flang/mlir] Fix "file too big" build error on CYGWIN.

Carlo Bramini via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 02:19:19 PDT 2023


carlo-bramini updated this revision to Diff 556537.
carlo-bramini added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

> Prove me wrong and test this code in cmake:

Well, this is not the way I'm using MSVC for building CYGWIN applications but perhaps you could do it by using a toolchain script file. Probably, with a simple implementation, CMake won't be even able to configure because MSDOS and UNIX paths have different syntax, which can be bypassed by writing something similar to VCPKG so, in any case, this wouldn't be so immediate. But it seems it is no more important.

In the last days, I compiled llvm-project with MinGW-w64 from CYGWIN.
This is a cross-compilation actually, so this is the toolchain file used for configuring CMake.
I made it available for reference here, if somebody will want to use this build environment:

  # The name of the target operating system.
  SET(CMAKE_SYSTEM_NAME Windows)
  
  # Force the version of the system.
  #SET(CMAKE_SYSTEM_VERSION 10)
  
  # The classical MinGW-32 (http://www.mingw.org/)
  #SET(TOOLCHAIN_PREFIX "i586-mingw32msvc")
  
  # 32 or 64 bits MinGW-w64 (http://mingw-w64.sourceforge.net/)
  #SET(TOOLCHAIN_PREFIX "i686-w64-mingw32")
  SET(TOOLCHAIN_PREFIX "x86_64-w64-mingw32")
  
  # Toolchain path prefix (CYGWIN cross compiler)
  SET(COMPILER_PREFIX ${TOOLCHAIN_PREFIX}/sys-root/mingw)
  
  # Toolchain path prefix (standard prefix)
  #SET(COMPILER_PREFIX ${TOOLCHAIN_PREFIX})
  
  SET(PKG_CONFIG_EXECUTABLE ${TOOLCHAIN_PREFIX}-pkg-config)
  
  # Compilers to use for C and C++
  FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${TOOLCHAIN_PREFIX}-gcc)
  FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${TOOLCHAIN_PREFIX}-g++)
  FIND_PROGRAM(CMAKE_RC_COMPILER NAMES ${TOOLCHAIN_PREFIX}-windres)
  
  # Path to the target environment
  SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX})
  
  # Adjust the default behaviour of the FIND_XXX() commands:
  # search headers and libraries in the target environment, search 
  # programs in the host environment
  SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  
  #SET(CMAKE_SYSTEM_PROCESSOR x86)
  SET(CMAKE_SYSTEM_PROCESSOR x64)

This is made for building for 64bit, but it possible to compile for 32bit by changing some comments inside.

With MinGW-w64, the sources were compiled successfully, no more "too many sections" and "File too big" errors.
I got other errors and I have seen some strange things when doing this cross compilation, but not the ones signaled into the above issues.
Running Ninja in verbose mode, I discovered that "-Wa,-mbig-obj" is already feed into the flags.
Searching into the sources, I found this:

https://github.com/llvm/llvm-project/blob/88348252a60e22dacde9cf92a0767e9f89c2e287/llvm/cmake/modules/HandleLLVMOptions.cmake#L466

Here, the "-Wa,-mbig-obj" option is added and here, few lines above this point:

https://github.com/llvm/llvm-project/blob/88348252a60e22dacde9cf92a0767e9f89c2e287/llvm/cmake/modules/HandleLLVMOptions.cmake#L461

there is the if statement that allows to add it.
So, I replaced it with:

  elseif(MINGW OR CYGWIN)

I recompiled the sources after this change and it worked fine also on CYGWIN.
So, about these issues:

https://github.com/llvm/llvm-project/issues/63582
https://github.com/llvm/llvm-project/issues/57718
https://github.com/llvm/llvm-project/issues/51143

it looks like that they were **already** fixed, but nobody tested and/or closed them. Is it possible?
I removed the definition of _GNU_SOURCE, which was a copy/paste from here:

https://github.com/llvm/llvm-project/blob/53602e6193d98b1e814b76a27e99ef7e18c9769c/third-party/benchmark/CMakeLists.txt#L230

I will add it into a different patch, since it is probably off-topic here.
About the existing "-Wa,-mbig-obj" option into llvm/cmake/modules/HandleLLVMOptions.cmake, I don't know if it is good for both normal and standalone builds, but if it had been accepted for MINGW, I expect that it would be ok also for CYGWIN.

It also seems to me that this global "-Wa,-mbig-obj" increased the build time of llvm.
>From 3 hours, now it required about 4 hours for completing the build on my PC, but perhaps it's just normal.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159404/new/

https://reviews.llvm.org/D159404

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -458,7 +458,7 @@
   # value (1 MB) which is not enough for us in tasks such as parsing recursive
   # C++ templates in Clang.
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
-elseif(MINGW) # FIXME: Also cygwin?
+elseif(MINGW OR CYGWIN)
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,16777216")
 
   # Pass -mbig-obj to mingw gas to avoid COFF 2**16 section limit.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159404.556537.patch
Type: text/x-patch
Size: 628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230912/e6adb6b0/attachment.bin>


More information about the llvm-commits mailing list