riboseinc / retrace

retrace is a versatile security vulnerability / bug discovery tool through monitoring and modifying the behavior of compiled binaries on Linux, OpenBSD/FreeBSD/NetBSD (shared object) and macOS (dynamic library).
Other
60 stars 19 forks source link

Fix libnereon build on msys2 #421

Open ribose-jeffreylau opened 2 years ago

ribose-jeffreylau commented 2 years ago

https://github.com/riboseinc/retrace/runs/4656054619?check_suite_focus=true#step:5:384

Makefile has not been generated at all.

-- Build files have been written to: D:/a/retrace/retrace/libnereon/build
+ ls -la
total 102
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 .
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 ..
+ ls -la ..
-rw-r--r-- 1 runneradmin None 60014 Dec 29 05:49 build.ninja
-rw-r--r-- 1 runneradmin None  1931 Dec 29 05:49 cmake_install.cmake
-rw-r--r-- 1 runneradmin None 16458 Dec 29 05:49 CMakeCache.txt
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 CMakeFiles
-rw-r--r-- 1 runneradmin None   337 Dec 29 05:49 CTestTestfile.cmake
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 libucl
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 libucl-inst
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 libucl-prefix
-rw-r--r-- 1 runneradmin None    70 Dec 29 05:49 nereon_config.h
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 src
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 tests
drwxr-xr-x 1 runneradmin None     0 Dec 29 05:49 tools
total 35
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 .
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 ..
+ make
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 .git
-rw-r--r-- 1 runneradmin None    8 Dec 29 05:49 .gitignore
-rw-r--r-- 1 runneradmin None  140 Dec 29 05:49 .travis.yml
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 build
-rw-r--r-- 1 runneradmin None 1332 Dec 29 05:49 CMakeLists.txt
-rw-r--r-- 1 runneradmin None   94 Dec 29 05:49 nereon_config.h.in
-rw-r--r-- 1 runneradmin None 3107 Dec 29 05:49 README.md
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 src
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 tests
drwxr-xr-x 1 runneradmin None    0 Dec 29 05:49 tools
mingw32-make: *** No targets specified and no makefile found.  Stop.
maxirmx commented 2 years ago

You install ninja so cmake uses ninja generator by default. There is build.ninja file that is essentially a makefile.
If you call

cmake --build  .

it will select correct build system that matches configure step

You can also do

cmake .. -G "Unix Makefiles" 

in order to get Makefile and not build.ninja

maxirmx commented 2 years ago

There is a problem here: https://github.com/riboseinc/libnereon/blob/master/src/CMakeLists.txt

LIBNEREON_LIBRARY is not defined as CMake target at all. Unix and MacOS versions of cmake somehow manage to create correct build sequence, but MSYS version fails. So the fix is required at libneron source.

maxirmx commented 2 years ago

Then there is an issue with RTLD_NEXT flag which is a bedrock of retrace technology. It is not POSIX and MSYS compilation with default settings considers it undefined

Probably

#define _GNU_SOURCE
#include <dlfcn.h>

can help but it needs to be tested as well

maxirmx commented 2 years ago

If msys (=unix) environment is used for compilation it is essentially cygwin that does not support GNU extensions to dlsysm So hooking with RTLD_NEXT does not compile and I did not find any port or extension

If mingw (=windows) environment is used for compilation, there is a package that pretends that it implements RTLD_NEXT -- https://packages.msys2.org/base/mingw-w64-dlfcn.
However, mingw lacks queue (https://man7.org/linux/man-pages/man7/queue.7.html) and may be some other GNU extensions.

So the only approach I see is to use mingw and adopt queue.h (I think it can be just dropped in).

I have to say that I am not MSYS expert so that all may be wrong.

ribose-jeffreylau commented 2 years ago

So the only approach I see is to use mingw and adopt queue.h (I think it can be just dropped in).

Sounds like we can probably create a separate GitHub Action workflow for mingw to test this out, too.

maxirmx commented 2 years ago

I do not know, can make assumptions only. Now windows build looks like full scale project that requires some upfront experiments and research

maxirmx commented 2 years ago

Libnereon build fixed is here: https://github.com/riboseinc/retrace/pull/427

maxirmx commented 2 years ago

So the only approach I see is to use mingw and adopt queue.h (I think it can be just dropped in).

Sounds like we can probably create a separate GitHub Action workflow for mingw to test this out, too.

I made some tests locally. Mingw build fails fast because Windows SDK doeds not have Queue.h

ribose-jeffreylau commented 2 years ago

Thanks @maxirmx ! This is good progress. I'll merge whatever we have now and figure the rest later.