[ZBX-15915] round() undefined in Solaris 9 8/03 (SPARC), linking fails Created: 2019 Apr 01  Updated: 2019 May 24  Resolved: 2019 May 21

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent (G)
Affects Version/s: 3.0.26
Fix Version/s: 3.0.28rc1, 4.0.8rc1, 4.2.2rc1, 4.4.0alpha1, 4.4 (plan)

Type: Problem report Priority: Blocker
Reporter: Saulius Krasuckas Assignee: Andrejs Kozlovs
Resolution: Fixed Votes: 0
Labels: agent, libm, round, solaris
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Solaris 9 8/03 s9s_u4wos_08a SPARC


Attachments: Text File Sol9_SPARC_zabbix_3.0.26__config.log     Text File Sol9_SPARC_zabbix_3.0.26__configure_OK.txt     Text File Sol9_SPARC_zabbix_3.0.26__make_fails.txt    
Team: Team A
Sprint: Sprint 51 (Apr 2019), Sprint 52 (May 2019)
Story Points: 0.5

 Description   

Steps to reproduce:

  1. I configured with by pointing to additional lib-dirs:

LDFLAGS="-L/opt/csw/lib/sparcv9 -L/.SUNWnative/lib/sparcv9" ./configure --enable-agent

  1. run make

Result:

Linking zabbix_agentd fails:

gcc -DHAVE_CONFIG_H -I. -I../../include    -DZABBIX_DAEMON -DSYSCONFDIR="\"/usr/local/etc\"" -DLIBDIR="\"/usr/local/lib\"" -g -O2 -MT zabbix_agentd-zabbix_agentd.o -MD -MP -MF .deps/zabbix_agentd-zabbix_agentd.Tpo -c -o zabbix_agentd-zabbix_agentd.o `test -f 'zabbix_agentd.c' || echo './'`zabbix_agentd.c
mv -f .deps/zabbix_agentd-zabbix_agentd.Tpo .deps/zabbix_agentd-zabbix_agentd.Po
gcc -DZABBIX_DAEMON -DSYSCONFDIR="\"/usr/local/etc\"" -DLIBDIR="\"/usr/local/lib\"" -g -O2  -L/opt/csw/lib/sparcv9 -L/.SUNWnative/lib/sparcv9  -o zabbix_agentd zabbix_agentd-active.o zabbix_agentd-stats.o zabbix_agentd-cpustat.o zabbix_agentd-diskdevices.o zabbix_agentd-vmstats.o zabbix_agentd-logfiles.o zabbix_agentd-zbxconf.o zabbix_agentd-listener.o zabbix_agentd-procstat.o zabbix_agentd-zabbix_agentd.o ../../src/libs/zbxsysinfo/libzbxagentsysinfo.a ../../src/libs/zbxsysinfo/solaris/libspecsysinfo.a ../../src/libs/zbxsysinfo/solaris/libspechostnamesysinfo.a ../../src/libs/zbxsysinfo/agent/libagentsysinfo.a ../../src/libs/zbxsysinfo/common/libcommonsysinfo.a ../../src/libs/zbxsysinfo/simple/libsimplesysinfo.a ../../src/libs/zbxlog/libzbxlog.a ../../src/libs/zbxregexp/libzbxregexp.a ../../src/libs/zbxalgo/libzbxalgo.a ../../src/libs/zbxsys/libzbxsys.a ../../src/libs/zbxnix/libzbxnix.a ../../src/libs/zbxcomms/libzbxcomms.a ../../src/libs/zbxconf/libzbxconf.a ../../src/libs/zbxcommon/libzbxcommon.a ../../src/libs/zbxcrypto/libzbxcrypto.a ../../src/libs/zbxjson/libzbxjson.a ../../src/libs/zbxexec/libzbxexec.a ../../src/libs/zbxmodules/libzbxmodules.a ../../src/libs/zbxself/libzbxself.a     -lkvm -lm -ldl -lrt -lnsl -lkstat -lsocket  -lresolv -liconv
Undefined                       first referenced
 symbol                             in file
