kyz/libmspack

configure / libtool fails with -flto

dilyanpalauzov opened this issue · 12 comments

Complinig libmspack 1.9.1 prints:

make V=1

make  all-am
make[1]: Entering directory '/src/mail/libmspack-1.9.1/libmspack'
/bin/sh ./libtool  --tag=CC   --mode=link gcc -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -flto -pipe -O3 -export-symbols-regex '^mspac
k_' -version-info 1:0:1 -no-undefined -flto=6 -Wl,-O1,-s -o libmspack.la -rpath /usr/local/lib mspack/system.lo mspack/cabc.lo mspack/cabd.lo mspa
ck/chmc.lo mspack/chmd.lo mspack/hlpc.lo mspack/hlpd.lo mspack/litc.lo mspack/litd.lo mspack/kwajc.lo mspack/kwajd.lo mspack/szddc.lo mspack/szddd
.lo mspack/oabc.lo mspack/oabd.lo mspack/lzxc.lo mspack/lzxd.lo mspack/mszipc.lo mspack/mszipd.lo mspack/qtmd.lo mspack/lzssd.lo mspack/crc32.lo  
libtool: link: /usr/local/bin/nm -B  mspack/.libs/system.o mspack/.libs/cabc.o mspack/.libs/cabd.o mspack/.libs/chmc.o mspack/.libs/chmd.o mspack/
.libs/hlpc.o mspack/.libs/hlpd.o mspack/.libs/litc.o mspack/.libs/litd.o mspack/.libs/kwajc.o mspack/.libs/kwajd.o mspack/.libs/szddc.o mspack/.li
bs/szddd.o mspack/.libs/oabc.o mspack/.libs/oabd.o mspack/.libs/lzxc.o mspack/.libs/lzxd.o mspack/.libs/mszipc.o mspack/.libs/mszipd.o mspack/.lib
s/qtmd.o mspack/.libs/lzssd.o mspack/.libs/crc32.o   |  | /usr/local/bin/sed 's/.* //' | sort | uniq > .libs/libmspack.exp
./libtool: eval: line 1845: syntax error near unexpected token `|'
./libtool: eval: line 1845: `/usr/local/bin/nm -B  mspack/.libs/system.o mspack/.libs/cabc.o mspack/.libs/cabd.o mspack/.libs/chmc.o mspack/.libs/
chmd.o mspack/.libs/hlpc.o mspack/.libs/hlpd.o mspack/.libs/litc.o mspack/.libs/litd.o mspack/.libs/kwajc.o mspack/.libs/kwajd.o mspack/.libs/szdd
c.o mspack/.libs/szddd.o mspack/.libs/oabc.o mspack/.libs/oabd.o mspack/.libs/lzxc.o mspack/.libs/lzxd.o mspack/.libs/mszipc.o mspack/.libs/mszipd
.o mspack/.libs/qtmd.o mspack/.libs/lzssd.o mspack/.libs/crc32.o   |  | /usr/local/bin/sed 's/.* //' | sort | uniq > .libs/libmspack.exp'
make[1]: *** [Makefile:894: libmspack.la] Error 2
make[1]: Leaving directory '/src/mail/libmspack-1.9.1/libmspack'
make: *** [Makefile:718: all] Error 2

I do not see anything wrong with the Makefile.am, but this is the only package that creates this problem. Moreover, the problem appars also within clamav, when the internal libmspack is used.

kyz commented

As libtool is provided by your build environment, and not supplied with libmspack, could you include a copy of libtool (and perhaps all the other files generated by autogen.sh), and the ./configure invocation used to build?

For comparison, my Ubuntu 16.04 environment includes libtool 2.4.6, which produces this output

