Bug 1468084 - undefined symbol my_progname in libnetsnmptrapd.so
undefined symbol my_progname in libnetsnmptrapd.so
Status: ASSIGNED
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: net-snmp (Show other bugs)
7.3
x86_64 Linux
unspecified Severity low
: rc
: ---
Assigned To: Josef Ridky
BaseOS QE Security Team
:
Depends On:
Blocks: 1470004
  Show dependency treegraph
 
Reported: 2017-07-05 21:39 EDT by k-endou
Modified: 2017-07-20 14:12 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1470004 (view as bug list)
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
patch with solution (1.26 KB, patch)
2017-07-12 05:09 EDT, Josef Ridky
no flags Details | Diff
better patch (1020 bytes, patch)
2017-07-20 14:06 EDT, Adam Williamson
no flags Details | Diff

  None (edit)
Description k-endou 2017-07-05 21:39:15 EDT
Description of problem:
When I was trying to run a perl script which uses NetSNMP::TrapReceiver module,
I found the script aborts with an "undefined symbol" error.
The error message was:
Can't load '/usr/lib64/perl5/vendor_perl/auto/NetSNMP/TrapReceiver/TrapReceiver.so' for module NetSNMP::TrapReceiver: /lib64/libnetsnmptrapd.so.31: undefined symbol: my_progname at /usr/lib64/perl5/DynaLoader.pm line 190.

Version-Release number of selected component (if applicable):
net-snmp-perl-5.7.2-24.el7_2.1.x86_64
net-snmp-agent-libs-5.7.2-24.el7_2.1.x86_64

How reproducible:
always when perl loads NetSNMP::TrapReceiver module

Steps to Reproduce:
1. execute "perl -MNetSNMP::TrapReceiver -e1"

Actual results:
aborts with the error message:
Can't load '/usr/lib64/perl5/vendor_perl/auto/NetSNMP/TrapReceiver/TrapReceiver.so' for module NetSNMP::TrapReceiver: /lib64/libnetsnmptrapd.so.31: undefined symbol: my_progname at /usr/lib64/perl5/DynaLoader.pm line 190.
 at -e line 0.
Compilation failed in require.
BEGIN failed--compilation aborted.

Expected results:
exits with no messages.

Additional info:
This seems caused by libnetsnmptrapd.so not linked dynamically to an appropriate mysql/mariadb library ( probably libmysqlclient.so ).
Because, no mysql/mariadb related library files appears in output of "ldd" command although libnetsnmptrapd.so contains some "my_*" or "mysql_*" symbols, which shown in "readelf -a".

Anyway, I also found a workaround to this problem.
Preloading libmysqlclient.so with "LD_PRELOAD" environment variable suppresses this error, and the script I tried runs normally now.
ex. $ LD_PRELOAD=/usr/lib64/mysql/libmysqlclient.so.18 perl -MNetSNMP::TrapReceiver -e1
Comment 2 Petr Pisar 2017-07-11 09:08:40 EDT
# ldd -r /usr/lib64/perl5/vendor_perl/auto/NetSNMP/TrapReceiver/TrapReceiver.so
[...]
undefined symbol: my_progname   (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_close   (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_error      (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_autocommit      (/lib64/libnetsnmptrapd.so.31)
undefined symbol: load_defaults (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_init       (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_prepare    (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_close      (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_real_connect    (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_commit  (/lib64/libnetsnmptrapd.so.31)
undefined symbol: my_init       (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_error   (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_bind_param (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_server_end      (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_sqlstate   (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_sqlstate        (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_errno   (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_init    (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_execute    (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_stmt_errno      (/lib64/libnetsnmptrapd.so.31)
undefined symbol: mysql_insert_id       (/lib64/libnetsnmptrapd.so.31)

From net-snmp build log:

libtool: link: gcc -shared  -fPIC -DPIC  .libs/snmptrapd_handlers.o .libs/snmptrapd_log.o .libs/snmptrapd_auth.o .libs/snmptrapd_sql.o   -L/builddir/build/BUILD/net-snmp-5.7.2/agent/.libs -L/builddir/build/BUILD/net-snmp-5.7.2/snmplib/.libs ../agent/.libs/libnetsnmpmibs.so -L/usr/lib64/perl5/CORE /builddir/build/BUILD/net-snmp-5.7.2/agent/.libs/libnetsnmpagent.so -lwrap /builddir/build/BUILD/net-snmp-5.7.2/snmplib/.libs/libnetsnmp.so -lsensors -lrpm -lrpmio ../snmplib/.libs/libnetsnmp.so -lssl -lcrypto -lperl -lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc  -O2 -fstack-protector-strong -m64 -mtune=generic -fstack-protector -Wl,--enable-new-dtags -Wl,-rpath -Wl,/usr/lib64/perl5/CORE -fstack-protector -Wl,-z -Wl,relro -Wl,-z -Wl,now   -Wl,-soname -Wl,libnetsnmptrapd.so.31 -o .libs/libnetsnmptrapd.so.31.0.2

The symbols are indeed provided by libmysqlclient.so and the path is added into ld-linux.so configuration by file /etc/ld.so.conf.d/mariadb-x86_64.conf.

So the only missing piece is $(mysql_config --libs) option to the libnetsnmptrapd.so.31.0.2's linker command.

Obviously upstream thinks that plugins does not need explicit linkage <https://sourceforge.net/p/net-snmp/bugs/1563/>.

I think this is a bug in net-snmp build script.
Comment 3 Josef Ridky 2017-07-12 05:09 EDT
Created attachment 1296787 [details]
patch with solution
Comment 4 Adam Williamson 2017-07-20 13:17:27 EDT
That patch really doesn't seem like the right way to fix this. The only way I can think it might work is that it effectively results in that definition of LIBS getting 'leaked' out of the configure step, such that *everything* in the entire build process likely winds up getting linked against libmysqlclient / libmariadb .

Wouldn't a more appropriate fix be to change the rule for libnetsnmptrapd.$(LIB_EXTENSION)$(LIB_VERSION) in apps/Makefile.in ?
Comment 5 Adam Williamson 2017-07-20 14:06 EDT
Created attachment 1301954 [details]
better patch

I think this patch is more correct; it adds MYSQL_LIBS to the linking of libnetsnmptrapd. The other patch results in 21 occurrences of -lmariadb in the build process, including linking some libraries against libmariadb that do not *need* to be linked against it at all; this patch results in 8 occurrences of -lmariadb , but still fixes the bug (at least, the ldd command no longer reports any unresolved symbols).
Comment 6 Adam Williamson 2017-07-20 14:12:26 EDT
Filed upstream https://sourceforge.net/p/net-snmp/bugs/2792/ with my patch. I'm doing a Fedora Rawhide build with my patch, too.

Note You need to log in before you can comment on or make changes to this bug.