volkszaehler / vzlogger

Logging utility for various meters & sensors
http://wiki.volkszaehler.org/software/controller/vzlogger
GNU General Public License v3.0
145 stars 123 forks source link

Libraries are linked dynamic and static #586

Closed narc-Ontakac2 closed 1 year ago

narc-Ontakac2 commented 1 year ago

debuild is giving a lintian error about libgmp and libidn2 beeing statically linked. ldd says they are linked dynamically:

$ ldd debian/vzlogger/usr/bin/vzlogger | grep 'idn2\|gmp'
    libidn2.so.0 => /lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f47fb145000)
    libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f47fa17f000)

The lintian warnings are however coming from looking for strings in the binary, see

$ grep 'idn2\|gmp' /usr/share/lintian/data/binaries/embedded-libs
gmp       || ||GNU MP: Cannot allocate memory
libidn2-0   || ||punycode conversion resulted in overflow

These strings are actually present in the vzlogger binary.

$ strings debian/vzlogger/usr/bin/vzlogger | grep 'GNU MP: Cannot allocate memory\|punycode conversion resulted in overflow'
GNU MP: Cannot allocate memory (size=%lu)
punycode conversion resulted in overflow

I am looking into this but I am grateful for any hints on what is going on here.

r00t- commented 1 year ago

@narc-Ontakac2: you accidentially created this in libsml instead of vzlogger, moved it over.

r00t- commented 1 year ago

the final link command for vzlogger, (as to be found by rm src/vzlogger ; make or in src/CMakeFiles/vzlogger.dir/link.txt) mentions "static" a few times, i guess the purpose is to link the internal libraries libvz.a libvz-api.a libproto.a statically, but i guess this is recursively applies to external libraries used by those. libidn and libgmp are actualy just the tip of the iceberg, libcurl is included too, and it's strings can be found - the binary is also exessively large! (curl then pulls in idn and gmp)

r00t- commented 1 year ago

manually applying this after running cmake but before linking fixes the issue:

sed -i 's/-Wl,-Bstatic//g;s/-Wl,-Bdynamic//g' src/CMakeFiles/vzlogger.dir/link.txt

we need to find out how to make cmake generate the link command correctly.

r00t- commented 1 year ago

this might seem like a regression, but even a build from 2020 has this issue:

root@raspberrypi:~# ls -l /usr/local/bin/vzlogger
-rwxr-xr-x 1 root root 8184908 May  6  2020 /usr/local/bin/vzlogger
root@raspberrypi:~# strings /usr/local/bin/vzlogger |grep punycode
[...]
string contains invalid punycode data
punycode encoded data will be too large
punycode conversion resulted in overflow
[...]
narc-Ontakac2 commented 1 year ago

It may be an improved or fixed lintian that now detects it.

narc-Ontakac2 commented 1 year ago

Curl is not affected, the CURL messages are from the vzlogger src.

strings /usr/lib/x86_64-linux-gnu/libcurl.so.4.8.0 | grep CURL:

finds nothing.

r00t- commented 1 year ago

thanks, even if it's not curl, it's still striking how this bloats the binary by several megabytes, so it's probably more than idn and gmp.

r00t- commented 1 year ago
[~/vzlogger]$ strip src/vzlogger
[~/vzlogger]$ du -h src/vzlogger
4.4M    src/vzlogger
[~/vzlogger]$ sed -i 's/-Wl,-Bstatic//g;s/-Wl,-Bdynamic//g' src/CMakeFiles/vzlogger.dir/link.txt
[~/vzlogger]$ rm src/vzlogger
[~/vzlogger]$ make vlogger &>/dev/null
[~/vzlogger]$ strip src/vzlogger
[~/vzlogger]$ du -h src/vzlogger
1.3M    src/vzlogger
``` ```
[~/vzlogger]$ du -sch /usr/lib/x86_64-linux-gnu/libidn2.a /usr/lib/x86_64-linux-gnu/libgmp.a 
168K    /usr/lib/x86_64-linux-gnu/libidn2.a
1.2M    /usr/lib/x86_64-linux-gnu/libgmp.a
1.4M    total
r00t- commented 1 year ago

cmake -DENABLE_LOCAL=False fixes the issue... so it's caused by microhttpd.

sudo rm /usr/lib/x86_64-linux-gnu/libmicrohttpd.a also fixes it, looks like microhttpd prefers static linking, and if it does, also pulls in the other libraries. can't see the code responsible for that yet.

r00t- commented 1 year ago

https://github.com/volkszaehler/vzlogger/blob/master/modules/FindMicroHttpd.cmake#L84

r00t- commented 1 year ago

@narc-Ontakac2: can you test #587 ?