[uClibc] No feclearexcept in libm.so

Marvell Kirkwood based
Post Reply
User avatar
MrDini
Posts: 651
Joined: Mon Dec 21, 2015 7:21 pm
Contact:

[uClibc] No feclearexcept in libm.so

Post by MrDini » Thu Nov 02, 2017 10:53 pm

Hi,

I wanted to compile a source which uses feclearexcept and fetestexcept. Unfortunately the compilation ended in an error with undefined reference... :(

After that, I found this code for testing somewhere on the internet:

Code: Select all

#include <stdio.h>
#include <math.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS on

int main ()
{
  feclearexcept (FE_ALL_EXCEPT);
  sqrt(-1);
  if (fetestexcept(FE_INVALID)) printf ("sqrt(-1) raises FE_INVALID\n");
  return 0;
}
And tried to build a binary:

Code: Select all

root@NSA320S:~# gcc -o /tmp/test /tmp/test.c -lm
/tmp/ccKyBcNO.o: In function `main':
test.c:(.text+0xc): undefined reference to `feclearexcept'
test.c:(.text+0x20): undefined reference to `fetestexcept'
collect2: error: ld returned 1 exit status
Yeah, it looks like uClibc isn't supports the fe*except, but just to be definitely sure, I ran this command too:

Code: Select all

root@NSA320S:~# strings /ffp/lib/libm.so.0 | grep -E ^fe
root@NSA320S:~#
This is really strange, because the package, that I tried to compile could be a lifesaver. Is there an easy way to implement this into uClibc somehow @barmalej2?

Thanks
Thanks nas-central the lot of help! :)

barmalej2
Posts: 2382
Joined: Sun Apr 29, 2012 5:24 pm

Re: [uClibc] No feclearexcept in libm.so

Post by barmalej2 » Fri Nov 03, 2017 10:05 am

MrDini wrote:Is there an easy way to implement this into uClibc somehow @barmalej2?
Unfortunately not. From uClibc config:
UCLIBC_HAS_FENV
bool "Enable C99 Floating-point environment"
depends on UCLIBC_HAS_FLOATS
help
If you want the uClibc math library to contain the C99 floating
point environment, rounding and exception handling functions then
say Y here.

NOTE: Supported architectures currently include:
i386
This feature was enabled since first ffp uClibc release, thus is still confusing when compiling programs (header present with defined functions, but libmath doesn't has them for arm arch). Will be disabled in next release. I'm planning to upload full updated ffp toolchain in next weekend.
MrDini wrote: This is really strange, because the package, that I tried to compile could be a lifesaver.
Give me more info. Will see, what I can do.

User avatar
MrDini
Posts: 651
Joined: Mon Dec 21, 2015 7:21 pm
Contact:

Re: [uClibc] No feclearexcept in libm.so

Post by MrDini » Fri Nov 03, 2017 1:01 pm

Thanks. Hmmm, a new toolchain... It sounds great. :)

I wanted to compile the sox source in order to convert files directly on my NAS.

But with an sshfs mount and using an x64 PC, I could convert all of my files. So I have a half solution. :)

Will take a look on the configure script, maybe there is an fenv check somewhere (and force disable it with a patch in this case).
Thanks nas-central the lot of help! :)

barmalej2
Posts: 2382
Joined: Sun Apr 29, 2012 5:24 pm

Re: [uClibc] No feclearexcept in libm.so

Post by barmalej2 » Fri Nov 03, 2017 7:21 pm

SoX source code contains a lot hardcoded paths for /usr prefix. You need to adjust to /ffp in hard way. Basic instructions for SoX compilation:
# Adjust SoX for uClibc first
/ffp/bin/wget -Nnv 'https://git.buildroot.net/buildroot/pla ... libc.patch'
patch -p1 < 0001-uclibc.patch
# Fix SoX bug: https://sourceforge.net/p/sox/mailman/message/33499897/
/ffp/bin/wget -nv 'https://bogomips.org/sox.git/patch/?id= ... 4ac0217737' -O sox-dynamic.patch
patch -p1 < sox-dynamic.patch
# Adapt prefix for /ffp
grep -lrZ '/usr/local' . | xargs -r0 sed -i 's|/usr/local|/ffp|g'
grep -lrZ '/usr' . | xargs -r0 sed -i 's|/usr|/ffp|g'
find . -iname "config.*" -type f -exec sed -i -r 's/^#! ?\/bin\/sh/#!\/ffp\/bin\/sh/' {} +
find . -iname "config.*" -type f -exec sed -i -r 's/^#! ?\/bin\/bash/#!\/ffp\/bin\/bash/' {} +
find . -iname "config.*" -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/env/#!\/ffp\/bin\/env/' {} +
find . -iname "configure" -type f -exec sed -i -r 's/^#! ?\/bin\/sh/#!\/ffp\/bin\/sh/' {} +
find . -iname "configure" -type f -exec sed -i -r 's/^#! ?\/bin\/bash/#!\/ffp\/bin\/bash/' {} +
find . -iname "configure" -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/env/#!\/ffp\/bin\/env/' {} +
find . -executable -type f -exec sed -i -r 's/^#! ?\/bin\/sh/#!\/ffp\/bin\/sh/' {} +
find . -executable -type f -exec sed -i -r 's/^#! ?\/bin\/bash/#!\/ffp\/bin\/bash/' {} +
find . -executable -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/env/#!\/ffp\/bin\/env/' {} +
find . -iname "*.py*" -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/python/#!\/ffp\/bin\/python/' {} +
find . -iname "*.py*" -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/env/#!\/ffp\/bin\/env/' {} +
find . -iname "*.py*" -type f -exec sed -i -r 's/^#! ?\/bin\/python/#!\/ffp\/bin\/python/' {} +
find . -iname "*.py*" -type f -exec sed -i -r 's/^#! ?\/bin\/env/#!\/ffp\/bin\/env/' {} +
find . -iname "*.pl*" -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/perl/#!\/ffp\/bin\/perl/' {} +
find . -iname "*.pl*" -type f -exec sed -i -r 's/^#! ?\/usr\/bin\/env/#!\/ffp\/bin\/env/' {} +
find . -iname "*.pl*" -type f -exec sed -i -r 's/^#! ?\/bin\/perl/#!\/ffp\/bin\/perl/' {} +
find . -iname "*.pl*" -type f -exec sed -i -r 's/^#! ?\/bin\/env/#!\/ffp\/bin\/env/' {} +
# Reconfigure source code due to changes
autoreconf -fi
# And you are ready to go
ac_cv_header_fenv_h=no ./configure --prefix=/ffp --with-sysroot=/ffp --with-dyn-default --with-gsm --with-lpc10 --with-distro='Fonz Fun Plug'
make
Use can skip options --with-gsm --with-lpc10, if you have separate ffp packages of these. Otherwise they are required for static linking bundled in tree gsm and lpc10 sources, when --with-dyn-default (forces to link dynamically with ffp provided libraries) option is used.

User avatar
MrDini
Posts: 651
Joined: Mon Dec 21, 2015 7:21 pm
Contact:

Re: [uClibc] No feclearexcept in libm.so

Post by MrDini » Fri Nov 03, 2017 11:14 pm

Thanks. But as I noticed, if I remove the --with-dyn-default flag, it compiles smoothely. :)

And now, I have a working SoX package. :)
Thanks nas-central the lot of help! :)

barmalej2
Posts: 2382
Joined: Sun Apr 29, 2012 5:24 pm

Re: [uClibc] No feclearexcept in libm.so

Post by barmalej2 » Sat Nov 04, 2017 8:22 am

Are you saying that you can't compile, when options "--with-dyn-default --with-gsm --with-lpc10" is used?
Of course, you can build without "--with-dyn-default", but in that case you will get static build, which is not preferred as shared, using on low resources NAS.

User avatar
MrDini
Posts: 651
Joined: Mon Dec 21, 2015 7:21 pm
Contact:

Re: [uClibc] No feclearexcept in libm.so

Post by MrDini » Sat Nov 04, 2017 9:08 am

Yes. I moved the fenv.h first to a temporary path and reconfigured it. After that I ran the automake, but after a while, it showd up an undefined reference to 'lsx_error'.

And I found this patch, but I didn't have time to try this out, because I needed the binary ASAP, So I just removed the --with-dyn-default flag, and it compiled first without any issues. :) But I am going to recompile the source again with the patch applied.

PS: I didn't have to hardcode any pathes. It just worked. :D

Edit: Oh, I see, You also used this patch.
Thanks nas-central the lot of help! :)

Post Reply