How can I use --whole-archive with libtool without it being reordered?
Background: I'm compiling Extrae (performance profiling) from sources which depends on Dyninst which depends on libdwarf, which, on Debian Wheezy, is provided as a static library (usr/lib/libdwarf.a).
Dyninst is compiled from sources:
# ./configure --with-libdwarf-static; make; make install
creates:
/usr/lib/libdynDwarf.so.8.1
/usr/lib/libdyninstAPI.so.8
Then Extrae is compiled from sources.
# ./configure --with-mpi=/usr --with-mpi-libs=/usr/lib --with-papi=/usr/local --with-unwind=/usr --with-dyninst=/usr --with-dwarf=/usr --with-dwarf-libs=/usr/lib
...
# make
...
/bin/sh ../../../libtool --tag=CXX --mode=link g++ -I../../../src/common -I/usr/include -g -O2 -Wall -W -L/usr/lib64 -ldyninstAPI -L/usr/lib64 -lunwind -lparseAPI -lsymtabAPI -linstructionAPI -lcommon -L/usr/lib -ldwarf -lelf -L/usr/lib -lxml2 -o extrae extrae-extrae.o extrae-forkSnippets.o extrae-cudaSnippets.o extrae-ompSnippets.o extrae-apiSnippets.o extrae-mpiSnippets.o extrae-commonSnippets.o extrae-applicationType.o extrae-mini-xml-parse.o
libtool: link: g++ -I../../../src/common -I/usr/include -g -O2 -Wall -W -o extrae extrae-extrae.o extrae-forkSnippets.o extrae-cudaSnippets.o extrae-ompSnippets.o extrae-apiSnippets.o extrae-mpiSnippets.o extrae-commonSnippets.o extrae-applicationType.o extrae-mini-xml-parse.o -L/usr/lib64 -ldyninstAPI -lunwind -lparseAPI -lsymtabAPI -linstructionAPI -lcommon -L/usr/lib -ldwarf -lelf -lxml2
/usr/lib/libdynDwarf.so.8.1: undefined reference to `dwarf_elf_init'
/usr/lib/libdynDwarf.so.8.1: undefined reference to `dwarf_finish'
collect2: error: ld returned 1 exit status
make[4]: *** [extrae] Error 1
make[4]: Leaving directory `/root/src/extrae-2.3.4/src/launcher/dyninst'
This error is caused because libdynDwarf needs symbols that aren't included when the static library is linked. A solution to this is provided here, to replace:
-ldwarf
with:
-Wl,--whole-archive -ldwarf -Wl,--no-whole-archive
I make this change to:
./src/launcher/dyninst/Makefile.am
then configure and make again. I get this output:
/bin/sh ../../../libtool --tag=CXX --mode=link g++ -I../../../src/common -I/usr/include -g -O2 -Wall -W -L/usr/lib64 -ldyninstAPI -L/usr/lib64 -lunwind -lparseAPI -lsymtabAPI -linstructionAPI -lcommon -L/usr/lib -Wl,--whole-archive -ldwarf -Wl,--no-whole-archive -lelf -L/usr/lib -lxml2 -o extrae extrae-extrae.o extrae-forkSnippets.o extrae-cudaSnippets.o extrae-ompSnippets.o extrae-apiSnippets.o extrae-mpiSnippets.o extrae-commonSnippets.o extrae-applicationType.o extrae-mini-xml-parse.o
libtool: link: g++ -I../../../src/common -I/usr/include -g -O2 -Wall -W -Wl,--whole-archive -Wl,--no-whole-archive -o extrae extrae-extrae.o extrae-forkSnippets.o extrae-cudaSnippets.o extrae-ompSnippets.o extrae-apiSnippets.o extrae-mpiSnippets.o extrae-commonSnippets.o extrae-applicationType.o extrae-mini-xml-parse.o -L/usr/lib64 -ldyninstAPI -lunwind -lparseAPI -lsymtabAPI -linstructionAPI -lcommon -L/usr/lib -ldwarf -lelf -lxml2
/usr/lib/libdynDwarf.so.8.1: undefined reference to `dwarf_elf_init'
/usr/lib/libdynDwarf.so.8.1: undefined reference to `dwarf_finish'
Note that the liking ordering translated by libtool to (-ldwarf no longer wrapped by --whole-archive):
g++ ... -Wall -W -Wl,--whole-archive -Wl,--no-whole-archive -o extrae ... -ldyninstAPI ... -ldwarf ...
If I manually run the following two reordered commands, compilation succeeds and I can re-run make and it continues successfully.
g++ -I../../../src/common -I/usr/include -g -O2 -Wall -W -o load-module load_module-load-module.o -L/usr/lib64 -ldyninstAPI -lunwind -lparseAPI -lsymtabAPI -linstructionAPI -lcommon -L/usr/lib -Wl,--whole-archive -ldwarf -Wl,--no-whole-archive -lelf -lxml2
g++ -I../../../src/common -I/usr/include -g -O2 -Wall -W -o demo-launcher demo_launcher-demo-launcher.o -L/usr/lib64 -ldyninstAPI -lunwind -lparseAPI -lsymtabAPI -linstructionAPI -lcommon -L/usr/lib -Wl,--whole-archive -ldwarf -Wl,--no-whole-archive -lelf -lxml2
Question
- how can I stop libtool reordering flags?
- Is there a better solution?
Reference: Snipits of Makefile.am:
...
bin_PROGRAMS = extrae
...
extrae_SOURCES = extrae.C, ...
...
extrae_CXXFLAGS = -I$(COMMON_DIR)
extrae_CFLAGS = -I$(COMMON_DIR) -I@DYNINST_INCLUDES@ @XML2_CFLAGS@
extrae_LDFLAGS = @DYNINST_LDFLAGS@ -ldyninstAPI @UNWIND_LDFLAGS@ @UNWIND_LIBS@ -lparseAPI -lsymtabAPI -linstructionAPI $(DYNINST_EXTRA_LIBS) -lcommon @DWARF_LDFLAGS@ -ldwarf @ELF_LDFLAGS@ -lelf @XML2_LDFLAGS@ @XML2_LIBS@
-Wl,--whole-archive,-ldwarf,--no-whole-archive
. – Supplicatory