On Windows objcopy fails to split debug info with --only-keep-debug when this debug information is bigger than 2 GB. This is because of the following code in bfd_malloc(): if (size != sz /* This is to pacify memory checkers like valgrind. */ || ((signed long) sz) < 0) { bfd_set_error (bfd_error_no_memory); return NULL; } On mingw32 target sizeof(long) is 4 bytes which makes < 0 condition invalid.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cb87d9f1a49986b2eb92ac381444f4cc7c9d8a4f commit cb87d9f1a49986b2eb92ac381444f4cc7c9d8a4f Author: Alan Modra <amodra@gmail.com> Date: Fri Dec 28 09:34:28 2018 +1030 PR23966, mingw failure due to 32-bit long PR 23966 * libbfd.c (SSIZE_MAX): Define. (bfd_malloc, bfd_realloc): Don't cast size to long to check for "negative" values, compare against SSIZE_MAX instead.
The bfd_malloc bug is now fixed.