From 687c90dea774c21ec7366d47ff27f787ec8045a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sat, 10 Feb 2024 00:31:28 +0100 Subject: [PATCH] main/libucontext: fix build with -Os on x86 See: * https://github.com/kaniini/libucontext/issues/52#issuecomment-1936736286 * https://github.com/kaniini/libucontext/pull/60 --- ...ine-Ensure-omission-of-frame-pointer.patch | 47 +++++++++++++++++++ main/libucontext/APKBUILD | 10 ++-- 2 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 main/libucontext/0001-common-trampoline-Ensure-omission-of-frame-pointer.patch diff --git a/main/libucontext/0001-common-trampoline-Ensure-omission-of-frame-pointer.patch b/main/libucontext/0001-common-trampoline-Ensure-omission-of-frame-pointer.patch new file mode 100644 index 00000000000..cb0c588b8fd --- /dev/null +++ b/main/libucontext/0001-common-trampoline-Ensure-omission-of-frame-pointer.patch @@ -0,0 +1,47 @@ +From 13437174df7cd45873cf2d1d9c4c4277e2db8a5a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= +Date: Sat, 10 Feb 2024 00:13:28 +0100 +Subject: [PATCH] common-trampoline: Ensure omission of frame-pointer + +Some architecture-specific implementations of the FETCH_LINKPTR +(e.g. the one for x86) attempt to find the linkptr relative to the +stack pointer. Therefore, they make assumption about the value of +the SP at the point where the FETCH_LINKPTR code is executed. This +means that we don't want the C compiler to mess with our SP. + +For this purpose, local variables in this function are currently +declared using the register storage specifier. Additionally, we +need to make sure that a frame pointer is /always/ omitted for +this function. On x86 Alpine, the frame pointer is presently not +omitted with GCC 13 when using -Os, therefore the tests segfault +with -Os on Alpine presently. + +Fixes #52 +--- + arch/common/common-trampoline.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/arch/common/common-trampoline.c b/arch/common/common-trampoline.c +index 5b52327..41f994b 100644 +--- a/arch/common/common-trampoline.c ++++ b/arch/common/common-trampoline.c +@@ -14,7 +14,19 @@ + #include + #include + ++/* We need to make sure that the C compiler doesn't push any ++ * additional data to the stack frame. Otherwise, assumptions ++ * made by the architecture-specific implementation of the ++ * FETCH_LINKPTR() macro about the location of the linkptr, ++ * relative to the stack pointer, will not hold. ++ * ++ * Hence, we compile this function with -fomit-frame-pointer ++ * and use the register storage-class specifier for all local ++ * vars. Note that the latter is just a "suggestion" (see C99). ++ */ ++ + __attribute__ ((visibility ("hidden"))) ++__attribute__ ((optimize ("omit-frame-pointer"))) + void + libucontext_trampoline(void) + { diff --git a/main/libucontext/APKBUILD b/main/libucontext/APKBUILD index acb88ac9955..25242d05f48 100644 --- a/main/libucontext/APKBUILD +++ b/main/libucontext/APKBUILD @@ -1,14 +1,15 @@ # Maintainer: Ariadne Conill pkgname=libucontext pkgver=1.2 -pkgrel=2 +pkgrel=3 pkgdesc="ucontext function implementations" url="https://github.com/kaniini/libucontext" arch="all" license="ISC" subpackages="$pkgname-dev $pkgname-doc" makedepends="scdoc" -source="https://distfiles.ariadne.space/libucontext/libucontext-$pkgver.tar.xz" +source="https://distfiles.ariadne.space/libucontext/libucontext-$pkgver.tar.xz + 0001-common-trampoline-Ensure-omission-of-frame-pointer.patch" case "$CTARGET_ARCH" in arm*) LIBUCONTEXT_ARCH="arm" ;; @@ -17,10 +18,6 @@ case "$CTARGET_ARCH" in esac build() { - # workaround segfault on x86 with -Os - # https://github.com/kaniini/libucontext/issues/52 - CFLAGS="$CFLAGS -O2" - make ARCH="$LIBUCONTEXT_ARCH" make ARCH="$LIBUCONTEXT_ARCH" docs } @@ -35,4 +32,5 @@ package() { sha512sums=" 6603f2dcd87c4d9919c1726f2964632483e1a647733ff543d5935e3e2dac548adf320f1f9fb4c494691fe99fb393d64b15369f04d3783b2ca4c40b68c3d87865 libucontext-1.2.tar.xz +4e797976943dcc98dbc2541a17e517da1b95ed50e0c730c547ccc604e682d1150e90c6bb29f601549b6a0bf4b7228e7a7d9883e97ea6bff4d12956df6b9a1195 0001-common-trampoline-Ensure-omission-of-frame-pointer.patch "