https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81487
Bug ID: 81487 Summary: [mingw32] ld.exe: error: asprintf failed Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: gjl at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- Compiling a trivial program fails: int main() { return 0; } $ avr-gcc simple.c -mmcu=atmega8 -v Using built-in specs. Reading specs from e:/winavr/8.0_2017-07-18/bin/../lib/gcc/avr/8.0.0/device-specs/specs-atmega8 COLLECT_GCC=e:/WinAVR/8.0_2017-07-18/bin/avr-gcc COLLECT_LTO_WRAPPER=e:/winavr/8.0_2017-07-18/bin/../libexec/gcc/avr/8.0.0/lto-wrapper.exe Target: avr Configured with: ../../gcc.gnu.org/trunk/configure --target=avr --disable-nls --prefix=/local/gnu/install/gcc-8-avr-mingw32 --host=i686-w64-mingw32 --build=x86_64-linux-gnu --enable-languages=c,c++,lto --with-gnu-as --with-gnu-ld --disable-shared --with-dwarf2 --enable-checking=release Thread model: single gcc version 8.0.0 20170718 (experimental) [trunk revision 244001] (GCC) ... e:/winavr/8.0_2017-07-18/bin/../lib/gcc/avr/8.0.0/../../../../avr/bin/ld.exe: error: asprintf failed collect2.exe: error: ld returned 1 exit status The caller is lto-plugin.c::claim_file_handler() if (file->offset != 0) { char *objname; /* We pass the offset of the actual file, not the archive header. Can't use PRIx64, because that's C99, so we have to print the 64-bit hex int as two 32-bit ones. */ int lo, hi, t; lo = file->offset & 0xffffffff; hi = ((int64_t)file->offset >> 32) & 0xffffffff; t = hi ? asprintf (&objname, "%s@0x%x%08x", file->name, lo, hi) : asprintf (&objname, "%s@0x%x", file->name, lo); check (t >= 0, LDPL_FATAL, "asprintf failed"); lto_file.name = objname; } Presumably, the problem is caused by a broken asprintf host implementation which returns -1 for a string of length 46. So it would be nice to use a working implementation like xasprintf from libiberty. Apart from that, the ordering of lo and hi in asprintf (&objname, "%s@0x%x%08x", file->name, lo, hi) looks wrong. The arguments should be "file->name, hi, lo" to get a correct 64-bit value if hi != 0.