-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Type: new featureThe issue requests / The PR implemements a new feature for RIOTThe issue requests / The PR implemements a new feature for RIOT
Description
Description
Building native
for 32 bit musl fails.
Steps to reproduce the issue
make -C examples/default BOARD=native
fails on 32 bit musl systems with libucontext-dev installed.
Expected results
Compilation anf linking succeeds.
Actual results
Compilation fails.
Versions
Current development branch and current release RC
Suggested Fix
From 9761583a631ebf008b3157432014e8eacebb0445 Mon Sep 17 00:00:00 2001
From: Marian Buschsieweke <mari.hahn@wwu.de>
Date: Sun, 20 Nov 2022 12:07:38 +0100
Subject: [PATCH] cpu/native: fix compilation with musl
---
cpu/native/Makefile.include | 7 +++++++
cpu/native/irq_cpu.c | 13 +++++++------
cpu/native/native_cpu.c | 18 ++++++++++++------
cpu/native/periph/timer.c | 6 ++++--
4 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/cpu/native/Makefile.include b/cpu/native/Makefile.include
index 5a18218c57..e7cc0d73fa 100644
--- a/cpu/native/Makefile.include
+++ b/cpu/native/Makefile.include
@@ -13,3 +13,10 @@ TOOLCHAINS_SUPPORTED = gnu llvm afl
ifeq ($(OS) $(OS_ARCH),Linux x86_64)
RUST_TARGET = i686-unknown-linux-gnu
endif
+
+USE_LIBUCONTEXT := $(shell pkg-config libucontext 2> /dev/null && echo 1 || echo 0)
+
+ifeq ($(USE_LIBUCONTEXT),1)
+ CFLAGS += $(pkg-config libucontext --cflags) -DUSE_LIBUCONTEXT=1
+ LINKFLAGS += $(shell pkg-config libucontext --libs)
+endif
diff --git a/cpu/native/irq_cpu.c b/cpu/native/irq_cpu.c
index e27f88243a..026c9668c5 100644
--- a/cpu/native/irq_cpu.c
+++ b/cpu/native/irq_cpu.c
@@ -13,10 +13,16 @@
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
*/
+/* __USE_GNU for gregs[REG_EIP] access under glibc
+ * _GNU_SOURCE for REG_EIP and strsignal() under musl */
+#define __USE_GNU
+#define _GNU_SOURCE
+
#include <err.h>
+#include <signal.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stdlib.h>
#ifdef HAVE_VALGRIND_H
#include <valgrind.h>
@@ -29,11 +35,6 @@
#define VALGRIND_DEBUG(...)
#endif
-/* __USE_GNU for gregs[REG_EIP] access under Linux */
-#define __USE_GNU
-#include <signal.h>
-#undef __USE_GNU
-
#include "irq.h"
#include "cpu.h"
#include "periph/pm.h"
diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c
index 87370a89ea..c8c6998c1b 100644
--- a/cpu/native/native_cpu.c
+++ b/cpu/native/native_cpu.c
@@ -21,16 +21,22 @@
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
+/* __USE_GNU for gregs[REG_EIP] access under glibc
+ * _GNU_SOURCE for REG_EIP and strsignal() under musl */
#define __USE_GNU
+#define _GNU_SOURCE
+
+#include <err.h>
#include <signal.h>
-#undef __USE_GNU
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef USE_LIBUCONTEXT
+#include <libucontext/libucontext.h>
+#else
#include <ucontext.h>
-#include <err.h>
+#endif
#ifdef HAVE_VALGRIND_H
#include <valgrind.h>
diff --git a/cpu/native/periph/timer.c b/cpu/native/periph/timer.c
index 84e5d27072..2c10cac94b 100644
--- a/cpu/native/periph/timer.c
+++ b/cpu/native/periph/timer.c
@@ -111,7 +111,8 @@ static void do_timer_set(unsigned int offset, bool periodic)
itv.it_interval = itv.it_value;
}
- DEBUG("timer_set(): setting %lu.%06lu\n", itv.it_value.tv_sec, itv.it_value.tv_usec);
+ DEBUG("timer_set(): setting %" PRIu64 ".%06" PRIu32 "\n",
+ (uint64_t)itv.it_value.tv_sec, (uint32_t)itv.it_value.tv_usec);
}
int timer_set(tim_t dev, int channel, unsigned int offset)
@@ -189,7 +190,8 @@ void timer_stop(tim_t dev)
}
_native_syscall_leave();
- DEBUG("time left: %lu.%06lu\n", itv.it_value.tv_sec, itv.it_value.tv_usec);
+ DEBUG("time left: %" PRIu64 ".%06" PRIu32 "\n",
+ (uint64_t)itv.it_value.tv_sec, (uint32_t)itv.it_value.tv_usec);
}
unsigned int timer_read(tim_t dev)
--
2.38.1
Metadata
Metadata
Assignees
Labels
Type: new featureThe issue requests / The PR implemements a new feature for RIOTThe issue requests / The PR implemements a new feature for RIOT