Skip to content

Commit

Permalink
Add dynamic linking support
Browse files Browse the repository at this point in the history
JIRA: RTOS-664
  • Loading branch information
badochov committed Oct 6, 2024
1 parent 762170d commit 93851da
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 5 deletions.
1 change: 1 addition & 0 deletions _projects/armv7a7-imx6ull-evk/rootfs-overlay/etc/rc.psh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ W /sbin/dummyfs -m /var -D
W /sbin/dummyfs -m /tmp -D
X /sbin/lwip enet:0x02188000:150:PHY:0.2:irq:-5:/dev/gpio5 enet:0x020b4000:152:no-mdio:PHY:0.1:irq:-6:/dev/gpio5
X /bin/posixsrv
W /bin/ldconfig
X /bin/psh
1 change: 1 addition & 0 deletions _projects/armv7a9-zynq7000-qemu/rootfs-overlay/etc/rc.psh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ W /bin/bind devfs /dev
W /sbin/dummyfs -m /tmp -D
X /bin/posixsrv
T /dev/console
W /bin/ldconfig
X /linuxrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export HOME=/root
W /bin/bind devfs /dev
W /sbin/dummyfs -m /tmp -D
X /bin/posixsrv
W /bin/ldconfig
X /bin/psh
1 change: 1 addition & 0 deletions _projects/ia32-generic-qemu/rootfs-overlay/etc/rc.psh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ W /sbin/dummyfs -m /tmp -D
X /bin/posixsrv
X /sbin/lwip rtl:0x18:11
T /dev/console
W /bin/ldconfig
X /bin/psh
1 change: 1 addition & 0 deletions _projects/riscv64-generic-qemu/rootfs-overlay/etc/rc.psh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export HOME=/root
W /bin/bind devfs /dev
W /sbin/dummyfs -m /tmp -D
X /bin/posixsrv
W /bin/ldconfig
X /bin/psh
6 changes: 6 additions & 0 deletions _projects/sparcv8leon3-generic-qemu/rootfs-overlay/etc/rc.psh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:{}:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
export HOME=/root
W /bin/bind devfs /dev
X /bin/posixsrv
X /bin/psh
20 changes: 20 additions & 0 deletions _user/dlopen/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Makefile for user application
#
# Copyright 2024 Phoenix Systems
#
ifeq ($(HAVE_SHLIB), y)

NAME := libhello
LOCAL_HEADERS := hello.h
LOCAL_SRCS := hello.c

include $(shared-lib.mk)


NAME := dlopen
LOCAL_SRCS := main.c

include $(binary-dyn.mk)

endif
24 changes: 24 additions & 0 deletions _user/dlopen/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Phoenix-RTOS
*
* dlopen
*
* Example of user application using dlopen.
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include "hello.h"

#include <stdio.h>


int hello(void)
{
return printf("Hello shared world!\n");
}
21 changes: 21 additions & 0 deletions _user/dlopen/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Phoenix-RTOS
*
* dlopen
*
* Example of user application using dlopen.
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#ifndef _USER_DLOPEN_DYN_H_
#define _USER_DLOPEN_DYN_H_

int hello(void);

#endif
40 changes: 40 additions & 0 deletions _user/dlopen/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Phoenix-RTOS
*
* dlopen
*
* Example of user application using dlopen.
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include <stddef.h>
#include <stdio.h>
#include <dlfcn.h>
#include <sys/debug.h>

int main(void)
{
void *handle = dlopen("/usr/lib/libhello.so", RTLD_LAZY);
if (handle == NULL) {
printf("%s\n", dlerror());
return 1;
}
int (*hello)(void) = (int (*)(void))dlsym(handle, "hello");
if (hello == NULL) {
printf("%s\n", dlerror());
(void)dlclose(handle);
return 1;
}

hello();

(void)dlclose(handle);

return 0;
}
21 changes: 21 additions & 0 deletions _user/sharedlib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Makefile for user application
#
# Copyright 2024 Phoenix Systems
#
ifeq ($(HAVE_SHLIB), y)

NAME := libdyn
LOCAL_HEADERS := dyn.h
LOCAL_SRCS := dyn.c

include $(shared-lib.mk)


NAME := sharedlib
LOCAL_SRCS := main.c
DEP_LIBS_SHARED := libdyn

include $(binary-dyn.mk)

endif
25 changes: 25 additions & 0 deletions _user/sharedlib/dyn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Phoenix-RTOS
*
* sharedlib
*
* Example of user application using shared libraries.
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include "dyn.h"


extern void *_DYNAMIC;


void *dyn(void)
{
return &_DYNAMIC;
}
22 changes: 22 additions & 0 deletions _user/sharedlib/dyn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Phoenix-RTOS
*
* sharedlib
*
* Example of user application using shared libraries.
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#ifndef _USER_SHAREDLIB_DYN_H_
#define _USER_SHAREDLIB_DYN_H_

void *dyn(void);

