[Openmp-commits] [openmp] 96fcaf0 - [openmp] Fix building for mingw targets after import library changes

Martin Storsjö via Openmp-commits openmp-commits at lists.llvm.org
Tue Feb 14 14:49:01 PST 2023


Author: Martin Storsjö
Date: 2023-02-15T00:30:30+02:00
New Revision: 96fcaf0cc06a6f442b3e67a936ca04806bde1f03

URL: https://github.com/llvm/llvm-project/commit/96fcaf0cc06a6f442b3e67a936ca04806bde1f03
DIFF: https://github.com/llvm/llvm-project/commit/96fcaf0cc06a6f442b3e67a936ca04806bde1f03.diff

LOG: [openmp] Fix building for mingw targets after import library changes

06d9bf5e64d472db5485815d9c3f70631064bb25 (https://reviews.llvm.org/D143431)
did a large restructuring of how the import library is created;
previously, a second step to tweak the import library was only
done for MSVC style targets, but after this commit, that logic
was applied for mingw targets too.

Since LIBOMP_GENERATED_IMP_LIB_FILENAME and LIBOMP_IMP_LIB_FILE
are equal on mingw targets (both are "libomp.dll.a", while they
are "libomp.dll.lib" and "libomp.lib" for MSVC targets), this caused
a conflict, with errors like this:

  ninja: error: build.ninja:875: multiple rules generate runtime/src/libomp.dll.a [-w dupbuild=err]

Skip the logic with a second step to recreate the import library
for mingw targets. The MSVC specific logic for this relies on
running the static archiver with CMAKE_LINK_DEF_FILE_FLAG, which
with MS lib.exe (and llvm-lib) ignore the input object files and
just generates an import library - but mingw style tools don't
support this mode of operation. (By attemptinig the same, mingw tools
would generate a static library with the def file as one member.)
With mingw tools, the same can be achieved by invoking the dlltool
executable instead.

Instead of adding alternative logic for invoking dlltool, just skip
the second import library step, since neither GNU nor LLVM mingw
tools actually generate import libraries that link by ordinal - so
there's no need for a second import library.

Differential Revision: https://reviews.llvm.org/D143992

Added: 
    

Modified: 
    openmp/runtime/cmake/LibompMicroTests.cmake
    openmp/runtime/src/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/cmake/LibompMicroTests.cmake b/openmp/runtime/cmake/LibompMicroTests.cmake
index 12aef99dd9c20..88deb461dbaf3 100644
--- a/openmp/runtime/cmake/LibompMicroTests.cmake
+++ b/openmp/runtime/cmake/LibompMicroTests.cmake
@@ -40,7 +40,7 @@
 # get library location
 if(WIN32)
   get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
-  get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ompimp ARCHIVE_OUTPUT_DIRECTORY)
+  get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY)
   if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
     set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
   endif()

diff  --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index 94ba881e56002..aa087fe22312f 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -272,6 +272,12 @@ if(WIN32)
     ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}
   )
 
+  if(MSVC)
+    set(LIBOMP_IMP_LIB_TARGET ompimp)
+  else()
+    set(LIBOMP_IMP_LIB_TARGET omp)
+  endif()
+
   # Create def files to designate exported functions
   libomp_get_gdflags(LIBOMP_GDFLAGS) # generate-def.pl flags (Windows only)
   libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
@@ -289,18 +295,31 @@ if(WIN32)
     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
   )
 
-  # Regenerate the import library to import by name, not ordinal
-  add_library(ompimp STATIC ${LIBOMP_SOURCE_FILES})
-    set_target_properties(ompimp PROPERTIES
-      PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
-    LINKER_LANGUAGE C
-  )
-  set_target_properties(ompimp PROPERTIES STATIC_LIBRARY_OPTIONS 
-      "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE_IMP}"
-  )
-  add_dependencies(ompimp libomp-needed-headers)
-  
- 
+  if (MSVC)
+    # Regenerate the import library to import by name, not ordinal.
+    #
+    # For mingw, we can't regenerate an import library by passing
+    # CMAKE_LINK_DEF_FILE_FLAG to the static library archiver; that just
+    # ends up creating a regular static library that contains the def file.
+    # For mingw, we would have to call the suitable dlltool for regenerating
+    # an import library. However, neither GNU nor LLVM based mingw tools
+    # generate import libraries that actually link by ordinal, so this step
+    # isn't strictly necessary.
+    #
+    # Also, in mingw builds, LIBOMP_GENERATED_IMP_LIB_FILENAME and
+    # LIBOMP_IMP_LIB_FILE currently end up equal, while they need to 
diff er
+    # for this second step to work.
+    add_library(ompimp STATIC ${LIBOMP_SOURCE_FILES})
+      set_target_properties(ompimp PROPERTIES
+        PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
+      LINKER_LANGUAGE C
+    )
+    set_target_properties(ompimp PROPERTIES STATIC_LIBRARY_OPTIONS
+        "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE_IMP}"
+    )
+    add_dependencies(ompimp libomp-needed-headers)
+  endif()
+
 endif()
 
 # Building the Fortran module files
@@ -357,7 +376,7 @@ add_dependencies(libomp-micro-tests libomp-test-deps)
 # We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
 if(WIN32)
   install(TARGETS omp RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
-  install(TARGETS ompimp ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+  install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
   # Create aliases (regular copies) of the library for backwards compatibility
   set(LIBOMP_ALIASES "libiomp5md")
   foreach(alias IN LISTS LIBOMP_ALIASES)


        


More information about the Openmp-commits mailing list