[uClibc 0000133]: lrint, lrintf et al. math functions defined in headers but not in .so (breaks Xine)

bugs at busybox.net bugs at busybox.net
Thu Dec 8 20:36:21 UTC 2005


The following issue has been CLOSED 
====================================================================== 
http://busybox.net/bugs/view.php?id=133 
====================================================================== 
Reported By:                jamie
Assigned To:                uClibc
====================================================================== 
Project:                    uClibc
Issue ID:                   133
Category:                   Math Library
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     closed
Resolution:                 fixed
Fixed in Version:           
====================================================================== 
Date Submitted:             03-06-2005 10:19 PST
Last Modified:              12-08-2005 12:36 PST
====================================================================== 
Summary:                    lrint, lrintf et al. math functions defined in
headers but not in .so (breaks Xine)
Description: 
#define _GNU_SOURCE
#include <math.h>
int main ()
{
  return lrintf (0.0);
}

This program fails to compile, citing a link time error, "undefined
reference to `lrintf'".

However, there is no compile time warning, because the function is
declared, it just isn't implemented in libm.so or libm.a.

The function _is_ implemented in <bits/mathinline.h>, however.

If __USE_EXTERN_INLINES is added to the compiler flags, then this program
compiles and runs fine.

This omission breaks "Xine" (the audio/video player), where one of the
codecs uses the lrintf() function.  There are no compiler warnings because
the function is declared, and in fact it builds fine because it's building
a shared library; the problem is detected only at run time when the shared
library cannot be loaded.

Glibc, from which the header files are derived, does have a definition of
this function and its relatives in libm.so and libm.a.  (Glibc 2.3.4 or
thereabouts).

====================================================================== 

---------------------------------------------------------------------- 
 jbrandmeyer - 03-09-05 09:23  
---------------------------------------------------------------------- 
sinf and cosf suffer the same problem.  GCC bug# 20353 is somewhat related
to this problem. 

---------------------------------------------------------------------- 
 jamie - 03-09-05 10:15  
---------------------------------------------------------------------- 
The GCC bug is a bit different because GCC calls sinf and cosf even when
the source program doesn't mention them, as an "optimisation".

But yes, they are related.

A quick hack for uclibc (not a perfect solution, but functional) for both
these bugs would be:

float lrintf (float x) { return (float) lrint ((double) x); }
float sinf (float x) { return (float) sin ((double) x); }

Although in the case of functions like lrintf(), it's probably better to
enable the inlined implementations when optimising. 

---------------------------------------------------------------------- 
 jbrandmeyer - 03-09-05 16:08  
---------------------------------------------------------------------- 
lrintf remains outstanding, since lrint() is not defined, but it appears
that sinf and cosf have been added by Mr. Anderson (using the technique
you describe) a couple of days ago. 

---------------------------------------------------------------------- 
 jamie - 03-09-05 17:59  
---------------------------------------------------------------------- 
There is an implementation of lrint() (and other functions) available in
<bits/mathinline.h>, which can be used in a slightly dirty way to make the
library implementations:

#include <math.h>
#define __NTH(f) __ # f
#include <bits/mathinline.h>

long int lrintf (float x) { __lrintf (x); }
long int lrint (double x) { __lrint (x); }
long int lrintl (long double x) { __lrintl (x); }

(Not tested).
You get the idea.  No need to write actual math functions.

-- Jamie 

---------------------------------------------------------------------- 
 psm - 03-12-05 12:37  
---------------------------------------------------------------------- 
see bug http://busybox.net/bugs/view.php?id=144 for full math support 

---------------------------------------------------------------------- 
 vapier - 12-08-05 12:36  
---------------------------------------------------------------------- 
latest svn has more math funcs 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
03-06-05 10:19  jamie          New Issue                                    
03-09-05 09:23  jbrandmeyer    Note Added: 0000073                          
03-09-05 09:24  jbrandmeyer    Issue Monitored: jbrandmeyer                    
03-09-05 10:15  jamie          Note Added: 0000078                          
03-09-05 16:08  jbrandmeyer    Note Added: 0000079                          
03-09-05 17:59  jamie          Note Added: 0000080                          
03-12-05 12:37  psm            Note Added: 0000084                          
03-16-05 11:52  andersen       Assigned To              mjn3 => uClibc      
12-08-05 12:36  vapier         Note Added: 0000753                          
12-08-05 12:36  vapier         Status                   assigned => closed  
12-08-05 12:36  vapier         Resolution               open => fixed       
======================================================================




More information about the uClibc-cvs mailing list