cglibclibm

Compilng s_sin.c of GNU libm after changing the source


I want to slightly modify libm's sin function (source: s_sin.c) to experiment with something numerical. However, I don't see how to compile the modified source.

I would like to avoid doing "./configure, make". So, to resolve all dependencies, I tried to compile s_sin.c with libm.a in my system. But my compiler quickly rejects the compilation as it cannot find the header file "mydefs.h" in the source file. There are many such header files in the source.

My question is: what is the easiest way for experimenting with changing a single math function in GNU libm and the compiling it? Thanks.


Solution

  • I would like to avoid doing "./configure, make".

    You cannot avoid that (since it is the usual build procedure), but you could pass more arguments to configure. Try configure --help first. You could avoid the next make install (or pass some DESTDIR=/tmp/somedir/ to it).

    My question is: what is the easiest way for experimenting with changing a single math function in GNU libm and the compiling it?

    I would recommend a small chroot(2)-ed environment. Debian has schroot and debootstrap to make that reasonably easy.

    Then you still do ./configure -perhaps with a different --prefix ...- followed by make. You may or not want make install

    Consider perhaps playing with musl-libc, since it can coexist with your system's libc

    BTW, sin is an unusual function (like many in -lm). You could set a breakpoint there to check that most of your system programs don't use it. Don't forget to backup the system's libc and have some static shell running just in case (perhaps sash, because many core utilities are builtin: a static sash contains internal variants of tar, cp, mv etc... that don't depend on any external libc)

    Your could also add (temporarily) some #define sin(x) mysin(x) in some header (e.g. /usr/include/math.h) or use LD_PRELOAD tricks.

    (it is unclear what you really want to do. libm.so is only used by programs, not by itself; what actual numerical experiments do you want to do ??).