1 automake and libtool research for sigrok bug #1433
2 partial linking to create a NULL terminated list of drivers
3 which were built into the library
5 inspired by https://sigrok.org/bugzilla/show_bug.cgi?id=802
6 and https://sigrok.org/bugzilla/show_bug.cgi?id=1433,
7 reported for LTO but probably of more general nature
8 (just noticed with recent LTO setups)
11 - driver source code provided "driver code" (regular application)
12 as well as "list item" (one pointer to the driver's description)
13 - driver pointer is put into a separate segment during compilation,
14 needs to get collected to a list of drivers with NULL termination
15 at compile time, ideally before application code uses the library
16 - existing build support for the libsigrok library puts all drivers
17 into the src/libdrivers.la library, iteration over the driver list
18 is fortunately concentrated in a src/drivers.c source file
21 - use a linker script to convert the src/drivers.lo iteration logic
22 plus the src/libdrivers.la code base into a src/libdrivers_list.la
23 library that applications can "juse use"
25 interactive libtool use for partial linking
26 takes automake out of the equation, still is flawed
27 $ libtool --no-quiet --mode=link gcc -o drivers_list.o src/driver_1.lo src/driver_2.lo src/src_libdrivers_list_la-drivers.lo ../src/drivers.ld
28 libtool: link: /usr/bin/ld -m elf_x86_64 -r -o drivers_list.o src/.libs/driver_1.o src/.libs/driver_2.o src/.libs/src_libdrivers_list_la-drivers.o
29 what the? runs ld(1) which is good, but ignores the specified .ld script which is essential! neither -T file nor -Wl,-T,file change this :(
31 build with or without LTO support enabled:
33 $ env CFLAGS=-flto LDFLAGS=-flto ../configure
34 build with drivers enabled/disabled (up to three, enabled by default)
35 $ ../configure --disable-driver2
39 alternative approach to compile time and linker sections:
40 register from constructors at runtime, executes before main() and may
41 not rely on malloc(3), could rely on static vars and .bss containing
42 zeroes, can use a linked list instead of an array _if_ driver items
43 provide the node storage, that would elimintate the need for an upper
44 limit of the number of drivers, could eliminate the linker section,
45 may be most portable, at the expense of a little startup code and a
46 little static non-const memory per registered driver
48 re-consideration of linker scripts and link time list creation:
49 - gut feeling suggests that the linker script would be most appropriate
50 and most desirable, but experiments suggest that it's fragile
51 - needed to -Wl,-T,file in _la_LDFLAGS, still gets "broken" (split)
52 but appears to take effect, LTO is yet to get checked
53 - uncertain whether -Wc,-T... is needed (compile time use of the
54 linker script, which phase is the "ld -r" associated with?)
55 - ideally the build rules would create the library (and the app)
56 and dump the library's embedded list after library creation,
57 think cmake POST_BUILD and its automake counterpart (if one exists)
58 - a potential command to dump the drivers list (array of pointers) is:
59 objdump -j $SECTION -s $OBJECTFILE
60 specifically this expansion of the above:
61 $ objdump -s -j __sr_driver_list -j __DATA,__sr_driver_list build/src/.libs/libcombo.so
62 - recent experiments suggest that dynamic linking works with automake
63 and the linker script, but static linking fails, using cmake and the
64 linker script works for dynamic linking, static linking was not tested
65 (inability to statically link are assumed to break sigrok Windows builds)