Subject: bug#39009: checking command to parse /usr/bin/nm -B output from gcc object... failed

From: Martin Liška <[email-masked]>
Date: Tue, 7 Jan 2020 14:31:25 +0100

Hello.

nm -B detection fails to be detected with -flto and -fno-common CFLAGS:

configure:6307: checking command to parse /usr/bin/nm -B output from gcc object
configure:6460: gcc -c -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -fno-common -flto  conftest.c >&5
configure:6463: $? = 0
configure:6467: /usr/bin/nm -B conftest.o \| sed -n -e 's/^.*[ ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[ ][ ]*\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2 \2/p' | sed '/ __gnu_lto/d' \> conftest.nm
configure:6470: $? = 0
configure:6536: gcc -o conftest -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -fno-common -flto  -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -fno-common -flto conftest.c conftstm.o >&5
conftest.c:18:12: error: variable 'nm_test_var' redeclared as function
    18 | extern int nm_test_var();
       |            ^
conftest.c:4:6: note: previously declared here
     4 |    relocations are performed -- see ld's documentation on pseudo-relocs.  */
       |      ^
lto1: fatal error: errors during merging of translation units
compilation terminated.
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
configure:6539: $? = 1

As seen, I bet problem is in conftstm.o file (for which I can't see how it's created). Probably the file is missing
declaration of nm_test_var and so that it's implicitly deduced to be int nm_test_var().

Thanks,
Martin