kubo/funchook

funchook won't build on alpine linux

drdavella opened this issue · 3 comments

When I attempt to build funchook on Alpine linux I get the following error:

funchook_unix.c: In function 'funchook_strerror':
funchook_unix.c:455:33: error: 'sys_nerr' undeclared (first use in this function); did you mean 'stderr'?
     if (0 <= errnum && errnum < sys_nerr) {
                                 ^~~~~~~~
                                 stderr
funchook_unix.c:455:33: note: each undeclared identifier is reported only once for each function it appears in
funchook_unix.c:456:16: error: 'sys_errlist' undeclared (first use in this function)
         return sys_errlist[errnum];
                ^~~~~~~~~~~

If I remove these lines the package builds just fine. It seems like using _sys_errlist and sys_errlist is non-standard. Is there any reason not to just use strerror instead?

kubo commented

Thanks for reporting the issue. I'll fix it.

Is there any reason not to just use strerror instead?

That's because funchook avoids calling external functions on Linux and macOS in order to prevent function calls invoked by funchook from being hooked.

Funchook imports the following ten symbols on Linux at present. Only one of them is a normal external function.

$ nm libfunchook.so | grep '^   '
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 w _Jv_RegisterClasses
                 w __cxa_finalize@@GLIBC_2.2.5
                 w __gmon_start__
                 U __stack_chk_fail@@GLIBC_2.4
                 U _r_debug@@GLIBC_2.2.5
                 U _sys_errlist@@GLIBC_2.12
                 U _sys_nerr@@GLIBC_2.12
                 U dlsym@@GLIBC_2.2.5

Thanks very much for the response and the explanation! Is there a good way around this if you're not willing to include strerror? Could we possibly add a compile-time option for use cases where we don't expect strerror to be hooked?

kubo commented

I may add a compile-time option to implement strerror compatible with musl by including http://git.musl-libc.org/cgit/musl/tree/src/errno/__strerror.h (MIT license code).