Hi. lang_print_memory_usage() at ld/ldlang.c calculates and displays the memory region usage as follows: 9282 percent = used_length * 100.0 / r->length; 9284 printf (" %6.2f%%\n", percent); If the memory region length is zero (denoted by r->length), this will cause division by zero. Likely no other harm is done, except not all printf implementations adhere to e.g. IEEE 1003.1 (POSIX specifications), causing some implementation specific format to be shown when a NaN is passed (or -NaN, given that the floating point implementation behaves as such). E.g. MinGW targets (as they use MS Visual C library) display `[-]1.#J' (`[-]1#IND' truncated to %6.2f). This might cause issues if a tool that uses the output data does not except this kind of behaviour (wouldn't call this undefined by any means).
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1769380a11463b907263ef5443de5d14559f2095 commit 1769380a11463b907263ef5443de5d14559f2095 Author: Alan Modra <amodra@gmail.com> Date: Thu Dec 5 16:37:25 2019 +1030 PR25244, --print-memory-usage, division by zero if MEMORY length is zero PR 25244 * ldlang.c (lang_print_memory_usage): Don't print percent used when length is zero.
Fixed.
I think there's a slight issue with this patch: It also omits the linefeed for that particular memory region, should the length be zero.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2410edcd3176d81d0ab8d24afe69f0d59649f69e commit 2410edcd3176d81d0ab8d24afe69f0d59649f69e Author: Alan Modra <amodra@gmail.com> Date: Thu Dec 5 21:29:21 2019 +1030 Re: PR25244, --print-memory-usage, division by zero if MEMORY length is zero Do print the linefeed when length is zero. PR 25244 * ldlang.c (lang_print_memory_usage): Correct last patch.
(In reply to Pekka Seppänen from comment #3) > I think there's a slight issue with this patch: It also omits the linefeed > for that particular memory region, should the length be zero. Thanks for noticiing.