Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cutter can't find rizin on Haiku #3877

Open
Begasus opened this issue Sep 20, 2023 · 19 comments
Open

Cutter can't find rizin on Haiku #3877

Begasus opened this issue Sep 20, 2023 · 19 comments
Assignees
Milestone

Comments

@Begasus
Copy link

Begasus commented Sep 20, 2023

Work environment

Questions Answers
OS/arch/bits (mandatory) Haiku R1B4 64bit
Architecture/bits of the file (mandatory) x86/64
rizin -v full output, not truncated (mandatory) rizin 0.6.2 @ haiku-x86-64
commit: 8c3dc83f8db0a6392496fc5cef8188df1dd09b25

Expected behavior

Cutter finds and uses rizin libraries/headers

Actual behavior

Cutter fails to find the rizin installation when running cmake

CMakeOutput.log.txt

Steps to reproduce the behavior

Download cutter source archive
Run cmake in Terminal:

 cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCUTTER_USE_BUNDLED_RIZIN=OFF
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /boot/system/lib/cmake/rz_core/rz_coreConfig.cmake:35 (find_library):
  Could not find rz_core_LIBRARY using the following names: rz_core
Call Stack (most recent call first):
  /boot/system/lib/cmake/Rizin/RizinConfig.cmake:96 (find_package)
  CMakeLists.txt:78 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Opslag/haikuports/dev-util/cutter/work-2.3.2/sources/cutter-2.3.2/build/CMakeFiles/CMakeOutput.log".

I've got a "fix" by re-importing the previous method to find rizin, but it's not a good one (although Cutter builds and runs fine on Haiku).

@Begasus
Copy link
Author

Begasus commented Sep 20, 2023

This started out for me as I went to update to cutter's version to 2.2.1.
We already had some conversation on that PR about it, thought I'd drop it here so it's easier to detect.
Previous PR and work-around: haikuports/haikuports#8713

@Begasus
Copy link
Author

Begasus commented Sep 20, 2023

Adding output log ...
CMakeOutput.log.txt

@Begasus
Copy link
Author

Begasus commented Sep 20, 2023

With patching still working (although still without decompiler)

Cutter-2 3 2

@Begasus
Copy link
Author

Begasus commented Sep 20, 2023

Wondering ... isn't there an option to force the search with pkg-config (as the pkgconfig files are already present)?

@XVilka XVilka added this to the 0.7.0 milestone Sep 21, 2023
@ret2libc
Copy link
Member

Hey @Begasus , sorry for the late reply but how did you install Rizin? Is there a package for Rizin on Haiku? Could you paste the content of /boot/system/lib/cmake/rz_core/rz_coreConfig.cmake please?

Also, could you tell me the exact path the rz_core library is in Haiku?

@Begasus
Copy link
Author

Begasus commented Oct 5, 2023

Quite busy atm on haikuports side, so sorry for not getting back sooner, I'll try to add some files for the build process and mentioned one.

rz_core in installed in /boot/system/lib (default on 64bit system) and /boot/system/lib/x86 (defaults for 32bit hybrid).

Build log:
Build_Rizin.txt

Contets of rz_coreConfig.cmake:

################################################################################
#
# This module provides the following imported targets, if found:
#
#  rz_core::rz_core
#
# This file is intended to be consumed by clients who wish to use rz_core from CMake.
# The recommended way to use find this module is using `find_package(Rizin COMPONENTS ...)`.
#
# Provides the following variables
# rz_core_FOUND        - Flag for indicating that rz_core package has been found
# rz_core_VERSION      - Version of rz_core
# rz_core_INCLUDE_DIRS - Directories to include
# rz_core_LIBRARY      - Path to the single library that this module represents, without dependencies
# rz_core_LIBRARIES    - Libraries to link
# rz_core_LIBRARY_DIRS - Library directories to search for link libraries
# rz_core_PLUGINDIR    - Directory where plugins are placed, without the prefix part
#
################################################################################

set(RIZIN_MODULE_PREFIXED rz_core)
set(rz_core_VERSION 0.6.2)

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

