setting CPU_TYPE when cross-compiling from Linux to Windows
Claude Heiland-Allen
claude at mathr.co.uk
Sun Dec 29 00:30:32 UTC 2019
Hi,
On 28/12/2019 23:52, Marc Glisse wrote:
> On Sat, 28 Dec 2019, Claude Heiland-Allen wrote:
>
>> I use Linux. I have a program (that uses GMP via MPFR) that I
>> cross-compile for Windows and run in Wine.
>>
>> I would like to test the new zen-specific optimizations on my AMD
>> Ryzen 7 2700X CPU, but I can't seem to get it to work:
>>
>> ```
>> hg clone https://gmplib.org/repo/gmp/
>> cd gmp
>> ./.bootstrap
>> GMP_CPU_TYPE="zen" \
>> CC_FOR_BUILD="gcc" \
>> CPP_FOR_BUILD="gcc -E" \
>> CFLAGS="-march=native -O3 -fomit-frame-pointer" \
>> CXXFLAGS="-march=native -O3 -fomit-frame-pointer" \
>> LDFLAGS="-static-libgcc -static-libstdc++" \
>> CPPFLAGS="-D__USE_MINGW_ANSI_STDIO" \
>> ./configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32 \
>> --prefix=/home/claude/winNATIVE
>> ...
>> config.status: linking mpn/x86_64/k8/gmp-mparam.h to gmp-mparam.h
>> config.status: executing libtool commands
>> configure: summary of build options:
>>
>> Version: GNU MP 6.1.99
>> Host type: x86_64-w64-mingw32
>> ABI: 64
>> Install prefix: /home/claude/winNATIVE
>> Compiler: x86_64-w64-mingw32-gcc
>> Static libraries: yes
>> Shared libraries: no
>>
>> configure: If wine64 is installed, use make check
>> TESTS_ENVIRONMENT=wine64.
>> ```
>>
>> Notice that it is linking `x86_64/k8` instead of `x86_64/zen`.
>>
>> Compiling natively on Linux with `GMP_CPU_TYPE=zen` works fine (and
>> some test programs are faster), but unfortunately my main program is
>> Windows-only. I do not have Microsoft Windows to test a native build
>> there.
>>
>> How can I do this?
>
> Hello,
>
> did you read the documentation?
> https://gmplib.org/manual/Build-Options.html indicates to use the host
> triplet to specify the cpu. Where did you read about this use of
> GMP_CPU_TYPE? As far as I can tell, it is only useful at runtime, and
> only if you have a fat build and passed some options to configure.
>
Thanks for the pointer to the manual, I should have checked that part of
it sooner.
However trying the method suggested in the documentation also fails, but
in a different way:
```
CC_FOR_BUILD="gcc" \
CPP_FOR_BUILD="gcc -E" \
CFLAGS="-march=native -O3 -fomit-frame-pointer" \
CXXFLAGS="-march=native -O3 -fomit-frame-pointer" \
LDFLAGS="-static-libgcc -static-libstdc++" \
CPPFLAGS="-D__USE_MINGW_ANSI_STDIO" \
./configure --build=zen-pc-linux-gnu --host=zen-w64-mingw32 \
--prefix=/home/claude/winNATIVE
...
config.status: linking mpn/x86_64/zen/gmp-mparam.h to gmp-mparam.h
config.status: executing libtool commands
configure: summary of build options:
Version: GNU MP 6.1.99
Host type: zen-w64-mingw32
ABI: 64
Install prefix: /home/claude/winNATIVE
Compiler: gcc
Static libraries: yes
Shared libraries: no
configure: If wine64 is installed, use make check TESTS_ENVIRONMENT=wine64.
```
Notice it uses compiler `gcc` instead of `x86_64-w64-mingw32-gcc`, which
leads to a build for Linux, not Windows.
Trying a fat build (thanks for the pointer to this method, I think it's
what I really need) also fails, at `make check`:
```
CC_FOR_BUILD="gcc" \
CPP_FOR_BUILD="gcc -E" \
CPPFLAGS="-D__USE_MINGW_ANSI_STDIO" \
./configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32 \
--enable-fat --prefix="/home/claude/winNATIVE"
...
config.status: linking mpn/x86_64/fat/gmp-mparam.h to gmp-mparam.h
config.status: executing libtool commands
configure: summary of build options:
Version: GNU MP 6.1.99
Host type: x86_64-w64-mingw32
ABI: 64
Install prefix: /home/claude/winNATIVE
Compiler: x86_64-w64-mingw32-gcc
Static libraries: yes
Shared libraries: no
configure: If wine64 is installed, use make check TESTS_ENVIRONMENT=wine64.
make
...
make check TESTS_ENVIRONMENT=wine64
make check-recursive
make[1]: Entering directory '/home/claude/winNATIVE/src/gmp'
Making check in tests
make[2]: Entering directory '/home/claude/winNATIVE/src/gmp/tests'
Making check in .
make[3]: Entering directory '/home/claude/winNATIVE/src/gmp/tests'
make t-bswap.exe t-constants.exe t-count_zeros.exe t-hightomask.exe
t-modlinv.exe t-popc.exe t-parity.exe t-sub.exe libtests.la
make[4]: Entering directory '/home/claude/winNATIVE/src/gmp/tests'
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2
-pedantic -fomit-frame-pointer -m64 -no-install -static-libgcc
-static-libstdc++ -o t-bswap.exe t-bswap.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer
-m64 -static-libgcc -static-libstdc++ -o t-bswap.exe t-bswap.o
./.libs/libtests.a /home/claude/winNATIVE/src/gmp/.libs/libgmp.a
../.libs/libgmp.a
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.o: in function `main':
t-bswap.c:(.text.startup+0xc): undefined reference to `tests_start'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0x17):
undefined reference to `mp_trace_base'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0x29):
undefined reference to `__gmpn_random'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0x33):
undefined reference to `ref_bswap_limb'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0x53):
undefined reference to `tests_end'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0x7a):
undefined reference to `mpn_trace'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0x90):
undefined reference to `mpn_trace'
/usr/bin/x86_64-w64-mingw32-ld: t-bswap.c:(.text.startup+0xa6):
undefined reference to `mpn_trace'
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:766: t-bswap.exe] Error 1
make[4]: Leaving directory '/home/claude/winNATIVE/src/gmp/tests'
make[3]: *** [Makefile:1187: check-am] Error 2
make[3]: Leaving directory '/home/claude/winNATIVE/src/gmp/tests'
make[2]: *** [Makefile:824: check-recursive] Error 1
make[2]: Leaving directory '/home/claude/winNATIVE/src/gmp/tests'
make[1]: *** [Makefile:995: check-recursive] Error 1
make[1]: Leaving directory '/home/claude/winNATIVE/src/gmp'
make: *** [Makefile:1290: check] Error 2
```
Trying a shared build also fails, but a bit earlier (at the DLL linking
step):
```
CC_FOR_BUILD="gcc" \
CPP_FOR_BUILD="gcc -E" \
CPPFLAGS="-D__USE_MINGW_ANSI_STDIO" \
./configure --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32 \
--disable-static --enable-shared --enable-fat \
--prefix="/home/claude/winNATIVE"
...
make
...
libtool: link: x86_64-w64-mingw32-gcc -shared mpn/.libs/x86_64_add_n.o
mpn/.libs/x86_64_addmul_1.o mpn/.libs/x86_64_bdiv_dbm1c.o
mpn/.libs/x86_64_com.o mpn/.libs/x86_64_cnd_add_n.o
mpn/.libs/x86_64_cnd_sub_n.o mpn/.libs/x86_64_copyd.o
mpn/.libs/x86_64_copyi.o mpn/.libs/x86_64_dive_1.o
mpn/.libs/x86_64_divrem_1.o mpn/.libs/x86_64_gcd_11.o
mpn/.libs/x86_64_lshift.o mpn/.libs/x86_64_lshiftc.o
mpn/.libs/x86_64_mod_1_1.o mpn/.libs/x86_64_mod_1_2.o
mpn/.libs/x86_64_mod_1_4.o mpn/.libs/x86_64_mod_34lsub1.o
mpn/.libs/x86_64_mode1o.o mpn/.libs/x86_64_mul_1.o
mpn/.libs/x86_64_rshift.o mpn/.libs/x86_64_sub_n.o
mpn/.libs/x86_64_submul_1.o mpn/.libs/x86_64_addlsh1_n.o
mpn/.libs/x86_64_addlsh2_n.o mpn/.libs/x86_64_sublsh1_n.o
mpn/.libs/fat_mod_1.o mpn/.libs/fat_mul_basecase.o
mpn/.libs/fat_mullo_basecase.o mpn/.libs/fat_redc_1.o
mpn/.libs/fat_redc_2.o mpn/.libs/fat_sqr_basecase.o
mpn/.libs/fat_addmul_2.o mpn/.libs/k8_mul_basecase.o
mpn/.libs/k8_mullo_basecase.o mpn/.libs/k8_redc_1.o
mpn/.libs/k8_sqr_basecase.o mpn/.libs/k8_addmul_2.o
mpn/.libs/k10_gcd_11.o mpn/.libs/k10_lshift.o mpn/.libs/k10_lshiftc.o
mpn/.libs/k10_rshift.o mpn/.libs/bd1_add_n.o mpn/.libs/bd1_addmul_1.o
mpn/.libs/bd1_com.o mpn/.libs/bd1_copyd.o mpn/.libs/bd1_copyi.o
mpn/.libs/bd1_gcd_11.o mpn/.libs/bd1_mul_1.o
mpn/.libs/bd1_mul_basecase.o mpn/.libs/bd1_sub_n.o
mpn/.libs/bd1_submul_1.o mpn/.libs/bd1_addmul_2.o
mpn/.libs/bd1_addlsh1_n.o mpn/.libs/bd1_sublsh1_n.o
mpn/.libs/bt1_add_n.o mpn/.libs/bt1_addmul_1.o mpn/.libs/bt1_copyd.o
mpn/.libs/bt1_copyi.o mpn/.libs/bt1_gcd_11.o mpn/.libs/bt1_mul_1.o
mpn/.libs/bt1_mul_basecase.o mpn/.libs/bt1_redc_1.o
mpn/.libs/bt1_sqr_basecase.o mpn/.libs/bt1_sub_n.o
mpn/.libs/bt1_submul_1.o mpn/.libs/bt2_com.o mpn/.libs/bt2_copyd.o
mpn/.libs/bt2_copyi.o mpn/.libs/bt2_gcd_11.o mpn/.libs/zen_addmul_1.o
mpn/.libs/zen_com.o mpn/.libs/zen_copyd.o mpn/.libs/zen_copyi.o
mpn/.libs/zen_gcd_11.o mpn/.libs/zen_lshift.o mpn/.libs/zen_lshiftc.o
mpn/.libs/zen_mul_1.o mpn/.libs/zen_mul_basecase.o
mpn/.libs/zen_mullo_basecase.o mpn/.libs/zen_rshift.o
mpn/.libs/zen_sqr_basecase.o mpn/.libs/zen_submul_1.o
mpn/.libs/zen_addlsh1_n.o mpn/.libs/zen_sublsh1_n.o mpn/.libs/p4_add_n.o
mpn/.libs/p4_addmul_1.o mpn/.libs/p4_lshift.o mpn/.libs/p4_lshiftc.o
mpn/.libs/p4_mod_34lsub1.o mpn/.libs/p4_mul_1.o
mpn/.libs/p4_mul_basecase.o mpn/.libs/p4_mullo_basecase.o
mpn/.libs/p4_redc_1.o mpn/.libs/p4_rshift.o mpn/.libs/p4_sqr_basecase.o
mpn/.libs/p4_sub_n.o mpn/.libs/p4_submul_1.o mpn/.libs/p4_addmul_2.o
mpn/.libs/p4_addlsh1_n.o mpn/.libs/p4_addlsh2_n.o
mpn/.libs/p4_sublsh1_n.o mpn/.libs/core2_add_n.o
mpn/.libs/core2_addmul_1.o mpn/.libs/core2_com.o mpn/.libs/core2_copyd.o
mpn/.libs/core2_copyi.o mpn/.libs/core2_divrem_1.o
mpn/.libs/core2_gcd_11.o mpn/.libs/core2_lshift.o
mpn/.libs/core2_lshiftc.o mpn/.libs/core2_mul_basecase.o
mpn/.libs/core2_mullo_basecase.o mpn/.libs/core2_redc_1.o
mpn/.libs/core2_rshift.o mpn/.libs/core2_sqr_basecase.o
mpn/.libs/core2_sub_n.o mpn/.libs/core2_submul_1.o
mpn/.libs/core2_addlsh1_n.o mpn/.libs/core2_addlsh2_n.o
mpn/.libs/core2_sublsh1_n.o mpn/.libs/coreinhm_addmul_1.o
mpn/.libs/coreinhm_redc_1.o mpn/.libs/coreinhm_submul_1.o
mpn/.libs/coreisbr_add_n.o mpn/.libs/coreisbr_addmul_1.o
mpn/.libs/coreisbr_cnd_add_n.o mpn/.libs/coreisbr_cnd_sub_n.o
mpn/.libs/coreisbr_divrem_1.o mpn/.libs/coreisbr_gcd_11.o
mpn/.libs/coreisbr_lshift.o mpn/.libs/coreisbr_lshiftc.o
mpn/.libs/coreisbr_mul_1.o mpn/.libs/coreisbr_mul_basecase.o
mpn/.libs/coreisbr_mullo_basecase.o mpn/.libs/coreisbr_redc_1.o
mpn/.libs/coreisbr_rshift.o mpn/.libs/coreisbr_sqr_basecase.o
mpn/.libs/coreisbr_sub_n.o mpn/.libs/coreisbr_submul_1.o
mpn/.libs/coreisbr_addmul_2.o mpn/.libs/coreisbr_addlsh1_n.o
mpn/.libs/coreisbr_addlsh2_n.o mpn/.libs/coreihwl_add_n.o
mpn/.libs/coreihwl_addmul_1.o mpn/.libs/coreihwl_mul_1.o
mpn/.libs/coreihwl_mul_basecase.o mpn/.libs/coreihwl_mullo_basecase.o
mpn/.libs/coreihwl_redc_1.o mpn/.libs/coreihwl_sqr_basecase.o
mpn/.libs/coreihwl_sub_n.o mpn/.libs/coreihwl_submul_1.o
mpn/.libs/coreihwl_addmul_2.o mpn/.libs/coreibwl_addmul_1.o
mpn/.libs/coreibwl_mul_basecase.o mpn/.libs/coreibwl_mullo_basecase.o
mpn/.libs/coreibwl_sqr_basecase.o mpn/.libs/atom_add_n.o
mpn/.libs/atom_addmul_1.o mpn/.libs/atom_com.o
mpn/.libs/atom_cnd_add_n.o mpn/.libs/atom_cnd_sub_n.o
mpn/.libs/atom_copyd.o mpn/.libs/atom_copyi.o mpn/.libs/atom_dive_1.o
mpn/.libs/atom_lshift.o mpn/.libs/atom_lshiftc.o mpn/.libs/atom_mul_1.o
mpn/.libs/atom_redc_1.o mpn/.libs/atom_rshift.o mpn/.libs/atom_sub_n.o
mpn/.libs/atom_submul_1.o mpn/.libs/atom_addmul_2.o
mpn/.libs/atom_addlsh1_n.o mpn/.libs/atom_addlsh2_n.o
mpn/.libs/atom_sublsh1_n.o mpn/.libs/silvermont_add_n.o
mpn/.libs/silvermont_addmul_1.o mpn/.libs/silvermont_lshift.o
mpn/.libs/silvermont_lshiftc.o mpn/.libs/silvermont_mul_1.o
mpn/.libs/silvermont_mul_basecase.o
mpn/.libs/silvermont_mullo_basecase.o mpn/.libs/silvermont_rshift.o
mpn/.libs/silvermont_sqr_basecase.o mpn/.libs/silvermont_sub_n.o
mpn/.libs/silvermont_submul_1.o mpn/.libs/silvermont_addlsh1_n.o
mpn/.libs/silvermont_addlsh2_n.o mpn/.libs/goldmont_add_n.o
mpn/.libs/goldmont_addmul_1.o mpn/.libs/goldmont_mul_1.o
mpn/.libs/goldmont_redc_1.o mpn/.libs/goldmont_sub_n.o
mpn/.libs/goldmont_submul_1.o mpn/.libs/nano_copyd.o
mpn/.libs/nano_copyi.o mpn/.libs/nano_dive_1.o
mpn/.libs/nano_gcd_11.o -O2 -m64 -Wl,--export-all-symbols
-Wl,--output-def -Wl,.libs/libgmp-3.dll.def -o .libs/libgmp-10.dll
-Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker
.libs/libgmp.dll.a
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_dive_1.o:fake:(.text+0x28): undefined reference to
`__gmp_binvert_limb_table'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_divrem_1.o:fake:(.text+0xb9): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_divrem_1.o:fake:(.text+0x158): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_mod_1_1.o:fake:(.text+0x106): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_mod_1_2.o:fake:(.text+0x196): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_mod_1_4.o:fake:(.text+0x1b6): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/x86_64_mode1o.o:fake:(.text+0x28): undefined reference to
`__gmp_binvert_limb_table'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_mod_1.o:fat_mod_1.c:(.text+0x7f): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_mod_1.o:fat_mod_1.c:(.text+0x15f): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_mul_basecase.o:fat_mul_basecase.c:(.text+0x48): undefined
reference to `__gmpn_mul_2'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_mul_basecase.o:fat_mul_basecase.c:(.rdata$.refptr.__gmpn_cpuvec[.refptr.__gmpn_cpuvec]+0x0):
undefined reference to `__gmpn_cpuvec'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_sqr_basecase.o:fat_sqr_basecase.c:(.text+0x4e1): undefined
reference to `__gmpn_cpuvec_init'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_sqr_basecase.o:fat_sqr_basecase.c:(.text+0x551): undefined
reference to `__gmpn_mul_2'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/fat_sqr_basecase.o:fat_sqr_basecase.c:(.rdata$.refptr.__gmpn_cpuvec_initialized[.refptr.__gmpn_cpuvec_initialized]+0x0):
undefined reference to `__gmpn_cpuvec_initialized'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/bt1_redc_1.o:fake:(.text+0x238): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/p4_redc_1.o:fake:(.text+0x238): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/core2_divrem_1.o:fake:(.text+0xad): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/core2_redc_1.o:fake:(.text+0x296): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/coreinhm_redc_1.o:fake:(.text+0x2b9): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/coreisbr_divrem_1.o:fake:(.text+0xb9): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/coreisbr_divrem_1.o:fake:(.text+0x158): undefined reference to
`__gmpn_invert_limb'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/coreisbr_redc_1.o:fake:(.text+0x2b2): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/coreihwl_redc_1.o:fake:(.text+0x4ba): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/atom_dive_1.o:fake:(.text+0x2f): undefined reference to
`__gmp_binvert_limb_table'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/atom_redc_1.o:fake:(.text+0x286): undefined reference to
`__gmpn_add_n'
/usr/bin/x86_64-w64-mingw32-ld:
mpn/.libs/nano_dive_1.o:fake:(.text+0x2f): undefined reference to
`__gmp_binvert_limb_table'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:880: libgmp.la] Error 1
make[2]: Leaving directory '/home/claude/winNATIVE/src/gmp'
make[1]: *** [Makefile:995: all-recursive] Error 1
make[1]: Leaving directory '/home/claude/winNATIVE/src/gmp'
make: *** [Makefile:785: all] Error 2
```
Thanks for any advice,
Claude
--
https://mathr.co.uk
More information about the gmp-bugs
mailing list