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 
This commit is contained in:
Benjamin Lamowski 2023-08-16 17:11:29 +02:00 committed by Christian Helmuth
parent 0a85964f91
commit 9f7e47368f
12 changed files with 37 additions and 103 deletions
repos/libports
lib
recipes
api/compat-libc
src/compat-libc
src/lib/compat-libc

@ -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 =

@ -1,2 +0,0 @@
fstat T
stat T

@ -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 $@

@ -1 +1 @@
2023-06-12 1ce2539b566b8d0d1a1f9919b8c7543f32467679
2023-08-16 e490a07341485a2514c6f57bbc0d83bd63d7d9a1

@ -1 +0,0 @@
compat-libc

@ -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 $@

@ -1 +0,0 @@
2023-06-12-a b499380d630694fbe520d666320b5bba333fce25

@ -15,8 +15,10 @@
#define _WANT_FREEBSD11_STAT /* enable freebsd11_stat */
#define _KERNEL /* disable 'stat' */
#include <sys/stat.h>
#include "libc.h"
#include <dlfcn.h>
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);

@ -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 <sys/stat.h>
#include <dlfcn.h>
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);
}

@ -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_ */

@ -1,8 +0,0 @@
# compatible old version implemeted in this library
FBSD_1.0 {
global:
stat;
fstat;
local:
*;
};