-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
AUX more.patch 5751 BLAKE2B 8da5909d8b858e09d3c8b72239ff425ac541b037ad7d4cbfcf367d9070d3ccc52d1e6265aae275160e7ccbb2324265e1065ac7ea869097facf4e18c8b2940881 SHA512 33decc67b3fef3ba81dc5f1883e36ebdff86bdd3b47a9449049f383badf97b9f1c2b4517d14aee9de7b6c48265b5407c4c9439243205e0ea1ba70734e402e1e3 | ||
DIST gcompat-1.0.0.tar.xz 25912 BLAKE2B 96710c8c6dacb758327e399d6cc3adc9b412024560b354c5ac41e1f36b0f5b5697d74ff123954786134225516ea16f54109e577ebb75fe1ed315e3dbc3ee090e SHA512 61e355445571760b7cb8c8a828e7182544fefb403dca602f0b3756f39430974b5161517b0fdf4636a8a513be8e64d4dcb13553b28e9c7833f15c3b9871c94455 | ||
EBUILD gcompat-1.0.0.ebuild 1876 BLAKE2B c05cc8e195f34c83d6397c436bfe62a0a6167c31fe1e9dd75ffbc90e71a35f23de32bced549425b58d724d7374bbec11cccbe6849e05816d4d4ae28716b47b79 SHA512 7c3ee92ddbaca58a0771824bee83c5910b046eca532a992f417149da7912f7119d4f7b8f59fd50fc397540706c4a66ea9c2ef5ae2638b09e56ee8c99ebaf6827 | ||
MISC metadata.xml 520 BLAKE2B 2edaaffa4eff0a6817edb0ab9156adf992cf4db7113b27d6629ccd67f5a7268e33a6bd62de1f28f384e5ed7ae0f0fceb735b1d57bb310ae46a06d3076b565e79 SHA512 ed564c080d5a39757c2a60201dab0b7f26ac96241ecfc0defccd7aff8141e7cb2c1ea6a310e4c95160445da8ea0cac2580728506f8004a1136b91c92a177346f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
diff --git a/Makefile b/Makefile | ||
index e421055..184b828 100644 | ||
--- a/Makefile | ||
+++ b/Makefile | ||
@@ -7,6 +7,7 @@ LIBGCOMPAT_SRC = \ | ||
libgcompat/dlfcn.c \ | ||
libgcompat/error.c \ | ||
libgcompat/execinfo.c \ | ||
+ libgcompat/fcntl.c \ | ||
libgcompat/gnulib.c \ | ||
libgcompat/grp.c \ | ||
libgcompat/internal.c \ | ||
@@ -21,6 +22,7 @@ LIBGCOMPAT_SRC = \ | ||
libgcompat/realpath.c \ | ||
libgcompat/resolv.c \ | ||
libgcompat/resource.c \ | ||
+ libgcompat/scandirat.c \ | ||
libgcompat/setjmp.c \ | ||
libgcompat/signal.c \ | ||
libgcompat/socket.c \ | ||
@@ -60,17 +62,29 @@ WITH_OBSTACK = $(shell \ | ||
done; echo "no") | ||
endif | ||
|
||
+ifndef WITH_FTS | ||
+WITH_OBSTACK = $(shell \ | ||
+ for pkg in musl-fts fts-standalone; do \ | ||
+ ${PKG_CONFIG} --exists "$$pkg" && { echo "$$pkg"; exit 0; } \ | ||
+ done; echo "no") | ||
+endif | ||
+ | ||
ifneq (${WITH_OBSTACK},no) | ||
OBSTACK_CFLAGS = $(shell ${PKG_CONFIG} --cflags ${WITH_OBSTACK}) -DWITH_OBSTACK | ||
OBSTACK_LIBS = $(shell ${PKG_CONFIG} --libs ${WITH_OBSTACK}) | ||
endif | ||
|
||
+ifneq (${WITH_FTS},no) | ||
+FTS_CFLAGS = $(shell ${PKG_CONFIG} --cflags ${WITH_FTS}) | ||
+FTS_LIBS = $(shell ${PKG_CONFIG} --libs ${WITH_FTS}) | ||
+endif | ||
+ | ||
all: ${LIBGCOMPAT_NAME} ${LOADER_NAME} | ||
|
||
${LIBGCOMPAT_NAME}: ${LIBGCOMPAT_OBJ} | ||
${CC} ${CFLAGS} ${LDFLAGS} -shared -Wl,-soname,${LIBGCOMPAT_NAME} \ | ||
-o ${LIBGCOMPAT_NAME} ${LIBGCOMPAT_OBJ} \ | ||
- -Wl,--no-as-needed ${LIBUCONTEXT_LIBS} ${OBSTACK_LIBS} | ||
+ -Wl,--no-as-needed ${LIBUCONTEXT_LIBS} ${OBSTACK_LIBS} ${FTS_LIBS} | ||
|
||
${LIBGCOMPAT_OBJ}: ${LIBGCOMPAT_INCLUDE} | ||
|
||
@@ -83,7 +97,7 @@ ${LOADER_NAME}: ${LOADER_OBJ} | ||
-DLINKER='"${LINKER_PATH}"' -DLOADER='"${LOADER_NAME}"' \ | ||
-fPIC -Ilibgcompat -std=c99 \ | ||
-Wall -Wextra -Wno-frame-address -Wno-unused-parameter \ | ||
- ${LIBUCONTEXT_CFLAGS} ${OBSTACK_CFLAGS} -o $@ $< | ||
+ ${LIBUCONTEXT_CFLAGS} ${OBSTACK_CFLAGS} ${FTS_CFLAGS} -o $@ $< | ||
|
||
clean: | ||
rm -f libgcompat/*.o loader/*.o ${LIBGCOMPAT_NAME} ${LOADER_NAME} | ||
diff --git a/libgcompat/fcntl.c b/libgcompat/fcntl.c | ||
new file mode 100644 | ||
index 0000000..6cd3894 | ||
--- /dev/null | ||
+++ b/libgcompat/fcntl.c | ||
@@ -0,0 +1,35 @@ | ||
+#include <fcntl.h> /* fcntl, openat */ | ||
+#include <stdarg.h> /* va_list, va_start, va_end */ | ||
+#include <linux/stat.h> /* statx */ | ||
+#include <unistd.h> /* syscall */ | ||
+#include <sys/syscall.h> /* SYS_statx */ | ||
+ | ||
+int fcntl64(int fd, int cmd, ...) | ||
+{ | ||
+ int ret; | ||
+ va_list ap; | ||
+ | ||
+ va_start(ap, cmd); | ||
+ ret = fcntl(fd,cmd,ap); | ||
+ va_end(ap); | ||
+ | ||
+ return ret; | ||
+} | ||
+ | ||
+int __openat_2(int fd, const char *filename, int flags, ...) | ||
+{ | ||
+ int ret; | ||
+ va_list ap; | ||
+ | ||
+ va_start(ap, flags); | ||
+ ret = openat(fd, filename, flags, ap); | ||
+ va_end(ap); | ||
+ | ||
+ return ret; | ||
+} | ||
+ | ||
+int statx(int dirfd, const char *pathname, int flags, | ||
+ unsigned int mask, struct statx *statxbuf) | ||
+{ | ||
+ return syscall(SYS_statx, dirfd, pathname, flags, mask, statxbuf); | ||
+} | ||
diff --git a/libgcompat/misc.c b/libgcompat/misc.c | ||
index 0677550..684b400 100644 | ||
--- a/libgcompat/misc.c | ||
+++ b/libgcompat/misc.c | ||
@@ -1,6 +1,7 @@ | ||
#include <stdlib.h> /* abort, at_quick_exit */ | ||
#include <sys/stat.h> /* dev_t */ | ||
#include <sys/sysmacros.h> /* major, makedev, minor */ | ||
+#include <string.h> /* memset */ | ||
|
||
/** | ||
* Terminate a function in case of buffer overflow. | ||
@@ -33,3 +34,12 @@ unsigned int gnu_dev_minor(dev_t dev) | ||
} | ||
|
||
void *__libc_stack_end = NULL; | ||
+ | ||
+void __explicit_bzero_chk(void *dst, size_t len, size_t dstlen) | ||
+{ | ||
+ if (dstlen < len){ | ||
+ __chk_fail(); | ||
+ } | ||
+ memset(dst, 0, len); | ||
+ __asm__ __volatile__ ("" ::: "memory"); | ||
+} | ||
diff --git a/libgcompat/scandirat.c b/libgcompat/scandirat.c | ||
new file mode 100644 | ||
index 0000000..70b0061 | ||
--- /dev/null | ||
+++ b/libgcompat/scandirat.c | ||
@@ -0,0 +1,48 @@ | ||
+#include <dirent.h> | ||
+#include <string.h> | ||
+#include <stdlib.h> | ||
+#include <stdint.h> | ||
+#include <errno.h> | ||
+#include <stddef.h> | ||
+#include <fcntl.h> | ||
+ | ||
+#define FLAGS O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_LARGEFILE|O_NDELAY | ||
+ | ||
+int scandirat(int dirfd, const char *path, struct dirent ***res, | ||
+ int (*sel)(const struct dirent *), | ||
+ int (*cmp)(const struct dirent **, const struct dirent **)) | ||
+{ | ||
+ int fd = openat(dirfd, path, FLAGS); | ||
+ DIR *d = fdopendir(fd); | ||
+ struct dirent *de, **names=0, **tmp; | ||
+ size_t cnt=0, len=0; | ||
+ int old_errno = errno; | ||
+ | ||
+ if (!d) return -1; | ||
+ | ||
+ while ((errno=0), (de = readdir(d))) { | ||
+ if (sel && !sel(de)) continue; | ||
+ if (cnt >= len) { | ||
+ len = 2*len+1; | ||
+ if (len > SIZE_MAX/sizeof *names) break; | ||
+ tmp = realloc(names, len * sizeof *names); | ||
+ if (!tmp) break; | ||
+ names = tmp; | ||
+ } | ||
+ names[cnt] = malloc(de->d_reclen); | ||
+ if (!names[cnt]) break; | ||
+ memcpy(names[cnt++], de, de->d_reclen); | ||
+ } | ||
+ closedir(d); | ||
+ | ||
+ if (errno) { | ||
+ if (names) while (cnt-->0) free(names[cnt]); | ||
+ free(names); | ||
+ return -1; | ||
+ } | ||
+ errno = old_errno; | ||
+ | ||
+ if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp); | ||
+ *res = names; | ||
+ return cnt; | ||
+} | ||
diff --git a/libgcompat/unistd.c b/libgcompat/unistd.c | ||
index e40fb6e..964c92b 100644 | ||
--- a/libgcompat/unistd.c | ||
+++ b/libgcompat/unistd.c | ||
@@ -7,6 +7,7 @@ | ||
#include <stdlib.h> /* calloc */ | ||
#include <dlfcn.h> /* dlsym */ | ||
#include <string.h> /* strcmp */ | ||
+#include <sys/syscall.h> /* SYS_xxx */ | ||
|
||
#include "alias.h" /* alias */ | ||
|
||
@@ -234,3 +235,7 @@ int execv(const char *pathname, char *const argv[]) { | ||
int execvp(const char *file, char *const argv[]) { | ||
return execv(file, argv); | ||
} | ||
+ | ||
+int renameat2(int oldfd, const char *old, int newfd, const char *new, unsigned int flags){ | ||
+ return syscall(SYS_renameat2, oldfd, old, newfd, new, flags); | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2018-2020 Haelwenn (lanodan) Monnier <[email protected]> | ||
# Distributed under the terms of the GNU General Public License v2 | ||
|
||
EAPI=7 | ||
|
||
inherit multilib-minimal flag-o-matic | ||
|
||
DESCRIPTION="The GNU C Library compatibility layer for musl" | ||
HOMEPAGE="https://code.foxkit.us/adelie/gcompat" | ||
KEYWORDS="~amd64 ~x86 ~arm64" | ||
LICENSE="UoI-NCSA" | ||
IUSE="+libucontext +obstack +fts" | ||
SRC_URI="https://distfiles.adelielinux.org/source/${PN}/${P}.tar.xz" | ||
SLOT="0" | ||
|
||
DEPEND=" | ||
libucontext? ( sys-libs/libucontext ) | ||
obstack? ( sys-libs/obstack-standalone ) | ||
fts? ( sys-libs/fts-standalone ) | ||
" | ||
RDEPEND="${DEPEND}" | ||
|
||
PATCHES=( "${FILESDIR}/more.patch" ) | ||
|
||
get_loader_name() { | ||
# Loosely based on Adélie APKBUILD | ||
# TODO: Check against glibc’s logic | ||
|
||
case "$ABI" in | ||
x86) echo "ld-linux.so.2" ;; | ||
amd64) echo "ld-linux-x86-64.so.2" ;; | ||
arm*) echo "ld-linux-armhf.so.3" ;; | ||
arm64) echo "ld-linux-aarch64.so.1" ;; | ||
mips | powerpc | s390) echo "ld.so.1" ;; | ||
esac | ||
} | ||
|
||
get_glibc_libdir() { | ||
case "$ABI" in | ||
amd64 | arm64) echo "lib64";; | ||
*) echo "lib";; | ||
esac | ||
} | ||
|
||
get_linker_path() { | ||
local arch=$(ldd 2>&1 | sed -n '1s/^musl libc (\(.*\))$/\1/p') | ||
echo "/lib/ld-musl-${arch}.so.1" | ||
} | ||
|
||
src_compile() { | ||
filter-flags "-Wl,--as-needed" | ||
|
||
emake \ | ||
LINKER_PATH="$(get_linker_path)" \ | ||
LOADER_NAME="$(get_loader_name)" \ | ||
WITH_OBSTACK="$(usex obstack 'obstack-standalone' 'no')" \ | ||
WITH_FTS="$(usex fts 'fts-standalone' 'no')" \ | ||
$(usex libucontext WITH_LIBUCONTEXT=yes '') | ||
} | ||
|
||
src_install() { | ||
emake \ | ||
LINKER_PATH="$(get_linker_path)" \ | ||
LOADER_NAME="$(get_loader_name)" \ | ||
WITH_OBSTACK="$(usex obstack 'obstack-standalone' 'no')" \ | ||
WITH_FTS="$(usex fts 'fts-standalone' 'no')" \ | ||
$(usex libucontext WITH_LIBUCONTEXT=yes '') \ | ||
DESTDIR="${D}" \ | ||
install | ||
|
||
mkdir -p "${ED}/$(get_glibc_libdir)" | ||
mv "${ED}/lib/$(get_loader_name)" "${ED}/$(get_glibc_libdir)/$(get_loader_name)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> | ||
<pkgmetadata> | ||
<maintainer type="person"> | ||
<email>[email protected]</email> | ||
</maintainer> | ||
<use> | ||
<flag name="obstack">Use <pkg>sys-libs/obstack-standalone</pkg> for greater compatibility</flag> | ||
<flag name="libucontext">Use <pkg>sys-libs/libucontext</pkg> for greater compatibility</flag> | ||
<flag name="fts">Use <pkg>sys-libs/fts-standalone</pkg> for greater compatibility</flag> | ||
</use> | ||
</pkgmetadata> |