Bug 29218

Summary: libiberty cannot find __imp___acrt_iob_func for x86_64-w64-mingw32 cross toolchain for canadian compilation
Product: binutils Reporter: cqwrteur <euloanty>
Component: binutilsAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WORKSFORME    
Severity: normal CC: amodra, euloanty
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: x86_64-w64-mingw32 Target: i586-msdosdjgp
Build: x86_64-linux-gnu Last reconfirmed:
Attachments: config file

Description cqwrteur 2022-06-01 17:10:17 UTC
/usr/local/lib/gcc/x86_64-pc-linux-gnu/13.0.0/../../../../x86_64-pc-linux-gnu/bin/ld: ../libiberty/libiberty.a(xmalloc.o): in function `fprintf':
/home/cqwrteur/toolchains/native/x86_64-w64-mingw32/x86_64-w64-mingw32/include/stdio.h:361: undefined reference to `__mingw_vfprintf'
/usr/local/lib/gcc/x86_64-pc-linux-gnu/13.0.0/../../../../x86_64-pc-linux-gnu/bin/ld: ../libiberty/libiberty.a(xmalloc.o): in function `xmalloc_failed':
/home/cqwrteur/toolchains_build/build/x86_64-w64-mingw32/i586-msdosdjgpp/binutils-gdb/libiberty/../../../../../binutils-gdb/libiberty/xmalloc.c:134: undefined reference to `__imp___acrt_iob_func'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:2488: doc/chew.stamp] Error 1
make[3]: Leaving directory '/home/cqwrteur/toolchains_build/build/x86_64-w64-mingw32/i586-msdosdjgpp/binutils-gdb/bfd'
make[2]: *** [Makefile:1939: info-recursive] Error 1
make[2]: Leaving directory '/home/cqwrteur/toolchains_build/build/x86_64-w64-mingw32/i586-msdosdjgpp/binutils-gdb/bfd'
make[1]: *** [Makefile:3071: all-bfd] Error 2
make[1]: *** Waiting for unfinished jobs....
yes
Comment 1 cqwrteur 2022-06-01 17:13:23 UTC
Created attachment 14128 [details]
config file
Comment 2 cqwrteur 2022-06-01 17:46:22 UTC
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=7273d78f3f7ae3701512f1ff423430f51b011ece

I believe it breaks because of this commitment. It makes the binary compiled with the build compiler instead of the host compiler.

It completely breaks Canadian compilation.
Comment 3 cqwrteur 2022-06-01 17:48:04 UTC
BTW. The xmalloc thing should be just __builtin_trap(). No more debugging information and recovery thank you.
Comment 4 cqwrteur 2022-06-01 17:49:06 UTC
void* xmalloc(size_t sz) noexcept
{
    void* ptr = malloc(sz);
    if(!ptr)
        __builtin_trap();
    return ptr;
}

Thank you. Since stdio on mingw-w64 bloats binary size.
Comment 5 cqwrteur 2022-06-01 17:53:11 UTC
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=b0de9ed86f3af84fbd636f94a58b9c4ad7f4e743

well it looks like this does not fix Canadian compilation.
Comment 6 Alan Modra 2022-06-01 23:13:10 UTC
I can build the canadian cross you describe, using
~/src/binutils-gdb/configure \
--target=i586-msdosdjgpp --host=x86_64-w64-mingw32 --build=x86_64-linux-gnu \
--disable-gdb --disable-gdbserver --disable-sim --disable-readline \
--disable-libdecnumber --disable-libbacktrace --disable-gprofng --disable-nls

$ file bfd/doc/chew
bfd/doc/chew: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=e68ec21e6eb9b489db730e2731ec73932e74c9b0, for GNU/Linux 3.2.0, not stripped
$ file gas/as-new.exe 
gas/as-new.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows

And yes, I also see a fail to link bfd/doc/chew if I use source checked out at commit 739f9506642.