From 9f7e47368fe7d8bea4c9b411dd1027f375c8b5af Mon Sep 17 00:00:00 2001 From: Benjamin Lamowski Date: Wed, 16 Aug 2023 17:11:29 +0200 Subject: [PATCH] libports: transform `compat-libc` into a static library Dynamically loading the `compat-libc` breaks `fork(2)` on Genode. Switch `compat-libc` to a special api package that provides a source file for statically linking the library, analogous to the `blit` package. This also requires a quirk in Goa but should prevent breaking `fork()` and removes the runtime and archive dependencies for Rust packages using `compat-libc`. Ref genodelabs/goa#61 --- repos/libports/lib/mk/compat-libc.mk | 5 --- repos/libports/lib/symbols/compat-libc | 2 - .../recipes/api/compat-libc/content.mk | 8 +--- repos/libports/recipes/api/compat-libc/hash | 2 +- repos/libports/recipes/src/compat-libc/api | 1 - .../recipes/src/compat-libc/content.mk | 10 ----- repos/libports/recipes/src/compat-libc/hash | 1 - .../recipes/src/compat-libc/used_apis | 2 - repos/libports/src/lib/compat-libc/compat.cc | 38 ++++++++++++++-- repos/libports/src/lib/compat-libc/libc.c | 43 ------------------- repos/libports/src/lib/compat-libc/libc.h | 20 --------- repos/libports/src/lib/compat-libc/symbol.map | 8 ---- 12 files changed, 37 insertions(+), 103 deletions(-) delete mode 100644 repos/libports/lib/symbols/compat-libc delete mode 100644 repos/libports/recipes/src/compat-libc/api delete mode 100644 repos/libports/recipes/src/compat-libc/content.mk delete mode 100644 repos/libports/recipes/src/compat-libc/hash delete mode 100644 repos/libports/recipes/src/compat-libc/used_apis delete mode 100644 repos/libports/src/lib/compat-libc/libc.c delete mode 100644 repos/libports/src/lib/compat-libc/libc.h delete mode 100644 repos/libports/src/lib/compat-libc/symbol.map diff --git a/repos/libports/lib/mk/compat-libc.mk b/repos/libports/lib/mk/compat-libc.mk index f6e8ec19e3..ebe239713e 100644 --- a/repos/libports/lib/mk/compat-libc.mk +++ b/repos/libports/lib/mk/compat-libc.mk @@ -1,14 +1,9 @@ -SHARED_LIB = yes LIBS += libc COMPAT_DIR = $(REP_DIR)/src/lib/compat-libc SRC_CC = compat.cc -SRC_C = libc.c vpath %.cc $(COMPAT_DIR) -vpath %.c $(COMPAT_DIR) - -LD_OPT += --version-script=$(COMPAT_DIR)/symbol.map CC_CXX_WARN_STRICT_CONVERSION = diff --git a/repos/libports/lib/symbols/compat-libc b/repos/libports/lib/symbols/compat-libc deleted file mode 100644 index b1bae03ee0..0000000000 --- a/repos/libports/lib/symbols/compat-libc +++ /dev/null @@ -1,2 +0,0 @@ -fstat T -stat T diff --git a/repos/libports/recipes/api/compat-libc/content.mk b/repos/libports/recipes/api/compat-libc/content.mk index fd9b3b670f..dda0639372 100644 --- a/repos/libports/recipes/api/compat-libc/content.mk +++ b/repos/libports/recipes/api/compat-libc/content.mk @@ -1,16 +1,10 @@ -MIRROR_FROM_REP_DIR := lib/symbols/compat-libc +MIRROR_FROM_REP_DIR := lib/mk/compat-libc.mk src/lib/compat-libc content: $(MIRROR_FROM_REP_DIR) LICENSE $(MIRROR_FROM_REP_DIR): $(mirror_from_rep_dir) -content: lib/symbol.map - -lib/symbol.map: - cp $(REP_DIR)/src/lib/compat-libc/symbol.map $@ - - LICENSE: cp $(GENODE_DIR)/LICENSE $@ diff --git a/repos/libports/recipes/api/compat-libc/hash b/repos/libports/recipes/api/compat-libc/hash index aed0203b8b..ee1d0961d6 100644 --- a/repos/libports/recipes/api/compat-libc/hash +++ b/repos/libports/recipes/api/compat-libc/hash @@ -1 +1 @@ -2023-06-12 1ce2539b566b8d0d1a1f9919b8c7543f32467679 +2023-08-16 e490a07341485a2514c6f57bbc0d83bd63d7d9a1 diff --git a/repos/libports/recipes/src/compat-libc/api b/repos/libports/recipes/src/compat-libc/api deleted file mode 100644 index 901f5e03c1..0000000000 --- a/repos/libports/recipes/src/compat-libc/api +++ /dev/null @@ -1 +0,0 @@ -compat-libc diff --git a/repos/libports/recipes/src/compat-libc/content.mk b/repos/libports/recipes/src/compat-libc/content.mk deleted file mode 100644 index dda0639372..0000000000 --- a/repos/libports/recipes/src/compat-libc/content.mk +++ /dev/null @@ -1,10 +0,0 @@ -MIRROR_FROM_REP_DIR := lib/mk/compat-libc.mk src/lib/compat-libc - -content: $(MIRROR_FROM_REP_DIR) LICENSE - -$(MIRROR_FROM_REP_DIR): - $(mirror_from_rep_dir) - -LICENSE: - cp $(GENODE_DIR)/LICENSE $@ - diff --git a/repos/libports/recipes/src/compat-libc/hash b/repos/libports/recipes/src/compat-libc/hash deleted file mode 100644 index ed29abeacc..0000000000 --- a/repos/libports/recipes/src/compat-libc/hash +++ /dev/null @@ -1 +0,0 @@ -2023-06-12-a b499380d630694fbe520d666320b5bba333fce25 diff --git a/repos/libports/recipes/src/compat-libc/used_apis b/repos/libports/recipes/src/compat-libc/used_apis deleted file mode 100644 index 4011ccc3b3..0000000000 --- a/repos/libports/recipes/src/compat-libc/used_apis +++ /dev/null @@ -1,2 +0,0 @@ -libc -so diff --git a/repos/libports/src/lib/compat-libc/compat.cc b/repos/libports/src/lib/compat-libc/compat.cc index 4c52c14ecc..ba9779513a 100644 --- a/repos/libports/src/lib/compat-libc/compat.cc +++ b/repos/libports/src/lib/compat-libc/compat.cc @@ -15,8 +15,10 @@ #define _WANT_FREEBSD11_STAT /* enable freebsd11_stat */ #define _KERNEL /* disable 'stat' */ #include -#include "libc.h" +#include +extern "C" int libc_stat(const char *, struct stat*); +extern "C" int libc_fstat(int, struct stat *); static void _to_freebsd11(struct stat *libc_buf, struct freebsd11_stat *buf) { @@ -36,8 +38,35 @@ static void _to_freebsd11(struct stat *libc_buf, struct freebsd11_stat *buf) buf->st_birthtim = libc_buf->st_birthtim; } +static void* libc_handle(void) +{ + static void *handle = NULL; + if (!handle) handle = dlopen("libc.lib.so", RTLD_LAZY); + return handle; +} -extern "C" int stat(const char *path, struct freebsd11_stat *buf) + +int (*_stat)(char const*, struct stat*); +int (*_fstat)(int, struct stat *); + +int libc_stat(const char *path, struct stat *buf) +{ + if (!_stat) + _stat = (int (*)(const char*, struct stat*)) dlsym(libc_handle(), "stat"); + + return _stat(path, buf); +} + + +int libc_fstat(int fd, struct stat *buf) +{ + if (!_fstat) + _fstat = (int (*)(int, struct stat*)) dlsym(libc_handle(), "fstat"); + + return _fstat(fd, buf); +} + +extern "C" int freebsd11_stat(const char *path, struct freebsd11_stat *buf) { struct stat libc_buf { }; @@ -50,7 +79,7 @@ extern "C" int stat(const char *path, struct freebsd11_stat *buf) } -extern "C" int fstat(int fd, struct freebsd11_stat *buf) +extern "C" int freebsd11_fstat(int fd, struct freebsd11_stat *buf) { struct stat libc_buf { }; @@ -61,3 +90,6 @@ extern "C" int fstat(int fd, struct freebsd11_stat *buf) return 0; } + +__sym_compat(fstat, freebsd11_fstat, FBSD_1.0); +__sym_compat(stat, freebsd11_stat, FBSD_1.0); diff --git a/repos/libports/src/lib/compat-libc/libc.c b/repos/libports/src/lib/compat-libc/libc.c deleted file mode 100644 index 9c1e9256a3..0000000000 --- a/repos/libports/src/lib/compat-libc/libc.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * \brief Interface real libc - * \author Sebastian Sumpf - * \date 2023-06-12 - */ - -/* - * Copyright (C) 2023 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#include -#include - -static void* libc_handle(void) -{ - static void *handle = NULL; - if (!handle) handle = dlopen("libc.lib.so", RTLD_LAZY); - return handle; -} - - -int (*_stat)(char const*, struct stat*); -int (*_fstat)(int, struct stat *); - -int libc_stat(const char *path, struct stat *buf) -{ - if (!_stat) - _stat = dlsym(libc_handle(), "stat"); - - return _stat(path, buf); -} - - -int libc_fstat(int fd, struct stat *buf) -{ - if (!_fstat) - _fstat = dlsym(libc_handle(), "fstat"); - - return _fstat(fd, buf); -} diff --git a/repos/libports/src/lib/compat-libc/libc.h b/repos/libports/src/lib/compat-libc/libc.h deleted file mode 100644 index ebc71e0a90..0000000000 --- a/repos/libports/src/lib/compat-libc/libc.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * \brief Interface real libc - * \author Sebastian Sumpf - * \date 2023-06-12 - */ - -/* - * Copyright (C) 2023 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _COMPAT_LIBC_H_ -#define _COMPAT_LIBC_H_ - -extern "C" int libc_stat(const char *, struct stat*); -extern "C" int libc_fstat(int, struct stat *); - -#endif /* _COMPAT_LIBC_H_ */ diff --git a/repos/libports/src/lib/compat-libc/symbol.map b/repos/libports/src/lib/compat-libc/symbol.map deleted file mode 100644 index 079771d5f8..0000000000 --- a/repos/libports/src/lib/compat-libc/symbol.map +++ /dev/null @@ -1,8 +0,0 @@ -# compatible old version implemeted in this library -FBSD_1.0 { - global: - stat; - fstat; - local: - *; -};