/bin/bash ./libtool  --tag=CC   --mode=link gcc -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -g -O2 -export-symbols-regex '^mspack_' -version-info 1:0:1 -no-undefined  -o libmspack.la -rpath /usr/local/lib mspack/system.lo mspack/cabc.lo mspack/cabd.lo mspack/chmc.lo mspack/chmd.lo mspack/hlpc.lo mspack/hlpd.lo mspack/litc.lo mspack/litd.lo mspack/kwajc.lo mspack/kwajd.lo mspack/szddc.lo mspack/szddd.lo mspack/oabc.lo mspack/oabd.lo mspack/lzxc.lo mspack/lzxd.lo mspack/mszipc.lo mspack/mszipd.lo mspack/qtmd.lo mspack/lzssd.lo mspack/crc32.lo  
libtool: link: rm -fr  .libs/libmspack.a .libs/libmspack.exp .libs/libmspack.la .libs/libmspack.lai .libs/libmspack.so .libs/libmspack.so.0 .libs/libmspack.so.0.1.0 .libs/libmspack.ver
libtool: link: /usr/bin/nm -B  mspack/.libs/system.o mspack/.libs/cabc.o mspack/.libs/cabd.o mspack/.libs/chmc.o mspack/.libs/chmd.o mspack/.libs/hlpc.o mspack/.libs/hlpd.o mspack/.libs/litc.o mspack/.libs/litd.o mspack/.libs/kwajc.o mspack/.libs/kwajd.o mspack/.libs/szddc.o mspack/.libs/szddd.o mspack/.libs/oabc.o mspack/.libs/oabd.o mspack/.libs/lzxc.o mspack/.libs/lzxd.o mspack/.libs/mszipc.o mspack/.libs/mszipd.o mspack/.libs/qtmd.o mspack/.libs/lzssd.o mspack/.libs/crc32.o   | sed -n -e 's/^.*[	 ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[	 ][	 ]*\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2 \2/p' | sed '/ __gnu_lto/d' | /bin/sed 's/.* //' | sort | uniq > .libs/libmspack.exp
libtool: link: /bin/grep -E -e "^mspack_" ".libs/libmspack.exp" > ".libs/libmspack.expT"
libtool: link: mv -f ".libs/libmspack.expT" ".libs/libmspack.exp"
libtool: link: echo "{ global:" > .libs/libmspack.ver
libtool: link:  cat .libs/libmspack.exp | sed -e "s/\(.*\)/\1;/" >> .libs/libmspack.ver
libtool: link:  echo "local: *; };" >> .libs/libmspack.ver
libtool: link:  gcc -shared  -fPIC -DPIC  mspack/.libs/system.o mspack/.libs/cabc.o mspack/.libs/cabd.o mspack/.libs/chmc.o mspack/.libs/chmd.o mspack/.libs/hlpc.o mspack/.libs/hlpd.o mspack/.libs/litc.o mspack/.libs/litd.o mspack/.libs/kwajc.o mspack/.libs/kwajd.o mspack/.libs/szddc.o mspack/.libs/szddd.o mspack/.libs/oabc.o mspack/.libs/oabd.o mspack/.libs/lzxc.o mspack/.libs/lzxd.o mspack/.libs/mszipc.o mspack/.libs/mszipd.o mspack/.libs/qtmd.o mspack/.libs/lzssd.o mspack/.libs/crc32.o    -g -O2   -Wl,-soname -Wl,libmspack.so.0 -Wl,-version-script -Wl,.libs/libmspack.ver -o .libs/libmspack.so.0.1.0
libtool: link: (cd ".libs" && rm -f "libmspack.so.0" && ln -s "libmspack.so.0.1.0" "libmspack.so.0")
libtool: link: (cd ".libs" && rm -f "libmspack.so" && ln -s "libmspack.so.0.1.0" "libmspack.so")
libtool: link: ar cru .libs/libmspack.a  mspack/system.o mspack/cabc.o mspack/cabd.o mspack/chmc.o mspack/chmd.o mspack/hlpc.o mspack/hlpd.o mspack/litc.o mspack/litd.o mspack/kwajc.o mspack/kwajd.o mspack/szddc.o mspack/szddd.o mspack/oabc.o mspack/oabd.o mspack/lzxc.o mspack/lzxd.o mspack/mszipc.o mspack/mszipd.o mspack/qtmd.o mspack/lzssd.o mspack/crc32.o
ar: `u' modifier ignored since `D' is the default (see `U')
libtool: link: ranlib .libs/libmspack.a
libtool: link: ( cd ".libs" && rm -f "libmspack.la" && ln -s "../libmspack.la" "libmspack.la" )

By comparison with yours, you seem to have CFLAGS='-flto -pipe -O3' and LDFLAGS='-flto=6 -Wl,-O1,-s', and also the shell is /bin/sh instead of /bin/bash

However, the main difference is that you have | | where I have | command | where command is the global_symbol_pipe in libtool:

# Take the output of nm and produce a listing of raw symbols and C names.
global_symbol_pipe="sed -n -e 's/^.*[    ]\\([ABCDGIRSTW][ABCDGIRSTW]*\\)[       ][      ]*\\([_A-Za-z][_A-Za-z0-9]*\\)\$/\\1 \\2 \\2/p' | sed '/      __gnu_lto/d'"

Somehow, this value has been replaced with blank text, and the build fails as a result.

I'm not sure where the problem comes from, however a quick internet search yields https://stackoverflow.com/questions/23587972/libtool-error-during-linkage and https://sourceforge.net/p/courier/mailman/message/32327466/ where someone has exactly the same problem building the courier mail system.

They say check the configure logs, so what does config.log say? Mine says this:

configure:6367: checking command to parse /usr/bin/nm -B output from gcc object
configure:6520: gcc -c -g -O2  conftest.c >&5
configure:6523: $? = 0
configure:6527: /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:6530: $? = 0
configure:6596: gcc -o conftest -g -O2   conftest.c conftstm.o >&5
configure:6599: $? = 0
configure:6637: result: ok

AC_MSG_CHECKING([command to parse $NM output from $compiler object])

This is the libmspack directory (compressed).

The output of ./configure is in c-out.

The file autogen.sh is not necessary: autoconf users know to run autoreconf.

kyz commented

autogen.sh is for convenience, it's OK to run autoreconf manually.

This is the problem: configure failed:

checking command to parse /usr/local/bin/nm -B output from gcc object... failed

Full details in your config.log:

configure:6531: /usr/local/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:6534: $? = 0
cannot find nm_test_var in conftest.nm
configure:6524: gcc -c -flto -pipe -O3  conftest.c >&5
configure:6527: $? = 0
configure:6531: /usr/local/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:6534: $? = 0
cannot run sed -n -e 's/^.*[     ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[         ][      ]*_\([_A-Za-z][_A-Za-z0-9]*\)$/\1 _\2 \2/p' | sed '/ __gnu_lto/d'

I'm not sure why you can't run sed, but you can't, according to this log. Do you have sed installed?

Disabling -flto -O3 helped for some reason.

The presence of autogen.sh leads nowadays to confusion. Its usage disappeared with the introduction of autoreconf in autoconf.

kyz commented

The root cause of this is that binutils "nm" does not cope well with recent changes in gcc's -flto support. This breaks LT_INIT autoconf tests, leading to the error you see. This has been fixed in the latest binutils releases.

Yes, this looks like problem with binutils, but with binutils 2.34.50.20200519 I still get the same error and the PR25355 is supposed to have been fixed in March 2020.

I have sed 4.7 in /usr/local/bin and sed 4.2.2 in /bin.

The problem is: mspack/.libs/crc32.o | | /usr/local/bin/sed: two pipes in a row without anything between them.

kyz commented

The contents of config.log will help diagnose the issue, take a look where configure is testing the nm command. Also, your config.log from before used /usr/local/bin/nm -- is this the fixed nm?

$ echo "char nm_test_var;" >nm.c
$ gcc nm.c -c -fno-common
$ nm nm.o
$ gcc nm.c -c -fno-common -flto
$ nm nm.o

Replace nm and gcc commands with the specific ones you want to check. The second nm invocation should not say "T nm_test_var", if it does this then this version of nm is not fixed.

The right nm is /usr/local/bin/nm. The first nm above prints 0000000000000000 B nm_test_var and the second nm prints 00000000 T nm_test_var. Nm is version 2.34.50.20200519. The same happens with clang-10 instead of gcc. Note that I have manually installed a symlink of /usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.3.1/liblto_plugin.so to /usr/local/lib/bfd-plugins/liblto_plugin.so . (As otherwise LTO does not work).

The config.log from today is attached:

config.log.txt