** Description changed:

  [Impact]
  The `libm.a` static library on i386 architecture lacks the math function 
`fmod`. This will break static compilation in scenarios where programs expect 
the function to exist.
  
- (mantic-i386)$ readelf --syms --wide /usr/lib/i386-linux-gnu/libm.a | grep 
fmod
+ The commit https://sourceware.org/git/?p=glibc.git;a=commit;h=16439f419b
+ removed the static fmod/fmodf on i386 (and m68k) with an empty w_fmod.c
+ used by ABIs that rely on the newer implementation. However, this change
+ also removed the necessary symbols from the static library.  As a side
+ effect, the expected compatibility symbols were no longer emitted into
+ the static library.
+ 
+ As a consequence, static builds that reference fmod may fail with
+ unresolved symbol errors during the linking stage.
+ 
+ 
+ [Test Case]
+ 
+ On a noble host install libc6-dev:i386 (and clang if needed) package. In
+ the test using clang with the -m32 flag in order to ignore the 64-bit
+ hardware and build this as a 32-bit executable since the bus is
+ affecting these architectures.
+ 
+ Verify afterwards:
+ $ ls /usr/lib32/libm.a
+ # confirm the library architecture
+ file /usr/lib32/libm.a
+ /usr/lib32/libm.a: current ar archive
+ 
+ 
+ Create a simple test.c file with the following contents:
+ 
+ #include <math.h>
+ 
+ int main() {
+     return fmod(5.0, 2.0);
+ }
+ 
+ [BEFORE THE PATCH]
+ 
+ Compile statically using clang:
+ $ clang -m32 -static test.c -lm 
+ /usr/bin/ld: /tmp/test-6f7fbc.o: in function `main':
+ test.c:(.text+0x38): undefined reference to `fmod'
+ clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
+ 
+ Check if the symbol is present:
+ $ readelf --syms --wide /usr/lib/i386-linux-gnu/libm.a | grep fmod
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodl_compat.o)
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmod_compat.o)
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodf_compat.o)
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmodl.o)
       2: 00000000    23 FUNC    GLOBAL DEFAULT    1 __ieee754_fmodl
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodl.o)
       4: 00000000   148 FUNC    GLOBAL DEFAULT    2 __fmodl
       7: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodl
       9: 00000000   148 FUNC    WEAK   DEFAULT    2 fmodf64x
      10: 00000000   148 FUNC    WEAK   DEFAULT    2 fmodl
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmod.o)
       2: 00000000    23 FUNC    GLOBAL DEFAULT    1 __ieee754_fmod
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmod.o)
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmodf.o)
       2: 00000000    23 FUNC    GLOBAL DEFAULT    1 __ieee754_fmodf
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodf.o)
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmodf128.o)
       7: 00000000  3227 FUNC    GLOBAL DEFAULT    2 __ieee754_fmodf128
      13: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf128
      14: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf128
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodf128.o)
       6: 00000000   578 FUNC    GLOBAL DEFAULT    2 __fmodf128
      10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf128
      12: 00000000   578 FUNC    WEAK   DEFAULT    2 fmodf128
  
- [Test Case]
  
- On a noble host install libc6-dev:i386 package and
+ Without the fix, fmod function is not present in the binary. This indicates 
that the linker was unable to resolve the fmod symbol from the static math 
library during the linking stage.
  
- $ readelf --syms --wide /usr/lib/i386-linux-gnu/libm.a | grep fmod
  
- Without the fix fmod function is not present (see readelf output of
- Description).
+ [AFTER THE PATCH]
  
- With the fix fmod fuctions are present:
+ Try again to statically compile the test.c program from above:
+ $ clang -m32 -static test.c -lm 
+ 
+ It should work without any errors and have a “a.out” file.
+ 
+ This resolves the "undefined reference to fmod" error, ensuring that the
+ necessary math functions from the libm library are properly linked and
+ included in the static binary.
+ 
+ In addition, with the fix fmod fuctions are present:
  
  readelf --syms --wide /usr/lib/i386-linux-gnu/libm.a | grep fmod
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodl_compat.o)
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmod_compat.o)
       4: 00000000   122 FUNC    GLOBAL DEFAULT    2 __fmod
       7: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmod
       9: 00000000   122 FUNC    WEAK   DEFAULT    2 fmodf32x
      10: 00000000   122 FUNC    WEAK   DEFAULT    2 fmodf64
      11: 00000000   122 FUNC    WEAK   DEFAULT    2 fmod
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodf_compat.o)
       4: 00000000   114 FUNC    GLOBAL DEFAULT    2 __fmodf
       7: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf
       9: 00000000   114 FUNC    WEAK   DEFAULT    2 fmodf32
      10: 00000000   114 FUNC    WEAK   DEFAULT    2 fmodf
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmodl.o)
       2: 00000000    23 FUNC    GLOBAL DEFAULT    1 __ieee754_fmodl
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodl.o)
       4: 00000000   148 FUNC    GLOBAL DEFAULT    2 __fmodl
       7: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodl
       9: 00000000   148 FUNC    WEAK   DEFAULT    2 fmodf64x
      10: 00000000   148 FUNC    WEAK   DEFAULT    2 fmodl
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmod.o)
       2: 00000000    19 FUNC    GLOBAL DEFAULT    1 __ieee754_fmod
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmod.o)
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmodf.o)
       2: 00000000    19 FUNC    GLOBAL DEFAULT    1 __ieee754_fmodf
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodf.o)
  File: /usr/lib/i386-linux-gnu/libm.a(e_fmodf128.o)
       7: 00000000  3227 FUNC    GLOBAL DEFAULT    2 __ieee754_fmodf128
      13: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf128
      14: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf128
  File: /usr/lib/i386-linux-gnu/libm.a(w_fmodf128.o)
       6: 00000000   578 FUNC    GLOBAL DEFAULT    2 __fmodf128
      10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __ieee754_fmodf128
      12: 00000000   578 FUNC    WEAK   DEFAULT    2 fmodf128
  
  [Regression Potential]
  
  The patch adds the symbols fmod/fmodf for static builds for i386 and m68k.
  The changes are arch specific, so any regression would affect i386 and m68k 
for the static libm.a.
  
  [Other]
  
  Fix : 
https://sourceware.org/git/?p=glibc.git;a=commit;h=0b716305dfb48c2d13ed4f7d06c082b90c1d226f
  Affected Ubuntu releases : Noble

** Changed in: glibc (Ubuntu Noble)
       Status: Incomplete => In Progress

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2036283

Title:
  i386 glibc is missing fmod in libm.a

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/2036283/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to