elfmaster / libelfmaster

Secure ELF parsing/loading library for forensics reconstruction of malware, and robust reverse engineering tools
http://www.bitlackeys.org
410 stars 64 forks source link

undefined reference to __glibc_unlikely #41

Open milahu opened 6 months ago

milahu commented 6 months ago

libelfmaster fails to compile with musl

gcc -I ./ -static shiva.o shiva_util.o shiva_signal.o shiva_ulexec.o shiva_auxv.o shiva_module.o shiva_trace.o shiva_trace_thread.o shiva_error.o shiva_maps.o shiva_analyze.o shiva_callsite.o shiva_target.o shiva_xref.o shiva_transform.o shiva_so.o shiva_post_linker.o /nix/store/rl8bajlymj1md1000f91gjhnvz0nrpwq-libelfmaster-0.4-alpha-unstable-2023-02-23/lib/libelfmaster.a /nix/store/jagvcafr5xbnriwg6xajw2brvcjxcwi1-capstone-4.0.2/lib/libcapstone.a -o './build'/shiva
/nix/store/a1kgwwyad44q620sym78yx5cwprgwqgs-binutils-2.40/bin/ld: /nix/store/rl8bajlymj1md1000f91gjhnvz0nrpwq-libelfmaster-0.4-alpha-unstable-2023-02-23/lib/libelfmaster.a(libelfmaster.o): in function `elf_scop_text_filesz':
(.text+0x3314): undefined reference to `__glibc_unlikely'

fix

    # fix: undefined reference to `__glibc_unlikely'
    #define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
    substituteInPlace include/libelfmaster.h \
      --replace-fail \
        '#define peu_probable __glibc_unlikely' \
        '#define peu_probable(cond) __builtin_expect ((cond), 0)' \
$ grep -r -w __glibc_unlikely libelfmaster/
libelfmaster/include/libelfmaster.h:#define peu_probable __glibc_unlikely

based on gear-lib/gear-lib/libdebug/gcc.macro

#define __glibc_unlikely(cond) __builtin_expect ((cond), 0)