#endif
25 changes: 25 additions & 0 deletions _user/sharedlib/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Phoenix-RTOS
*
* sharedlib
*
* Example of user application using shared libraries.
*
* Copyright 2024 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include <stdio.h>

#include "dyn.h"

int main(void)
{
printf("Dynamic section pointer %p\n", dyn());

return 0;
}
2 changes: 1 addition & 1 deletion phoenix-rtos-kernel
2 changes: 1 addition & 1 deletion phoenix-rtos-tests
Submodule phoenix-rtos-tests updated 67 files
+5 −0 Makefile
+28 −0 ld.elf_so/LICENSE.NetBSD
+173 −0 ld.elf_so/Makefile
+5 −0 ld.elf_so/README.md
+49 −0 ld.elf_so/h_df_1_noopen.c
+42 −0 ld.elf_so/h_dl_symver.c
+50 −0 ld.elf_so/h_ifunc.c
+149 −0 ld.elf_so/h_locking.c
+93 −0 ld.elf_so/h_thread_local_dtor.c
+10 −0 ld.elf_so/helper_abuse_dynamic/Makefile
+37 −0 ld.elf_so/helper_abuse_dynamic/h_abuse_dynamic.c
+10 −0 ld.elf_so/helper_abuse_static/Makefile
+37 −0 ld.elf_so/helper_abuse_static/h_abuse_static.c
+6 −0 ld.elf_so/helper_def_dynamic/Makefile
+37 −0 ld.elf_so/helper_def_dynamic/h_def_dynamic.c
+6 −0 ld.elf_so/helper_def_static/Makefile
+37 −0 ld.elf_so/helper_def_static/h_def_static.c
+6 −0 ld.elf_so/helper_dso1/Makefile
+66 −0 ld.elf_so/helper_dso1/h_helper_dso1.c
+10 −0 ld.elf_so/helper_dso2/Makefile
+57 −0 ld.elf_so/helper_dso2/h_helper_dso2.c
+11 −0 ld.elf_so/helper_dso3/Makefile
+46 −0 ld.elf_so/helper_dso3/h_helper_dso3.cpp
+6 −0 ld.elf_so/helper_ifunc_dso/Makefile
+84 −0 ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c
+10 −0 ld.elf_so/helper_onlyctor_dynamic/Makefile
+36 −0 ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c
+6 −0 ld.elf_so/helper_onlydef/Makefile
+29 −0 ld.elf_so/helper_onlydef/h_onlydef.c
+6 −0 ld.elf_so/helper_onlydef_static/Makefile
+29 −0 ld.elf_so/helper_onlydef_static/h_onlydef_static.c
+10 −0 ld.elf_so/helper_onlyuse_dynamic/Makefile
+37 −0 ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c
+10 −0 ld.elf_so/helper_onlyuse_static/Makefile
+37 −0 ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c
+27 −0 ld.elf_so/helper_symver_dso0/Makefile
+39 −0 ld.elf_so/helper_symver_dso0/h_helper_symver_dso0.c
+28 −0 ld.elf_so/helper_symver_dso1/Makefile
+41 −0 ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.c
+5 −0 ld.elf_so/helper_symver_dso1/h_helper_symver_dso1.map
+28 −0 ld.elf_so/helper_symver_dso2/Makefile
+59 −0 ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.c
+13 −0 ld.elf_so/helper_symver_dso2/h_helper_symver_dso2.map
+10 −0 ld.elf_so/helper_use_dynamic/Makefile
+37 −0 ld.elf_so/helper_use_dynamic/h_use_dynamic.c
+10 −0 ld.elf_so/helper_use_static/Makefile
+37 −0 ld.elf_so/helper_use_static/h_use_static.c
+29 −0 ld.elf_so/helpers.h
+6 −0 ld.elf_so/libexecassert/Makefile
+124 −0 ld.elf_so/libexecassert/execassert.c
+24 −0 ld.elf_so/libexecassert/execassert.h
+96 −0 ld.elf_so/t_df_1_noopen.c
+139 −0 ld.elf_so/t_dl_symver.c
+92 −0 ld.elf_so/t_dlerror-cleared.c
+106 −0 ld.elf_so/t_dlerror-false.c
+144 −0 ld.elf_so/t_dlinfo.c
+220 −0 ld.elf_so/t_dlvsym.c
+237 −0 ld.elf_so/t_hash.c
+234 −0 ld.elf_so/t_ifunc.c
+199 −0 ld.elf_so/t_rtld_r_debug.c
+88 −0 ld.elf_so/t_thread_local_dtor.c
+138 −0 ld.elf_so/t_tls_extern-nightly.c
+380 −0 ld.elf_so/t_tls_extern.c
+51 −0 ld.elf_so/test.yaml
+2 −2 proc/test_priority.c
+1 −1 thread-local/tls.c
+2 −0 thread-local/tls_functions.c
2 changes: 1 addition & 1 deletion phoenix-rtos-utils

0 comments on commit 93851da

Please sign in to comment.