Bug in glibc with the latest stable update

This is a repost of this comment originally posted to the stable update thread here: [Stable Update] 2025-02-16 - Kernels, Firefox, Qt, KDE Gear, GNOME - #75 by QAZXSW

The stable update on 2025-02-16 introduces an error in the lgammaf_r function inside glibc. This is a mathematical function that gives the logarithm of the gamma function for a given input.

Test code:

#include <iostream>
#include <cmath>

int main()
{
  int dsgngam;
  double dresult = lgamma_r (double (-1.0), &dsgngam);

  int fsgngam;
  float fresult = lgammaf_r (float (-1.0), &fsgngam);
  
  std::cout << "dresult = " << dresult << " dsgngam = " << dsgngam << '\n'
            << "fresult = " << fresult << " fsgngam = " << fsgngam << '\n' ;
}

With current gcc from the repositories:

$ g++ lgam.cc 

$ ./a.out 
dresult = inf dsgngam = 1
fresult = inf fsgngam = -1

Same output with current clang from the repositories:

$ clang++ lgam.cc 

$ ./a.out 
dresult = inf dsgngam = 1
fresult = inf fsgngam = -1

Both dsgngam and fsgngam should be +1 in all cases, but the float case gives -1 for both compilers, which is incorrect.

The sign of the log of the gamma function should only depend on the value of the input (-1) and not on whether it is float or double, but this version of glibc treats those datatypes differently and erroneously reports that one is positive and the other is negative.

This discrepancy in turn results in unit test failures in downstream numerical software.

Should this be taken upstream? If so, should it be taken to Arch or to the glibc developers?

No. There is a newer version in the testing and unstable repos. Please switch branches and test 2.41+r6+gcf88351b685d-1.

1 Like

Hi sorry for the delay. I switched to testing, did pacman -Syu, verified that the glibc was indeed the exact version you listed. After a reboot, it still gives the erroneous value for fsgngam (sign of the log of the gamma function, but only for float not double).

This was tested with current g++ from the testing branch. No compilation flags, nothing set in CXXFLAGS etc.

The latest version is 2.41+r9+ga900dbaf70f0-1. You find it currently in our unstable branch. There was this issue reported: Intel ICPX will not compile in SYCL mode after glibc update to 2.41. (#20) · Issues · Arch Linux / Packaging / Packages / glibc · GitLab

Since you saw the issue with 2.41 it might be a regression: glibc updated from 2.40+r66+g7d4b6bcae91f-1 to 2.41+r2+g0a7c7a3e283a-1

Please file a bug report upstream if that version doesn’t solve it for you: https://sourceware.org/bugzilla/describecomponents.cgi?product=glibc

Changes made to the 2.41 branch can be followed here: https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/release/2.41/master

1 Like