set(rz_core_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/develop/headers/librz" "${PACKAGE_PREFIX_DIR}/develop/headers/librz/sdb")
set_and_check(rz_core_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
find_library(rz_core_LIBRARY NAMES rz_core HINTS "${rz_core_LIBRARY_DIRS}" NO_DEFAULT_PATH REQUIRED)
set(rz_core_LIBRARIES "${rz_core_LIBRARY}")
set(_rz_core_DEPENDENCIES rz_magic rz_util rz_demangler rz_diff rz_reg rz_syscall rz_search rz_cons rz_analysis rz_socket rz_type rz_io rz_lang rz_hash rz_flag rz_parse rz_egg rz_debug rz_crypto rz_config rz_bin rz_asm rz_bp rz_sign rz_il)
set(rz_core_PLUGINDIR /packages/rizin-0.6.2-1/.self/data/rizin/cutter/plugins)

include(CMakeFindDependencyMacro)
get_filename_component(_rizin_cmake_path "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
set(_rz_core_DEPENDENCY_TARGETS)
foreach(_module_dep ${_rz_core_DEPENDENCIES})
  if (NOT ${_module_dep}_FOUND)
    find_dependency(${_module_dep} PATHS ${_rizin_cmake_path} NO_DEFAULT_PATH)
  endif()

  if (NOT ${_module_dep}_FOUND)
    set(rz_core_FOUND False)
    return()
  endif()

  list(APPEND rz_core_INCLUDE_DIRS "${${_module_dep}_INCLUDE_DIRS}")
  list(APPEND rz_core_LIBRARIES "${${_module_dep}_LIBRARIES}")
  list(APPEND _rz_core_DEPENDENCY_TARGETS "${_module_dep}::${_module_dep}")
endforeach()

list(REMOVE_DUPLICATES rz_core_INCLUDE_DIRS)
list(REMOVE_DUPLICATES rz_core_LIBRARIES)

if(NOT TARGET rz_core::rz_core)
  add_library(rz_core::rz_core SHARED IMPORTED)
  target_link_libraries(rz_core::rz_core INTERFACE ${_rz_core_DEPENDENCY_TARGETS})
  set_target_properties(rz_core::rz_core PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${rz_core_INCLUDE_DIRS}")
  set_target_properties(rz_core::rz_core PROPERTIES
    IMPORTED_LOCATION "${rz_core_LIBRARY}")
endif()
set(rz_core_TARGET rz_core::rz_core)

For the record, this is our recipe to build rizin for Haiku.
https://github.com/haikuports/haikuports/blob/master/dev-util/rizin/rizin-0.6.2.recipe

@ret2libc
Copy link
Member

ret2libc commented Oct 5, 2023

Can you also share the rz_userconf.h file of rizin?

I'm not 100% sure yet, but I think you should set the --prefix to /boot/system if that's where you are actually going to install rizin. Instead, in the meson logs I see this:

    prefix                    : /packages/rizin-0.6.2-1/.self
    bindir                    : bin
    libdir                    : lib
    includedir                : develop/headers/librz
    datadir                   : data
    wwwroot                   : data/rizin/www
    sdb                       : data/rizin
    sigdb                     : data/rizin/sigdb
    themes                    : data/rizin/cons
    fortunes                  : data/rizin/fortunes
    flags                     : data/rizin/flag
    hud                       : data/rizin/hud
    plugins                   : /packages/rizin-0.6.2-1/.self/data/rizin/cutter/plugins
    bindings                  : lib/rizin-bindings

@Begasus
Copy link
Author

Begasus commented Oct 5, 2023

prefix is set in the recipe (as you could have seen in the link in my previous comment), just in case pasting it here:

	meson build \
		--buildtype=release \
		--wrap=default \
		--prefix=$prefix \
		--bindir=$commandBinDir \
		--datadir=$dataDir \
		--libdir=$libDir \
		--includedir=$includeDir \
		--mandir=$manDir \
		-D default_library=shared \
		-D rizin_plugins=$dataDir/rizin/cutter/plugins \
		-D use_sys_capstone=enabled \
		-D use_sys_magic=enabled \
		-D use_sys_libmspack=enabled \
		-D use_sys_libzip=enabled \
		-D use_sys_zlib=enabled \
		-D use_sys_lzma=enabled \
		-D use_sys_lz4=enabled \
		-D use_sys_xxhash=enabled \
		-D use_sys_openssl=enabled \
		-D enable_tests=false \
		-D enable_rz_test=false \
		-D subprojects_check=false

	ninja -C build

$prefix actually points to /boot/system

Content of rz_userconf.h:

#ifndef RZ_CONFIGURE_H
#define RZ_CONFIGURE_H

#include "rz_build_version.h"

// clang-format off
#define RZ_CHECKS_LEVEL             1
#define DEBUGGER                    1
#define HAVE_THREADS                1
#define HAVE_PTHREAD                1
#define HAVE_LZMA                   1
#define HAVE_ZLIB                   1
#define HAVE_DECL_ADDR_NO_RANDOMIZE 0
#define HAVE_DECL_PROCCTL_ASLR_CTL  0
#define HAVE_ARC4RANDOM_UNIFORM     0
#define HAVE_EXPLICIT_BZERO         0
#define HAVE_EXPLICIT_MEMSET        0
#define HAVE_CLOCK_NANOSLEEP        1
#define HAVE_SIGACTION              1
#define HAVE_PIPE                   1
#define HAVE_EXECV                  1
#define HAVE_EXECVE                 1
#define HAVE_EXECVP                 1
#define HAVE_EXECL                  1
#define HAVE_SYSTEM                 1
#define HAVE_REALPATH               1
#define HAVE_PIPE2                  0
#define HAVE_ENVIRON                1
#define HAVE_OPENPTY                0
#define HAVE_FORKPTY                0
#define HAVE_LOGIN_TTY              0
#define HAVE_SHM_OPEN               1
#define HAVE_LIB_MAGIC              1
#define USE_LIB_MAGIC               1
#define HAVE_LIB_XXHASH             1
#define USE_LIB_XXHASH              1
#define HAVE_LIB_SSL                1
#define HAVE_PTRACE                 0
#define USE_PTRACE_WRAP             0
#define HAVE_FORK                   1
#define HAVE_STRLCPY                1
#define HAVE_STRNLEN                1
#define WANT_DYLINK                 1
#define WITH_GPL                    1
#define HAVE_JEMALLOC               1
#define IS_IOS                      0
#define RZ_BUILD_DEBUG              0
#define WITH_SWIFT_DEMANGLER        1
#define HAVE_COPYFILE               0
#define HAVE_COPY_FILE_RANGE        0
#define HAVE_BACKTRACE              0
#define HAVE___BUILTIN_BSWAP16      1
#define HAVE___BUILTIN_BSWAP32      1
#define HAVE___BUILTIN_BSWAP64      1
#define HAVE_POSIX_MEMALIGN         1
#define HAVE__ALIGNED_MALLOC        0

#define HAVE_HEADER_LINUX_ASHMEM_H  0
#define HAVE_HEADER_SYS_SHM_H       0
#define HAVE_HEADER_SYS_IPC_H       1
#define HAVE_HEADER_SYS_MMAN_H      1
#define HAVE_HEADER_INTTYPES_H      1

#define RZ_IS_PORTABLE 0

#define RZ_BINDIR_DEPTH 1
// clang-format on

#define RZ_PREFIX "/packages/rizin-0.6.2-1/.self"
#define RZ_BINDIR "bin"
#define RZ_LIBDIR "lib"
#define RZ_INCDIR "develop/headers/librz"
#define RZ_DATDIR "data"

#define RZ_WWWROOT  "data/rizin/www"
#define RZ_PLUGINS  "/packages/rizin-0.6.2-1/.self/data/rizin/cutter/plugins"
#define RZ_DATADIR  "data/rizin"
#define RZ_SDB      "data/rizin"
#define RZ_SIGDB    "data/rizin/sigdb"
#define RZ_THEMES   "data/rizin/cons"
#define RZ_FORTUNES "data/rizin/fortunes"
#define RZ_FLAGS    "data/rizin/flag"
#define RZ_HUD      "data/rizin/hud"

#define RZ_SDB_ARCH_PLATFORMS RZ_JOIN_3_PATHS(RZ_SDB, "asm", "platforms")
#define RZ_SDB_ARCH_CPUS      RZ_JOIN_3_PATHS(RZ_SDB, "asm", "cpus")
#define RZ_SDB_TYPES          RZ_JOIN_2_PATHS(RZ_SDB, "types")
#define RZ_SDB_OPCODES        RZ_JOIN_2_PATHS(RZ_SDB, "opcodes")
#define RZ_SDB_REG            RZ_JOIN_2_PATHS(RZ_SDB, "reg")
#define RZ_SDB_MAGIC          RZ_JOIN_2_PATHS(RZ_SDB, "magic")
#define RZ_SDB_FORMAT         RZ_JOIN_2_PATHS(RZ_SDB, "format")
#define RZ_PDB                RZ_JOIN_2_PATHS(RZ_DATADIR, "pdb")
#define RZ_PROJECTS           RZ_JOIN_2_PATHS(RZ_DATADIR, "projects")
#define RZ_BINRC              RZ_JOIN_2_PATHS(RZ_DATADIR, "rc.d")

#define RZ_HOME_PREFIX    ".local"
#define RZ_HOME_CONFIGDIR RZ_JOIN_2_PATHS(".config", "rizin")
#define RZ_HOME_CACHEDIR  RZ_JOIN_2_PATHS(".cache", "rizin")

#define RZ_HOME_HISTORY RZ_JOIN_2_PATHS(RZ_HOME_CACHEDIR, "history")

#define RZ_HOME_CONFIG_RC     RZ_JOIN_2_PATHS(RZ_HOME_CONFIGDIR, "rizinrc")
#define RZ_HOME_CONFIG_RC_DIR RZ_JOIN_2_PATHS(RZ_HOME_CONFIGDIR, "rizinrc.d")
#define RZ_GLOBAL_RC          RZ_JOIN_2_PATHS(RZ_DATADIR, "rizinrc")
#define RZ_HOME_RC            ".rizinrc"

// This is an optional extra prefix used to load plugins, sdb files, sdb files,
// etc. It can be outside the default prefix. Used e.g. by Homebrew to load
// plugins from the general /opt/homebrew prefix instead of the version specific
// prefix e.g. /opt/homebrew/Cellar/rizin/0.x.y/
// clang-format off
#define RZ_EXTRA_PREFIX 0
// clang-format on

#endif

@ret2libc
Copy link
Member

ret2libc commented Oct 6, 2023

prefix is set in the recipe (as you could have seen in the link in my previous comment), just in case pasting it here:

I've looked at the recipe and I see where it is set, however...

$prefix actually points to /boot/system

This is not what the rizin build logs say.

    prefix                    : /packages/rizin-0.6.2-1/.self
    bindir                    : bin
    libdir                    : lib
    includedir                : develop/headers/librz

Content of rz_userconf.h:

#define RZ_PREFIX "/packages/rizin-0.6.2-1/.self"
#define RZ_BINDIR "bin"
#define RZ_LIBDIR "lib"
#define RZ_INCDIR "develop/headers/librz"
#define RZ_DATDIR "data"

#define RZ_WWWROOT  "data/rizin/www"
#define RZ_PLUGINS  "/packages/rizin-0.6.2-1/.self/data/rizin/cutter/plugins"

You can see it here as well that RZ_PREFIX/aka prefix is not /boot/system. Is it a symlink maybe? Anyway, I think it would be better to set it straight to /boot/system if possible.

@Begasus
Copy link
Author

Begasus commented Oct 6, 2023

Packages are created as archived ones, once they are installed all the contect is available in /boot/system, as all our packages are and can be found by other packages requiring them. Installing directly to /boot/system is not possible as the system directories are read-only.
Building them is done in a chroot environment where the packages are "mounted" and available by for others.

@ret2libc
Copy link
Member

ret2libc commented Oct 6, 2023

Right, in those cases I think the common approach is to use the prefix that you would like to have (/boot/system in this case) but use a destdir during the install phase. Would that work for Haiku?

It would be something like this:

$ meson setup --prefix=/boot/system build
$ meson compile -C build
$ meson install -C build --destdir=/tmp/dir/
$ tree /tmp/dir/
/tmp/dir
└── boot
    └── system
        ├── bin
        │   ├── rizin
        │   ├── rz-asm
        │   ├── rz-ax
        │   ├── rz-bin
        │   ├── rz-diff
        │   ├── rz-find
        │   ├── rz-gg
        │   ├── rz-hash
        │   ├── rz-run
        │   ├── rz-sign
        │   └── rz-test
        ├── include
        │   └── librz
        │       ├── rz_agraph.h
        │       ├── rz_analysis.h
        │       ├── rz_asm.h
        │       ├── rz_basefind.h
        │       ├── rz_bin.h
[...]

@Begasus
Copy link
Author

Begasus commented Oct 18, 2023

Need to still investigate this, doing other ports in between, will get back to you, but so far this has never been done in our ports.

@XVilka XVilka modified the milestones: 0.7.0, 0.8.0 Feb 24, 2024
@ret2libc
Copy link
Member

Any news here?

@Begasus
Copy link
Author

Begasus commented Feb 27, 2024

At least no progress, tried a few things on my end with no luck. (has been a while though)

@Begasus
Copy link
Author

Begasus commented Mar 9, 2024

OK, tried using the mentioned way setting prefix to /boot/system etc. , still getting an error not finding rz_core

waiting for build package cutter-2.3.4-1 to be activated
Building ...
CMake Error at /boot/system/lib/cmake/rz_core/rz_coreConfig.cmake:35 (find_library):
  Could not find rz_core_LIBRARY using the following names: rz_core
Call Stack (most recent call first):
  /boot/system/lib/cmake/Rizin/RizinConfig.cmake:96 (find_package)
  CMakeLists.txt:78 (find_package)

From rz_userconf.h:

#define RZ_PREFIX "/boot/system"
#define RZ_BINDIR "bin"
#define RZ_LIBDIR "lib"
#define RZ_INCDIR "develop/headers/librz"
#define RZ_DATDIR "data"

#define RZ_WWWROOT  "data/rizin/www"
#define RZ_PLUGINS  "/boot/system/data/rizin/cutter/plugins"
#define RZ_DATADIR  "data/rizin"
#define RZ_SDB      "data/rizin"
#define RZ_SIGDB    "data/rizin/sigdb"
#define RZ_THEMES   "data/rizin/cons"
#define RZ_FORTUNES "data/rizin/fortunes"
#define RZ_FLAGS    "data/rizin/flag"
#define RZ_HUD      "data/rizin/hud"

From rz_coreConfig.cmake:

set(rz_core_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/develop/headers/librz" "${PACKAGE_PREFIX_DIR}/develop/headers/librz/sdb")
set_and_check(rz_core_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
find_library(rz_core_LIBRARY NAMES rz_core HINTS "${rz_core_LIBRARY_DIRS}" NO_DEFAULT_PATH REQUIRED)
set(rz_core_LIBRARIES "${rz_core_LIBRARY}")
set(_rz_core_DEPENDENCIES rz_magic rz_util rz_demangler rz_diff rz_reg rz_syscall rz_search rz_cons rz_analysis rz_socket rz_type rz_io rz_lang rz_hash rz_flag rz_parse rz_egg rz_debug rz_crypto rz_config rz_bin rz_asm rz_bp rz_sign rz_il)
set(rz_core_PLUGINDIR /boot/system/data/rizin/cutter/plugins)

@ret2libc
Copy link
Member

@Begasus could you paste a bit more from the rz_coreConfig.cmake file? In particular, i'd be interested in the line get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}.....). Thanks a lot! Hopefully we can fix this!

@Begasus
Copy link
Author

Begasus commented Mar 13, 2024

From a default build:

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)

When using --prefix=/boot/system:

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../../../boot/system" ABSOLUTE)

EDIT: got the wrong file for the second line :)

@ret2libc
Copy link
Member

@Begasus is there a fast way for me to test a Haiku machine?

@Begasus
Copy link
Author

Begasus commented Mar 14, 2024

@ret2libc Quickest way I guess would be to setup a VM:

  1. Grab an iso from: https://www.haiku-os.org/get-haiku/r1beta4/ and use the iso to install the OS on a virtual disk (I gues you are familiar enough on how to install virtual machines).
  2. Launch the installed system and open a Terminal window, then run an update (the beta has had some updates that are good to have around), in Terminal type pkgman full-sync (pkgman is our package manager)
  3. Restart the virtual machine once the updates have finished
  4. After restart launch a Terminal session again, grab the sources for rizin/cutter and extract to a place to your liking, use a prefix like -DCMAKE_INSTALL_PREFIX=/boot/home/config/non-packaged (this path is also in $PATH so being detected by the system).
  5. Everything should be available for building, so if you find something missing you can install them with pkgman, for instance liblzma, you will need the headers for those depending libraries and can install them like pkgman install liblzma_devel (this will also install the basic package providing only the libraries if not installed already).

If you need assistance, I'm mostly online and can be contacted at IRC (OFTC #haiku), or over matrix (@begasushaiku:matrix.org)

EDIT, for liblzma you need xz_utils_devel (you can search for a library/cmd etc like: pkgman search lib:liblzma or pkgman search devel:liblzma or just pkgman search liblzma).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants