From 4c7ff1fda1a64bf0687816f1442209080a0d28c5 Mon Sep 17 00:00:00 2001 From: Hubert Badocha Date: Sat, 24 Aug 2024 00:57:05 +0200 Subject: [PATCH] ld.elf_so: Add stub library to access non-POSIX rtld api JIRA: RTOS-664 --- ld.elf_so/Makefile | 5 +++ ld.elf_so/stubs/Makefile | 12 +++++++ ld.elf_so/stubs/librtld_stubs.c | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 ld.elf_so/stubs/Makefile create mode 100644 ld.elf_so/stubs/librtld_stubs.c diff --git a/ld.elf_so/Makefile b/ld.elf_so/Makefile index 22bd22f4..059700de 100644 --- a/ld.elf_so/Makefile +++ b/ld.elf_so/Makefile @@ -54,3 +54,8 @@ LANGUAGE_EXTENSIONS += %.S include $(binary.mk) LANGUAGE_EXTENSIONS := $(LANGUAGE_EXTENSIONS_OLD) + + +rtld: ld.elf_so librtld_stubs +rtld-install: ld.elf_so-install librtld_stubs-install +rtld-clean: ld.elf_so-clean librtld_stubs-clean \ No newline at end of file diff --git a/ld.elf_so/stubs/Makefile b/ld.elf_so/stubs/Makefile new file mode 100644 index 00000000..2afd3278 --- /dev/null +++ b/ld.elf_so/stubs/Makefile @@ -0,0 +1,12 @@ +# +# Makefile for Phoenix-RTOS librtld_stubs +# +# Copyright 2024 Phoenix Systems +# + +# Make library with stubs of non POSIX functions. +# This is required as this linker doesn't allow to add itself to NEEDED libs. +# To resolve a symbol from linker in dynamic binary a weak symbol is required. +NAME := librtld_stubs +LOCAL_SRCS := librtld_stubs.c +include $(shared-lib.mk) diff --git a/ld.elf_so/stubs/librtld_stubs.c b/ld.elf_so/stubs/librtld_stubs.c new file mode 100644 index 00000000..8c533d15 --- /dev/null +++ b/ld.elf_so/stubs/librtld_stubs.c @@ -0,0 +1,62 @@ +/* + * Phoenix-RTOS + * + * librtld_stubs + * + * Copyright 2024 Phoenix Systems + * Author: Hubert Badocha + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include + +#include "../include/NetBSD/dlfcn.h" +#include "../include/NetBSD/link_elf.h" + + +void *___dlauxinfo(void) +{ + abort(); +} + + +int __dlctl(void *a, int b, void *c) +{ + abort(); +} + + +int __dlinfo(void *a, int b, void *c) +{ + abort(); +} + + +void *__dlvsym(void * restrict a, const char * restrict b, const char * restrict c) +{ + abort(); +} + + +void ____dl_cxa_refcount(void *a, ssize_t b) +{ + abort(); +} + + +int __dl_iterate_phdr(int (*a)(struct dl_phdr_info *, size_t, void *), void *b) +{ + abort(); +} + + +extern void *_dlauxinfo(void) __attribute__((__pure__, weak, alias("___dlauxinfo"))); + +extern int dlctl(void *, int, void *) __attribute__((weak, alias("__dlctl"))); +extern int dlinfo(void *, int, void *) __attribute__((weak, alias("__dlinfo"))); +extern void *dlvsym(void * restrict, const char * restrict, const char * restrict) __attribute__((weak, alias("__dlvsym"))); +extern void __dl_cxa_refcount(void *, ssize_t) __attribute__((weak, alias("____dl_cxa_refcount"))); +extern int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *) __attribute__((weak, alias("__dl_iterate_phdr")));