From c3d84068f868c10035ee903981feccdc82c110a2 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Sat, 25 Jun 2022 13:20:14 +0100 Subject: [PATCH 01/12] WIP: patch OpenBLAS build for quadmath symbols Apply Carl's patch to OpenBLAS export build of library, to remove libquatmath symbol. See: https://github.com/MacPython/openblas-libs/pull/82#issuecomment-1161869998 --- patches-windows/openblas-make-libs.patch | 27 ++++++++++++++++++++++++ tools/build_openblas.sh | 5 +++++ 2 files changed, 32 insertions(+) create mode 100644 patches-windows/openblas-make-libs.patch diff --git a/patches-windows/openblas-make-libs.patch b/patches-windows/openblas-make-libs.patch new file mode 100644 index 00000000..6b0526da --- /dev/null +++ b/patches-windows/openblas-make-libs.patch @@ -0,0 +1,27 @@ +diff --git a/exports/Makefile b/exports/Makefile +index d8173534..4e2e0d7b 100644 +--- a/exports/Makefile ++++ b/exports/Makefile +@@ -119,11 +119,21 @@ dll : ../$(LIBDLLNAME) + # in their import table. By instead using a stable name it is possible to + # upgrade between library versions, without needing to re-link an application. + # For more details see: https://github.com/xianyi/OpenBLAS/issues/127. ++ifeq ($(DEBUG), 1) + ../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX) + $(RANLIB) ../$(LIBNAME) + $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ +- -shared -o ../$(LIBDLLNAME) -Wl,--out-implib,../$(IMPLIBNAME) \ ++ -shared -o ../$(LIBDLLNAME) -Wl,--defsym,quadmath_snprintf=snprintf \ + -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) ++ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a ++else ++../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX) ++ $(RANLIB) ../$(LIBNAME) ++ $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ ++ -shared -o ../$(LIBDLLNAME) -Wl,--defsym,quadmath_snprintf=snprintf -Wl,-gc-sections -Wl,-s \ ++ -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) ++ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a ++endif + + $(LIBPREFIX).def : $(GENSYM) + ./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index 253c6366..e10d543c 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -90,6 +90,11 @@ interface_flags="$interface_flags SYMBOLPREFIX=scipy_ LIBNAMEPREFIX=scipy_ FIXED # Build name for output library from gcc version and OpenBLAS commit. GCC_TAG="gcc_$(gcc -dumpversion | tr .- _)" OPENBLAS_VERSION=$(git describe --tags --abbrev=8) +# Patch OpenBLAS to exclude stray GFortran symbol. +# Replacement snprintf symbol only present for UCRTC 64-bit build. +if [ "$BUILD_BITS" == 64 ]; then + patch -p1 < ../patches-windows/openblas-make-libs.patch +fi # Build OpenBLAS # Variable used in creating output libraries make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ From 5c98be1590815014444ac62e6c80eaab6c665525 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Wed, 31 Jul 2024 22:17:41 +0300 Subject: [PATCH 02/12] add windows_build.bat to build locally --- tools/windows_build.bat | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tools/windows_build.bat diff --git a/tools/windows_build.bat b/tools/windows_build.bat new file mode 100644 index 00000000..0a358607 --- /dev/null +++ b/tools/windows_build.bat @@ -0,0 +1,13 @@ +rem Build x86_64 OpenBLAS locally with 64-bit interfaces +rem Requires c:\rtools40 +set BASH_PATH=c:\rtools40\usr\bin\bash.exe +set BUILD_BITS=64 +set CHERE_INVOKING=yes +set INTERFACE64=1 +set LDFLAGS=-lucrt -static -static-libgcc -Wl,--defsym,quadmath_snprintf=snprintf +set MSYSTEM=UCRT64 +set PLAT=x86_64 +set START_DIR=d:\pypy_stuff\openblas-libs +rmdir /q /s c:\opt\64 +rmdir /q /s c:\opt\64 +rem %BASH_PATH% -lc tools/build_openblas.sh From e7d27fb43dc28a400ea21b1fb9f1dbb1a3cb4b43 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Wed, 31 Jul 2024 22:22:56 +0300 Subject: [PATCH 03/12] update patch --- patches-windows/openblas-make-libs.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches-windows/openblas-make-libs.patch b/patches-windows/openblas-make-libs.patch index 6b0526da..ae002a24 100644 --- a/patches-windows/openblas-make-libs.patch +++ b/patches-windows/openblas-make-libs.patch @@ -2,7 +2,7 @@ diff --git a/exports/Makefile b/exports/Makefile index d8173534..4e2e0d7b 100644 --- a/exports/Makefile +++ b/exports/Makefile -@@ -119,11 +119,21 @@ dll : ../$(LIBDLLNAME) +@@ -123,11 +123,21 @@ dll : ../$(LIBDLLNAME) # in their import table. By instead using a stable name it is possible to # upgrade between library versions, without needing to re-link an application. # For more details see: https://github.com/xianyi/OpenBLAS/issues/127. From 2df815f260f4b5b071dac6de949e56c69c664cb9 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Sun, 4 Aug 2024 09:20:35 +0300 Subject: [PATCH 04/12] copy mingw import lib to OPENBLAS_ROOT for dynamic gfortran test --- tools/build_openblas.sh | 1 + tools/windows_build.bat | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index e10d543c..92336a33 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -106,6 +106,7 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ MAX_STACK_ALLOC=2048 \ $interface_flags make PREFIX=$openblas_root/$build_bits $interface_flags install +cp -f "*.dll.a" "$openblas_root/$build_bits/lib/" DLL_BASENAME=libscipy_openblas${SYMBOLSUFFIX}${LIBNAMESUFFIX} # OpenBLAS does not build a symbol-suffixed static library on Windows: diff --git a/tools/windows_build.bat b/tools/windows_build.bat index 0a358607..2ecc9286 100644 --- a/tools/windows_build.bat +++ b/tools/windows_build.bat @@ -8,6 +8,7 @@ set LDFLAGS=-lucrt -static -static-libgcc -Wl,--defsym,quadmath_snprintf=snprint set MSYSTEM=UCRT64 set PLAT=x86_64 set START_DIR=d:\pypy_stuff\openblas-libs -rmdir /q /s c:\opt\64 +set OPENBLAS_ROOT=c:\\opt rmdir /q /s c:\opt\64 rem %BASH_PATH% -lc tools/build_openblas.sh +rem %BASH_PATH% -lc tools/build_gfortran.sh From 380e3c37eb60b236696a92ae9f58d4fdcea8bd5d Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Sun, 4 Aug 2024 14:48:44 +0300 Subject: [PATCH 05/12] add debug --- tools/build_openblas.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index 92336a33..a1bc80d1 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -106,6 +106,7 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ MAX_STACK_ALLOC=2048 \ $interface_flags make PREFIX=$openblas_root/$build_bits $interface_flags install +ls -l . cp -f "*.dll.a" "$openblas_root/$build_bits/lib/" DLL_BASENAME=libscipy_openblas${SYMBOLSUFFIX}${LIBNAMESUFFIX} From 8fa61bc5f93124ee57d506d607426d04432395dc Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Sun, 4 Aug 2024 17:22:15 +0300 Subject: [PATCH 06/12] fix up copy --- tools/build_openblas.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index a1bc80d1..d8eb9e37 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -106,9 +106,8 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ MAX_STACK_ALLOC=2048 \ $interface_flags make PREFIX=$openblas_root/$build_bits $interface_flags install -ls -l . -cp -f "*.dll.a" "$openblas_root/$build_bits/lib/" DLL_BASENAME=libscipy_openblas${SYMBOLSUFFIX}${LIBNAMESUFFIX} +cp -f "${DLL_BASENAME}.dll.a" "$openblas_root/$build_bits/lib/" # OpenBLAS does not build a symbol-suffixed static library on Windows: # do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix From 12a2b7bcf742aee50e7363e24c38756b73cabfb7 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Sun, 4 Aug 2024 19:32:01 +0300 Subject: [PATCH 07/12] fix copy for 32-bit --- tools/build_openblas.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index d8eb9e37..84d69beb 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -106,8 +106,13 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ MAX_STACK_ALLOC=2048 \ $interface_flags make PREFIX=$openblas_root/$build_bits $interface_flags install -DLL_BASENAME=libscipy_openblas${SYMBOLSUFFIX}${LIBNAMESUFFIX} -cp -f "${DLL_BASENAME}.dll.a" "$openblas_root/$build_bits/lib/" +DLL_BASENAME=libscipy_openblas${LIBNAMESUFFIX} +if [ -f "${DLL_BASENAME}.dll.a" ]; then + cp -f "${DLL_BASENAME}.dll.a" "$openblas_root/$build_bits/lib/" +else + # 32-bit build somehow does not put scipy_ into the import lib name + cp -f "libopenblas.dll.a" "$openblas_root/$build_bits/lib/" +fi # OpenBLAS does not build a symbol-suffixed static library on Windows: # do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix From 261b95e4edb924b32b83ab04859b031b5ab75d75 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Tue, 6 Aug 2024 00:29:25 +0300 Subject: [PATCH 08/12] redo patch, ensure libquadmath is not used in static link --- patches-windows/openblas-make-libs.patch | 32 +++++---------- tools/build_openblas.sh | 50 +++++++++++++++--------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/patches-windows/openblas-make-libs.patch b/patches-windows/openblas-make-libs.patch index ae002a24..19ee74c9 100644 --- a/patches-windows/openblas-make-libs.patch +++ b/patches-windows/openblas-make-libs.patch @@ -1,27 +1,15 @@ diff --git a/exports/Makefile b/exports/Makefile -index d8173534..4e2e0d7b 100644 +index 668a4866e..956b51bf4 100644 --- a/exports/Makefile +++ b/exports/Makefile -@@ -123,11 +123,21 @@ dll : ../$(LIBDLLNAME) - # in their import table. By instead using a stable name it is possible to - # upgrade between library versions, without needing to re-link an application. - # For more details see: https://github.com/xianyi/OpenBLAS/issues/127. -+ifeq ($(DEBUG), 1) +@@ -126,8 +126,9 @@ dll : ../$(LIBDLLNAME) ../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX) - $(RANLIB) ../$(LIBNAME) - $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ -- -shared -o ../$(LIBDLLNAME) -Wl,--out-implib,../$(IMPLIBNAME) \ -+ -shared -o ../$(LIBDLLNAME) -Wl,--defsym,quadmath_snprintf=snprintf \ - -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) -+ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a -+else -+../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX) -+ $(RANLIB) ../$(LIBNAME) -+ $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ -+ -shared -o ../$(LIBDLLNAME) -Wl,--defsym,quadmath_snprintf=snprintf -Wl,-gc-sections -Wl,-s \ -+ -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) -+ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a -+endif - + $(RANLIB) ../$(LIBNAME) + $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ +- -shared -o ../$(LIBDLLNAME) -Wl,--out-implib,../$(IMPLIBNAME) \ ++ -shared -o ../$(LIBDLLNAME) -Wl,-gc-sections -Wl,-s -Wl,-Map,output.map \ + -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) ++ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a + $(LIBPREFIX).def : $(GENSYM) - ./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F) + ./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index 84d69beb..a9663f67 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -49,12 +49,12 @@ git submodule update --init --recursive # Get / clean code -git fetch origin -if [ -n "$OPENBLAS_COMMIT" ]; then - git checkout $OPENBLAS_COMMIT -fi -git clean -fxd -git reset --hard +# git fetch origin +# if [ -n "$OPENBLAS_COMMIT" ]; then +# git checkout $OPENBLAS_COMMIT +# fi +# git clean -fxd +# git reset --hard rm -rf $openblas_root/$build_bits # Set architecture flags @@ -76,7 +76,7 @@ fflags="$fextra $cflags -frecursive -ffpe-summary=invalid,zero" # Set suffixed-ILP64 flags if [ "$if_bits" == "64" ]; then - SYMBOLSUFFIX="64_" + LIBNAMESUFFIX="64_" interface_flags="INTERFACE64=1 SYMBOLSUFFIX=64_ LIBNAMESUFFIX=64_" # We override FCOMMON_OPT, so we need to set default integer manually fflags="$fflags -fdefault-integer-8" @@ -92,9 +92,9 @@ GCC_TAG="gcc_$(gcc -dumpversion | tr .- _)" OPENBLAS_VERSION=$(git describe --tags --abbrev=8) # Patch OpenBLAS to exclude stray GFortran symbol. # Replacement snprintf symbol only present for UCRTC 64-bit build. -if [ "$BUILD_BITS" == 64 ]; then - patch -p1 < ../patches-windows/openblas-make-libs.patch -fi +# if [ "$BUILD_BITS" == 64 ]; then +# patch -p1 < ../patches-windows/openblas-make-libs.patch +# fi # Build OpenBLAS # Variable used in creating output libraries make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ @@ -132,6 +132,26 @@ objcopy --redefine-syms exports/objcopy.def "${static_libname}" "${static_libnam cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${static_libname}" cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${DLL_BASENAME}.a" +# Make sure quadmath library is not statically linked in to the DLL by checking +# the output.map generated by the linker when using `-Wl,-gc-sections -Wl,-s` +# the map will have libname(o-filename) for each function pulled out of the +# library +# The file itself appears in the map +grep -A 3 "libquadmath.a(" output.map +case $? in + 0) + echo "link uses libquadmath.a when it should not" + exit -1 + ;; + 2) + echo "could not find 'output.map' to verify linking avoids libquadmath.a" + exit -1 + ;; + 1) + echo "verified no 'libquadmath' used when linking" + ;; +esac + cd $openblas_root # Copy library link file for custom name pushd $build_bits/lib @@ -154,16 +174,8 @@ else sed -e "s/^Cflags.*/\0 -DBLAS_SYMBOL_PREFIX=scipy_/" -i pkgconfig/scipy-openblas.pc fi popd -# Build template site.cfg for using this build -cat > ${build_bits}/site.cfg.template << EOF -[openblas${SYMBOLSUFFIX}] -libraries = $DLL_BASENAME -library_dirs = {openblas_root}\\${build_bits}\\lib -include_dirs = {openblas_root}\\${build_bits}\\include -EOF - ls $openblas_root/$build_bits/lib -zip_name="openblas${SYMBOLSUFFIX}-${OPENBLAS_VERSION}-${plat_tag}-${GCC_TAG}.zip" +zip_name="openblas${LIBNAMESUFFIX}-${OPENBLAS_VERSION}-${plat_tag}-${GCC_TAG}.zip" zip -r $zip_name $build_bits cp $zip_name ${builds_dir} From 3aefe4843854906ca524f3e96383c4590daa8d26 Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 6 Aug 2024 06:47:30 +0300 Subject: [PATCH 09/12] copy dll.a differently --- patches-windows/openblas-make-libs.patch | 16 +++++------ tools/build_openblas.sh | 35 ++++++++++++------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/patches-windows/openblas-make-libs.patch b/patches-windows/openblas-make-libs.patch index 19ee74c9..1e4d4aeb 100644 --- a/patches-windows/openblas-make-libs.patch +++ b/patches-windows/openblas-make-libs.patch @@ -4,12 +4,12 @@ index 668a4866e..956b51bf4 100644 +++ b/exports/Makefile @@ -126,8 +126,9 @@ dll : ../$(LIBDLLNAME) ../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX) - $(RANLIB) ../$(LIBNAME) - $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ -- -shared -o ../$(LIBDLLNAME) -Wl,--out-implib,../$(IMPLIBNAME) \ -+ -shared -o ../$(LIBDLLNAME) -Wl,-gc-sections -Wl,-s -Wl,-Map,output.map \ - -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) -+ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a - + $(RANLIB) ../$(LIBNAME) + $(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \ +- -shared -o ../$(LIBDLLNAME) -Wl,--out-implib,../$(IMPLIBNAME) \ ++ -shared -o ../$(LIBDLLNAME) -Wl,-gc-sections -Wl,-s -Wl,-Map,output.map \ + -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB) ++ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a + $(LIBPREFIX).def : $(GENSYM) - ./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F) + ./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index a9663f67..884d0662 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -49,12 +49,12 @@ git submodule update --init --recursive # Get / clean code -# git fetch origin -# if [ -n "$OPENBLAS_COMMIT" ]; then -# git checkout $OPENBLAS_COMMIT -# fi -# git clean -fxd -# git reset --hard +git fetch origin +if [ -n "$OPENBLAS_COMMIT" ]; then + git checkout $OPENBLAS_COMMIT +fi +git clean -fxd +git reset --hard rm -rf $openblas_root/$build_bits # Set architecture flags @@ -90,13 +90,14 @@ interface_flags="$interface_flags SYMBOLPREFIX=scipy_ LIBNAMEPREFIX=scipy_ FIXED # Build name for output library from gcc version and OpenBLAS commit. GCC_TAG="gcc_$(gcc -dumpversion | tr .- _)" OPENBLAS_VERSION=$(git describe --tags --abbrev=8) -# Patch OpenBLAS to exclude stray GFortran symbol. -# Replacement snprintf symbol only present for UCRTC 64-bit build. -# if [ "$BUILD_BITS" == 64 ]; then -# patch -p1 < ../patches-windows/openblas-make-libs.patch -# fi + +# Patch OpenBLAS build to resolve all symbols and avoid linking +# with libquadmath +if [ "$BUILD_BITS" == 64 ]; then + patch -p1 < ../patches-windows/openblas-make-libs.patch +fi + # Build OpenBLAS -# Variable used in creating output libraries make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ NUM_THREADS=24 NO_WARMUP=1 NO_AFFINITY=1 CONSISTENT_FPCSR=1 \ BUILD_LAPACK_DEPRECATED=1 TARGET=PRESCOTT BUFFERSIZE=20\ @@ -107,12 +108,10 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ $interface_flags make PREFIX=$openblas_root/$build_bits $interface_flags install DLL_BASENAME=libscipy_openblas${LIBNAMESUFFIX} -if [ -f "${DLL_BASENAME}.dll.a" ]; then - cp -f "${DLL_BASENAME}.dll.a" "$openblas_root/$build_bits/lib/" -else - # 32-bit build somehow does not put scipy_ into the import lib name - cp -f "libopenblas.dll.a" "$openblas_root/$build_bits/lib/" -fi +echo ------ +ls *.dll.a +echo ------ +cp -f *.dll.a $openblas_root/$build_bits/lib/{DLL_BASENAME}.dll.a # OpenBLAS does not build a symbol-suffixed static library on Windows: # do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix From e0ab028a239a85e5058c015b2f47daf29d964107 Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 6 Aug 2024 14:31:14 +0300 Subject: [PATCH 10/12] fix up grep result checking, use patch on 32-bit --- tools/build_openblas.sh | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index 884d0662..6d6677f2 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -93,9 +93,7 @@ OPENBLAS_VERSION=$(git describe --tags --abbrev=8) # Patch OpenBLAS build to resolve all symbols and avoid linking # with libquadmath -if [ "$BUILD_BITS" == 64 ]; then - patch -p1 < ../patches-windows/openblas-make-libs.patch -fi +patch -p1 < ../patches-windows/openblas-make-libs.patch # Build OpenBLAS make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ @@ -108,10 +106,7 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ $interface_flags make PREFIX=$openblas_root/$build_bits $interface_flags install DLL_BASENAME=libscipy_openblas${LIBNAMESUFFIX} -echo ------ -ls *.dll.a -echo ------ -cp -f *.dll.a $openblas_root/$build_bits/lib/{DLL_BASENAME}.dll.a +cp -f *.dll.a $openblas_root/$build_bits/lib/${DLL_BASENAME}.dll.a # OpenBLAS does not build a symbol-suffixed static library on Windows: # do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix @@ -134,22 +129,30 @@ cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${DLL_BASENAME # Make sure quadmath library is not statically linked in to the DLL by checking # the output.map generated by the linker when using `-Wl,-gc-sections -Wl,-s` # the map will have libname(o-filename) for each function pulled out of the -# library -# The file itself appears in the map -grep -A 3 "libquadmath.a(" output.map +# library libname +# The file itself appears in the map, so look for "libquadmath.a(". Use '-A 3' +# to show a bit of context if any symbols appear (which should not happen) +set +e +grep -A 3 "libquadmath.a(" exports/output.map case $? in 0) - echo "link uses libquadmath.a when it should not" - exit -1 - ;; - 2) - echo "could not find 'output.map' to verify linking avoids libquadmath.a" - exit -1 + echo "link uses libquadmath.a when it should not" + exit -1 ;; 1) - echo "verified no 'libquadmath' used when linking" + if [ -f exports/output.map ]; then + echo "Good, verified no 'libquadmath' used when linking" + else + echo "error occurred" + exit -1 + fi + ;; + *) + echo "grep returned $?, error occurred" + exit -1 ;; esac +set -e cd $openblas_root # Copy library link file for custom name From ba8119236f9296290e33f366d752932e322e3599 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Tue, 6 Aug 2024 18:09:00 +0300 Subject: [PATCH 11/12] add link flag --- .github/workflows/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 88051fb4..4330db27 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -45,13 +45,13 @@ jobs: echo "PLAT=i686" >> $env:GITHUB_ENV echo "WHEEL_PLAT=win32" >> $env:GITHUB_ENV echo "MSYSTEM=MINGW32" >> $env:GITHUB_ENV - echo "LDFLAGS=-static -static-libgcc" >> $env:GITHUB_ENV + echo "LDFLAGS=-static -static-libgcc -Wl,--defsym,quadmath_snprintf=snprintf" >> $env:GITHUB_ENV echo "BUILD_BITS=32" >> $env:GITHUB_ENV } else { echo "PLAT=x86_64" >> $env:GITHUB_ENV echo "WHEEL_PLAT=win_amd64" >> $env:GITHUB_ENV echo "MSYSTEM=UCRT64" >> $env:GITHUB_ENV - echo "LDFLAGS=-lucrt -static -static-libgcc" >> $env:GITHUB_ENV + echo "LDFLAGS=-lucrt -static -static-libgcc -Wl,--defsym,quadmath_snprintf=snprintf" >> $env:GITHUB_ENV echo "BUILD_BITS=64" >> $env:GITHUB_ENV } if ( ${{ matrix.INTERFACE64 }} -eq "1" ) { From 791e0ea00439571ef0f582ef4ff64b9507839e41 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Wed, 7 Aug 2024 16:29:33 +0300 Subject: [PATCH 12/12] redefine symbols for 32-bit windows build --- .github/workflows/windows.yml | 3 ++- tools/build_openblas.sh | 45 ++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 4330db27..08ef9720 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -45,7 +45,8 @@ jobs: echo "PLAT=i686" >> $env:GITHUB_ENV echo "WHEEL_PLAT=win32" >> $env:GITHUB_ENV echo "MSYSTEM=MINGW32" >> $env:GITHUB_ENV - echo "LDFLAGS=-static -static-libgcc -Wl,--defsym,quadmath_snprintf=snprintf" >> $env:GITHUB_ENV + # No ucrt on 32-bits, so use _snprintf_c instead + echo "LDFLAGS=-static -static-libgcc -Wl,--defsym,_quadmath_snprintf=__snprintf_c" >> $env:GITHUB_ENV echo "BUILD_BITS=32" >> $env:GITHUB_ENV } else { echo "PLAT=x86_64" >> $env:GITHUB_ENV diff --git a/tools/build_openblas.sh b/tools/build_openblas.sh index 6d6677f2..f9992994 100644 --- a/tools/build_openblas.sh +++ b/tools/build_openblas.sh @@ -104,27 +104,6 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \ FCOMMON_OPT="$fflags" \ MAX_STACK_ALLOC=2048 \ $interface_flags -make PREFIX=$openblas_root/$build_bits $interface_flags install -DLL_BASENAME=libscipy_openblas${LIBNAMESUFFIX} -cp -f *.dll.a $openblas_root/$build_bits/lib/${DLL_BASENAME}.dll.a - -# OpenBLAS does not build a symbol-suffixed static library on Windows: -# do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix -static_libname=$(find . -maxdepth 1 -type f -name '*.a' \! -name '*.dll.a' | tail -1) -make -C exports $interface_flags objcopy.def - -if [ "$build_bits" == "32" ]; then - sed -i "s/^/_/" exports/objcopy.def - sed -i "s/scipy_/_scipy_/" exports/objcopy.def -else - echo not updating objcopy,def, buildbits=$build_bits -fi -echo "\nshow some of objcopy.def" -head -10 exports/objcopy.def -echo -objcopy --redefine-syms exports/objcopy.def "${static_libname}" "${static_libname}.renamed" -cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${static_libname}" -cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${DLL_BASENAME}.a" # Make sure quadmath library is not statically linked in to the DLL by checking # the output.map generated by the linker when using `-Wl,-gc-sections -Wl,-s` @@ -133,7 +112,7 @@ cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${DLL_BASENAME # The file itself appears in the map, so look for "libquadmath.a(". Use '-A 3' # to show a bit of context if any symbols appear (which should not happen) set +e -grep -A 3 "libquadmath.a(" exports/output.map +grep -A 2 "libquadmath.a(" exports/output.map case $? in 0) echo "link uses libquadmath.a when it should not" @@ -154,6 +133,28 @@ case $? in esac set -e +make PREFIX=$openblas_root/$build_bits $interface_flags install +DLL_BASENAME=libscipy_openblas${LIBNAMESUFFIX} +cp -f *.dll.a $openblas_root/$build_bits/lib/${DLL_BASENAME}.dll.a + +# OpenBLAS does not build a symbol-suffixed static library on Windows: +# do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix +static_libname=$(find . -maxdepth 1 -type f -name '*.a' \! -name '*.dll.a' | tail -1) +make -C exports $interface_flags objcopy.def + +if [ "$build_bits" == "32" ]; then + sed -i "s/^/_/" exports/objcopy.def + sed -i "s/scipy_/_scipy_/" exports/objcopy.def +else + echo not updating objcopy,def, buildbits=$build_bits +fi +echo "\nshow some of objcopy.def" +head -10 exports/objcopy.def +echo +objcopy --redefine-syms exports/objcopy.def "${static_libname}" "${static_libname}.renamed" +cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${static_libname}" +cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${DLL_BASENAME}.a" + cd $openblas_root # Copy library link file for custom name pushd $build_bits/lib