Skip to content

Commit b08bfb2

Browse files
committed
backport drop-quadmath-symbol PR
1 parent acfae33 commit b08bfb2

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

.github/workflows/windows.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ jobs:
4545
echo "PLAT=i686" >> $env:GITHUB_ENV
4646
echo "WHEEL_PLAT=win32" >> $env:GITHUB_ENV
4747
echo "MSYSTEM=MINGW32" >> $env:GITHUB_ENV
48-
echo "LDFLAGS=-static -static-libgcc" >> $env:GITHUB_ENV
48+
# No ucrt on 32-bits, so use _snprintf_c instead
49+
echo "LDFLAGS=-static -static-libgcc -Wl,--defsym,_quadmath_snprintf=__snprintf_c" >> $env:GITHUB_ENV
4950
echo "BUILD_BITS=32" >> $env:GITHUB_ENV
5051
} else {
5152
echo "PLAT=x86_64" >> $env:GITHUB_ENV
5253
echo "WHEEL_PLAT=win_amd64" >> $env:GITHUB_ENV
5354
echo "MSYSTEM=UCRT64" >> $env:GITHUB_ENV
54-
echo "LDFLAGS=-lucrt -static -static-libgcc" >> $env:GITHUB_ENV
55+
echo "LDFLAGS=-lucrt -static -static-libgcc -Wl,--defsym,quadmath_snprintf=snprintf" >> $env:GITHUB_ENV
5556
echo "BUILD_BITS=64" >> $env:GITHUB_ENV
5657
}
5758
if ( ${{ matrix.INTERFACE64 }} -eq "1" ) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/exports/Makefile b/exports/Makefile
2+
index 668a4866e..956b51bf4 100644
3+
--- a/exports/Makefile
4+
+++ b/exports/Makefile
5+
@@ -126,8 +126,9 @@ dll : ../$(LIBDLLNAME)
6+
../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX)
7+
$(RANLIB) ../$(LIBNAME)
8+
$(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \
9+
- -shared -o ../$(LIBDLLNAME) -Wl,--out-implib,../$(IMPLIBNAME) \
10+
+ -shared -o ../$(LIBDLLNAME) -Wl,-gc-sections -Wl,-s -Wl,-Map,output.map \
11+
-Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB)
12+
+ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a
13+
14+
$(LIBPREFIX).def : $(GENSYM)
15+
./$(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)

tools/build_openblas.sh

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fflags="$fextra $cflags -frecursive -ffpe-summary=invalid,zero"
7676

7777
# Set suffixed-ILP64 flags
7878
if [ "$if_bits" == "64" ]; then
79-
SYMBOLSUFFIX="64_"
79+
LIBNAMESUFFIX="64_"
8080
interface_flags="INTERFACE64=1 SYMBOLSUFFIX=64_ LIBNAMESUFFIX=64_"
8181
# We override FCOMMON_OPT, so we need to set default integer manually
8282
fflags="$fflags -fdefault-integer-8"
@@ -90,8 +90,12 @@ interface_flags="$interface_flags SYMBOLPREFIX=scipy_ LIBNAMEPREFIX=scipy_ FIXED
9090
# Build name for output library from gcc version and OpenBLAS commit.
9191
GCC_TAG="gcc_$(gcc -dumpversion | tr .- _)"
9292
OPENBLAS_VERSION=$(git describe --tags --abbrev=8)
93+
94+
# Patch OpenBLAS build to resolve all symbols and avoid linking
95+
# with libquadmath
96+
patch -p1 < ../patches-windows/openblas-make-libs.patch
97+
9398
# Build OpenBLAS
94-
# Variable used in creating output libraries
9599
make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \
96100
NUM_THREADS=24 NO_WARMUP=1 NO_AFFINITY=1 CONSISTENT_FPCSR=1 \
97101
BUILD_LAPACK_DEPRECATED=1 TARGET=PRESCOTT BUFFERSIZE=20\
@@ -100,8 +104,38 @@ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \
100104
FCOMMON_OPT="$fflags" \
101105
MAX_STACK_ALLOC=2048 \
102106
$interface_flags
107+
108+
# Make sure quadmath library is not statically linked in to the DLL by checking
109+
# the output.map generated by the linker when using `-Wl,-gc-sections -Wl,-s`
110+
# the map will have libname(o-filename) for each function pulled out of the
111+
# library libname
112+
# The file itself appears in the map, so look for "libquadmath.a(". Use '-A 3'
113+
# to show a bit of context if any symbols appear (which should not happen)
114+
set +e
115+
grep -A 2 "libquadmath.a(" exports/output.map
116+
case $? in
117+
0)
118+
echo "link uses libquadmath.a when it should not"
119+
exit -1
120+
;;
121+
1)
122+
if [ -f exports/output.map ]; then
123+
echo "Good, verified no 'libquadmath' used when linking"
124+
else
125+
echo "error occurred"
126+
exit -1
127+
fi
128+
;;
129+
*)
130+
echo "grep returned $?, error occurred"
131+
exit -1
132+
;;
133+
esac
134+
set -e
135+
103136
make PREFIX=$openblas_root/$build_bits $interface_flags install
104-
DLL_BASENAME=libscipy_openblas${SYMBOLSUFFIX}${LIBNAMESUFFIX}
137+
DLL_BASENAME=libscipy_openblas${LIBNAMESUFFIX}
138+
cp -f *.dll.a $openblas_root/$build_bits/lib/${DLL_BASENAME}.dll.a
105139

106140
# OpenBLAS does not build a symbol-suffixed static library on Windows:
107141
# do it ourselves. On 32-bit builds, the objcopy.def names need a '_' prefix
@@ -143,16 +177,8 @@ else
143177
sed -e "s/^Cflags.*/\0 -DBLAS_SYMBOL_PREFIX=scipy_/" -i pkgconfig/scipy-openblas.pc
144178
fi
145179
popd
146-
# Build template site.cfg for using this build
147-
cat > ${build_bits}/site.cfg.template << EOF
148-
[openblas${SYMBOLSUFFIX}]
149-
libraries = $DLL_BASENAME
150-
library_dirs = {openblas_root}\\${build_bits}\\lib
151-
include_dirs = {openblas_root}\\${build_bits}\\include
152-
EOF
153-
154180
ls $openblas_root/$build_bits/lib
155181

156-
zip_name="openblas${SYMBOLSUFFIX}-${OPENBLAS_VERSION}-${plat_tag}-${GCC_TAG}.zip"
182+
zip_name="openblas${LIBNAMESUFFIX}-${OPENBLAS_VERSION}-${plat_tag}-${GCC_TAG}.zip"
157183
zip -r $zip_name $build_bits
158184
cp $zip_name ${builds_dir}

0 commit comments

Comments
 (0)