round                               zabbix_agentd-procstat.o
ld: fatal: Symbol referencing errors. No output written to zabbix_agentd
collect2: ld returned 1 exit status
make[2]: *** [zabbix_agentd] Error 1
make[2]: Leaving directory `/zabbix-3.0.26/src/zabbix_agent'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/zabbix-3.0.26/src'
make: *** [install-recursive] Error 1

I would transform this into a one liner:

Undefined symbol round first referenced }}{{in file }}{{zabbix_agentd-procstat.o

Expected:
Compilation should succeed.



 Comments   
Comment by Saulius Krasuckas [ 2019 Apr 01 ]

As we've haven't found libm on our Sol9 systems, I've copied some CDDL licensed code from lib/libm/common/m9x/round.c (and related header) of the illlumos project.  It compiled then.  But I am not sure about the right solution (legally and technically correct).

Comment by dimir [ 2019 Apr 02 ]

One of the solutions I see is adding availability of round() check to autotools.

Comment by Glebs Ivanovskis [ 2019 Apr 02 ]

It is interesting that it does not fail during compilation, so there is round() somewhere in header files...

Comment by Saulius Krasuckas [ 2019 Apr 02 ]

> there is round() somewhere in header files...

If I could get list of the headers being included, I would grep through them and see.

Comment by Glebs Ivanovskis [ 2019 Apr 02 ]

It should be in math.h

Comment by Andrejs Sitals [ 2019 Apr 03 ]

While math.h has to be included for round() to be available during compile time, it doesn't necessarily mean that it is declared in math.h. E.g., I have it in /usr/include/x86_64-linux-gnu/bits/mathcalls.h (which is included in math.h) on my development PC (Ubuntu) and it is declared using __MATHCALLX macro:

__MATHCALLX (round,, (_Mdouble_ __x), (__const__));

Comment by Glebs Ivanovskis [ 2019 Apr 03 ]

Argh, I forgot that missing function prototype is just a warning in C. Ignore my words.

Comment by Saulius Krasuckas [ 2019 Apr 03 ]

My bad: I recalled the old thing a bit wrongly.  Actually, we have the math lib installed, but it's version is low: libm.so.1

And it doesn't seem to contain round() :

[root@testlab02 zabbix-3.0.26]# /usr/ccs/bin/nm -D /usr/lib/libm.so.1 | wc -l
185
[root@testlab02 zabbix-3.0.26]# /usr/ccs/bin/nm -D /usr/lib/libm.so.1 | grep sqrt
[78]    |     46240|     152|FUNC |GLOB |0    |9      |__sqrt
[69]    |    135488|     124|FUNC |GLOB |0    |9      |__sqrtf
[72]    |    140896|    1032|FUNC |GLOB |0    |9      |__sqrtl
[173]   |     46240|     152|FUNC |WEAK |0    |9      |sqrt
[root@testlab02 zabbix-3.0.26]# /usr/ccs/bin/nm -D /usr/lib/libm.so.1 | grep -c sqrt
4
[root@testlab02 zabbix-3.0.26]# /usr/ccs/bin/nm -D /usr/lib/libm.so.1 | grep -c round
0

And libm.so.2 seems to be supported only from Solaris 10 and up:

https://stackoverflow.com/questions/33553982/solaris-version-that-uses-libm-so-2/#33584938

Maybe installing "C9X patch cluster" would help on Solaris 9, but "appropriate service contract" for these machines are long gone now:

https://mail.haskell.org/pipermail/glasgow-haskell-users/2009-March/016833.html

 

Has building Zabbix agent v3.x ever worked on Solaris 9 for you?  We would go back in time and compile earlier 3.x version.

 


@Glebs, I renamed function into zround() and well, it didn't even gave me a warning:

make[2]: Entering directory `/zabbix-3.0.26/src/zabbix_agent'
gcc -DHAVE_CONFIG_H -I. -I../../include -DZABBIX_DAEMON -DSYSCONFDIR="\"/usr/local/etc\"" -DLIBDIR="\"/usr/local/lib\"" -m64 -g -O2 -MT zabbix_agentd-procstat.o -MD -MP -MF .deps/zabbix_agentd-procstat.Tpo -c -o zabbix_agentd-procstat.o `test -f 'procstat.c' || echo './'`procstat.c
mv -f .deps/zabbix_agentd-procstat.Tpo .deps/zabbix_agentd-procstat.Po
gcc -DZABBIX_DAEMON -DSYSCONFDIR="\"/usr/local/etc\"" -DLIBDIR="\"/usr/local/lib\"" -m64 -g -O2 -L/opt/csw/lib/sparcv9 -I/usr/include/ -o zabbix_agentd zabbix_agentd-active.o zabbix_agentd-stats.o zabbix_agentd-cpustat.o zabbix_agentd-diskdevices.o zabbix_agentd-vmstats.o zabbix_agentd-logfiles.o zabbix_agentd-zbxconf.o zabbix_agentd-listener.o zabbix_agentd-procstat.o zabbix_agentd-zabbix_agentd.o ../../src/libs/zbxsysinfo/libzbxagentsysinfo.a ../../src/libs/zbxsysinfo/solaris/libspecsysinfo.a ../../src/libs/zbxsysinfo/solaris/libspechostnamesysinfo.a ../../src/libs/zbxsysinfo/agent/libagentsysinfo.a ../../src/libs/zbxsysinfo/common/libcommonsysinfo.a ../../src/libs/zbxsysinfo/simple/libsimplesysinfo.a ../../src/libs/zbxlog/libzbxlog.a ../../src/libs/zbxregexp/libzbxregexp.a ../../src/libs/zbxalgo/libzbxalgo.a ../../src/libs/zbxsys/libzbxsys.a ../../src/libs/zbxnix/libzbxnix.a ../../src/libs/zbxcomms/libzbxcomms.a ../../src/libs/zbxconf/libzbxconf.a ../../src/libs/zbxcommon/libzbxcommon.a ../../src/libs/zbxcrypto/libzbxcrypto.a ../../src/libs/zbxjson/libzbxjson.a ../../src/libs/zbxexec/libzbxexec.a ../../src/libs/zbxmodules/libzbxmodules.a ../../src/libs/zbxself/libzbxself.a -lkvm -lm -ldl -lrt -lnsl -lkstat -lsocket -lresolv -liconv
Undefined                       first referenced
 symbol                             in file
zround                              zabbix_agentd-procstat.o
ld: fatal: Symbol referencing errors. No output written to zabbix_agentd
collect2: ld returned 1 exit status

Which I find to be a bit strange (but OK with me as I haven't investigated into configured warnings threshold for this gcc 3.4.6 installation).

Comment by Saulius Krasuckas [ 2019 Apr 05 ]

I would like to repeat the question:

Has building Zabbix agent v3.x ever worked on Solaris 9 for you ? : )

Comment by Glebs Ivanovskis [ 2019 Apr 08 ]

Looks like round() was introduced in ZBX-11568. You can try 3.0.7 or lower. You can also undo that specific change by applying this patch:

Index: procstat.c
===================================================================
--- procstat.c	(revision 65790)
+++ procstat.c	(revision 65789)
@@ -1103,7 +1101,8 @@
 
 	/* 1e9 (nanoseconds) * 1e2 (percent) * 1e1 (one digit decimal place) */
 	ticks_diff *= __UINT64_C(1000000000000);
-	*value = round((double)ticks_diff / (time_diff * sysconf(_SC_CLK_TCK))) / 10;
+	ticks_diff /= time_diff * sysconf(_SC_CLK_TCK);
+	*value = (double)ticks_diff / 10;
 
 	ret = SUCCEED;
 out:
Comment by Saulius Krasuckas [ 2019 Apr 26 ]

Thanks.

Another way would be to import round() on the source code level.

Eg. musl contains friendly licensed (MIT) implementation:
https://github.com/cloudius-systems/musl/blob/HEAD/src/math/round.c

Although I haven't tested this implementation on Sol9.

Comment by Andrejs Kozlovs [ 2019 May 03 ]

As mentioned above, this situation happens on old Solaris OS and old math library. And this problem is actual for agent only.

We can got HAVE_ROUND define after minor modification of configure.ac and do the following using it:
1. Local round function for all cases (agent and server)

#ifndef HAVE_ROUND
double round( double x)
{
    if (x >= 0)
        x = x + 0.5;
    else
        x = x - 0.5;

    return (double)((int)x);
}
#endif

or
2. Make workaround for agent without precision lost

#ifdef HAVE_ROUND
    *value = round((double)ticks_diff / (time_diff * sysconf(_SC_CLK_TCK))) / 10;
#else
    *value = (int)((double)ticks_diff / (time_diff * sysconf(_SC_CLK_TCK)) + 0.5) / 10.0;
#endif
Comment by Andrejs Kozlovs [ 2019 May 21 ]

Fixed in:

  • 3.0.28rc1 17c9cfbfcfe
  • 4.0.8rc1 8465b64c025
  • 4.2.2rc1 39209e7bd45
  • 4.4.0alpha1 (trunk) b5c3e6db3f6
Generated at Fri Mar 29 10:23:17 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.