Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: Ole Schuerks <ole0811sch@gmail.com>
To: linux-kbuild@vger.kernel.org
Cc: ole0811sch@gmail.com, jude.gyimah@rub.de, thorsten.berger@rub.de,
	deltaone@debian.org, jan.sollmann@rub.de, mcgrof@kernel.org,
	masahiroy@kernel.org, linux-kernel@vger.kernel.org,
	nathan@kernel.org, nicolas@fjasle.eu
Subject: [PATCH v5 01/11] kconfig: Add PicoSAT interface
Date: Fri, 20 Sep 2024 10:56:18 +0200	[thread overview]
Message-ID: <20240920085628.51863-2-ole0811sch@gmail.com> (raw)
In-Reply-To: <20240920085628.51863-1-ole0811sch@gmail.com>

PicoSAT (https://fmv.jku.at/picosat/) is the SAT solver used in this
project. It is used as a dynamically loaded library. This commit contains a
script that installs PicoSAT as a library on the host system, a source file
that provides a function for loading a subset of functions from the
library, and a header file that declares these functions.

Signed-off-by: Patrick Franz <deltaone@debian.org>
Signed-off-by: Ibrahim Fayaz <phayax@gmail.com>
Signed-off-by: Thorsten Berger <thorsten.berger@rub.de>
Signed-off-by: Ole Schuerks <ole0811sch@gmail.com>
---
 scripts/kconfig/install-picosat.sh  | 29 +++++++++++
 scripts/kconfig/picosat_functions.c | 74 +++++++++++++++++++++++++++++
 scripts/kconfig/picosat_functions.h | 35 ++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100755 scripts/kconfig/install-picosat.sh
 create mode 100644 scripts/kconfig/picosat_functions.c
 create mode 100644 scripts/kconfig/picosat_functions.h

diff --git a/scripts/kconfig/install-picosat.sh b/scripts/kconfig/install-picosat.sh
new file mode 100755
index 000000000000..aadfa9582ecb
--- /dev/null
+++ b/scripts/kconfig/install-picosat.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+psinstdir=$(mktemp -d)
+if [ $? -ne 0 ]; then
+	echo "mktemp failed"
+	exit 1
+fi
+cd $psinstdir
+wget "https://fmv.jku.at/picosat/picosat-965.tar.gz"
+tar -xf picosat-965.tar.gz
+cd picosat-965
+cp makefile.in makefile.in2
+# change soname to conform with packages for Debian and Fedora
+sed -e "s,-soname -Xlinker libpicosat.so,-soname -Xlinker	\
+	libpicosat-trace.so.0," makefile.in2 > makefile.in
+./configure.sh -O -t --shared
+make libpicosat.so
+install -m 0755 -p libpicosat.so /usr/local/lib/libpicosat-trace.so.0.0.965	\
+&& ln -s -f libpicosat-trace.so.0.0.965 /usr/local/lib/libpicosat-trace.so.0	\
+&& ln -s -f libpicosat-trace.so.0 /usr/local/lib/libpicosat-trace.so \
+&& ldconfig
+echo
+if [ $? -ne 0 ]; then
+	echo "Installation of PicoSAT failed, make sure you are running with root privileges."
+	exit 1
+else
+	echo "Installation of PicoSAT succeeded."
+fi
diff --git a/scripts/kconfig/picosat_functions.c b/scripts/kconfig/picosat_functions.c
new file mode 100644
index 000000000000..ada42abbc22b
--- /dev/null
+++ b/scripts/kconfig/picosat_functions.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <dlfcn.h>
+#include <unistd.h>
+
+#include "array_size.h"
+
+#include "cf_defs.h"
+#include "picosat_functions.h"
+
+const char *picosat_lib_names[] = { "libpicosat-trace.so",
+				    "libpicosat-trace.so.0",
+				    "libpicosat-trace.so.1" };
+
+PicoSAT *(*picosat_init)(void);
+int (*picosat_add)(PicoSAT *pico, int lit);
+int (*picosat_deref)(PicoSAT *pico, int lit);
+void (*picosat_assume)(PicoSAT *pico, int lit);
+int (*picosat_sat)(PicoSAT *pico, int decision_limit);
+const int *(*picosat_failed_assumptions)(PicoSAT *pico);
+int (*picosat_added_original_clauses)(PicoSAT *pico);
+int (*picosat_enable_trace_generation)(PicoSAT *pico);
+void (*picosat_print)(PicoSAT *pico, FILE *file);
+
+#define PICOSAT_FUNCTION_LIST             \
+	X(picosat_init)                   \
+	X(picosat_add)                    \
+	X(picosat_deref)                  \
+	X(picosat_assume)                 \
+	X(picosat_sat)                    \
+	X(picosat_failed_assumptions)     \
+	X(picosat_added_original_clauses) \
+	X(picosat_enable_trace_generation)\
+	X(picosat_print)
+
+static void load_function(const char *name, void **ptr, void *handle, bool *failed)
+{
+	if (*failed)
+		return;
+
+	*ptr = dlsym(handle, name);
+	if (!*ptr) {
+		printd("While loading %s: %s\n", name, dlerror());
+		*failed = true;
+	}
+}
+
+bool load_picosat(void)
+{
+	void *handle = NULL;
+	bool failed = false;
+
+	/*
+	 * Try different names for the .so library. This is necessary since
+	 * all packages don't use the same versioning.
+	 */
+	for (int i = 0; i < ARRAY_SIZE(picosat_lib_names) && !handle; ++i)
+		handle = dlopen(picosat_lib_names[i], RTLD_LAZY);
+	if (!handle) {
+		printd("%s\n", dlerror());
+		return false;
+	}
+
+#define X(name) load_function(#name, (void **) &name, handle, &failed);
+
+	PICOSAT_FUNCTION_LIST
+#undef X
+
+	if (failed) {
+		dlclose(handle);
+		return false;
+	} else
+		return true;
+}
diff --git a/scripts/kconfig/picosat_functions.h b/scripts/kconfig/picosat_functions.h
new file mode 100644
index 000000000000..5d8524afa844
--- /dev/null
+++ b/scripts/kconfig/picosat_functions.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef PICOSAT_FUNCTIONS_H
+#define PICOSAT_FUNCTIONS_H
+
+#include <stdbool.h>
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PICOSAT_UNKNOWN         0
+#define PICOSAT_SATISFIABLE     10
+#define PICOSAT_UNSATISFIABLE   20
+
+typedef struct PicoSAT PicoSAT;
+
+extern PicoSAT *(*picosat_init)(void);
+extern int (*picosat_add)(PicoSAT *pico, int lit);
+extern int (*picosat_deref)(PicoSAT *pico, int lit);
+extern void (*picosat_assume)(PicoSAT *pico, int lit);
+extern int (*picosat_sat)(PicoSAT *pico, int decision_limit);
+extern const int *(*picosat_failed_assumptions)(PicoSAT *pico);
+extern int (*picosat_added_original_clauses)(PicoSAT *pico);
+extern int (*picosat_enable_trace_generation)(PicoSAT *pico);
+extern void (*picosat_print)(PicoSAT *pico, FILE *file);
+
+bool load_picosat(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PICOSAT_FUNCTIONS_H
-- 
2.39.2


  reply	other threads:[~2024-09-20  8:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-20  8:56 [PATCH v5 00/11] kbuild, kconfig: Add support for conflict resolution Ole Schuerks
2024-09-20  8:56 ` Ole Schuerks [this message]
2024-09-20 11:11   ` [PATCH v5 01/11] kconfig: Add PicoSAT interface Luis Chamberlain
2024-09-20  8:56 ` [PATCH v5 02/11] kbuild: Add list_is_{first,last}, list_size, list_at_index, list_for_each_from Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 03/11] kconfig: Add definitions Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 04/11] kconfig: Add files for building constraints Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 05/11] kconfig: Add files for handling expressions Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 06/11] kconfig: Add files for RangeFix Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 07/11] kconfig: Add files with utility functions Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 08/11] kconfig: Add tools Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 09/11] kconfig: Add xconfig-modifications Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 10/11] kconfig: Add loader.gif Ole Schuerks
2024-09-20  8:56 ` [PATCH v5 11/11] kconfig: Add documentation for the conflict resolver Ole Schuerks
2025-01-13 16:35   ` Brendan Jackman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240920085628.51863-2-ole0811sch@gmail.com \
    --to=ole0811sch@gmail.com \
    --cc=deltaone@debian.org \
    --cc=jan.sollmann@rub.de \
    --cc=jude.gyimah@rub.de \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas@fjasle.eu \
    --cc=thorsten.berger@rub.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox