ianlancetaylor / libbacktrace

A C library that may be linked into a C/C++ program to produce symbolic backtraces
Other
947 stars 220 forks source link

libbacktrace: always link test programs statically #95

Closed whitslack closed 1 year ago

whitslack commented 2 years ago

When configured with --enable-shared, Libtool was linking the test programs dynamically and placing the real binaries in .libs/ and wrapper scripts in the build root. objcopy pukes when given these wrapper scripts as input. The simplest workaround is to link libbacktrace into the test programs statically.

Excerpt of build failure with ./configure --enable-shared:

make  check-TESTS
make[1]: Entering directory '/var/tmp/portage/sys-libs/libbacktrace-1.0_p20220709/work/libbacktrace-8602fda64e78f1f46563220f2ee9f7e70819c51d'
make[2]: Entering directory '/var/tmp/portage/sys-libs/libbacktrace-1.0_p20220709/work/libbacktrace-8602fda64e78f1f46563220f2ee9f7e70819c51d'
rm -f btest_dwz btest_dwz_common.debug
cp btest btest_dwz_1
cp btest btest_dwz_2
if dwz -m btest_dwz_common.debug btest_dwz_1 btest_dwz_2; then \
  rm -f btest_dwz_2; \
  mv btest_dwz_1 btest_dwz; \
else \
  echo "Ignoring dwz errors, assuming that test passes"; \
  cp btest btest_dwz; \
fi
dwz: "btest_dwz_1" is not an ELF file
dwz: "btest_dwz_2" is not an ELF file
dwz: Too few files for multifile optimization
Ignoring dwz errors, assuming that test passes
objcopy --only-keep-debug btest btest_gnudebuglink.debug
objcopy: btest: file format not recognized
make[2]: *** [Makefile:2482: btest_gnudebuglink] Error 1
make[2]: Leaving directory '/var/tmp/portage/sys-libs/libbacktrace-1.0_p20220709/work/libbacktrace-8602fda64e78f1f46563220f2ee9f7e70819c51d'
make[1]: *** [Makefile:2008: check-TESTS] Error 2
make[1]: Leaving directory '/var/tmp/portage/sys-libs/libbacktrace-1.0_p20220709/work/libbacktrace-8602fda64e78f1f46563220f2ee9f7e70819c51d'
make: *** [Makefile:2293: check-am] Error 2

The error objcopy: btest: file format not recognized occurs because btest is a libtool wrapper script. The real btest binary executable is at .libs/btest.

Statically linking the test programs, as this PR does, allows the tests to succeed.

jtojnar commented 1 year ago

According to https://autotools.info/libtool/wrappers.html, -no-install is the way to go. Did that in #99