Skip to content

Commit b577676

Browse files
author
Hubert Badocha
committed
Add dynamic linking support.
JIRA: RTOS-664
1 parent 3eb2849 commit b577676

File tree

19 files changed

+214
-5
lines changed

19 files changed

+214
-5
lines changed

_projects/armv7a7-imx6ull-evk/rootfs-overlay/etc/rc.psh

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ W /sbin/dummyfs -m /var -D
77
W /sbin/dummyfs -m /tmp -D
88
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
99
X /bin/posixsrv
10+
W /bin/ldconfig
1011
X /bin/psh

_projects/armv7a9-zynq7000-qemu/rootfs-overlay/etc/rc.psh

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ W /bin/bind devfs /dev
55
W /sbin/dummyfs -m /tmp -D
66
X /bin/posixsrv
77
T /dev/console
8+
W /bin/ldconfig
89
X /linuxrc

_projects/armv7a9-zynq7000-zedboard/rootfs-overlay/etc/rc.psh

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export HOME=/root
44
W /bin/bind devfs /dev
55
W /sbin/dummyfs -m /tmp -D
66
X /bin/posixsrv
7+
W /bin/ldconfig
78
X /bin/psh

_projects/ia32-generic-qemu/rootfs-overlay/etc/rc.psh

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ W /sbin/dummyfs -m /tmp -D
66
X /bin/posixsrv
77
X /sbin/lwip rtl:0x18:11
88
T /dev/console
9+
W /bin/ldconfig
910
X /bin/psh

_projects/riscv64-generic-qemu/rootfs-overlay/etc/rc.psh

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export HOME=/root
44
W /bin/bind devfs /dev
55
W /sbin/dummyfs -m /tmp -D
66
X /bin/posixsrv
7+
W /bin/ldconfig
78
X /bin/psh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:{}:
2+
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
3+
export HOME=/root
4+
W /bin/bind devfs /dev
5+
X /bin/posixsrv
6+
X /bin/psh

_user/dlopen/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Makefile for user application
3+
#
4+
# Copyright 2024 Phoenix Systems
5+
#
6+
ifeq ($(HAVE_SHLIB), y)
7+
8+
NAME := libhello
9+
LOCAL_HEADERS := hello.h
10+
LOCAL_SRCS := hello.c
11+
12+
include $(shared-lib.mk)
13+
14+
15+
NAME := dlopen
16+
LOCAL_SRCS := main.c
17+
18+
include $(binary-dyn.mk)
19+
20+
endif

_user/dlopen/hello.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Phoenix-RTOS
3+
*
4+
* dlopen
5+
*
6+
* Example of user application using dlopen.
7+
*
8+
* Copyright 2024 Phoenix Systems
9+
* Author: Hubert Badocha
10+
*
11+
* This file is part of Phoenix-RTOS.
12+
*
13+
* %LICENSE%
14+
*/
15+
16+
#include "hello.h"
17+
18+
#include <stdio.h>
19+
20+
21+
int hello(void)
22+
{
23+
return printf("Hello shared world!\n");
24+
}

_user/dlopen/hello.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Phoenix-RTOS
3+
*
4+
* dlopen
5+
*
6+
* Example of user application using dlopen.
7+
*
8+
* Copyright 2024 Phoenix Systems
9+
* Author: Hubert Badocha
10+
*
11+
* This file is part of Phoenix-RTOS.
12+
*
13+
* %LICENSE%
14+
*/
15+
16+
#ifndef _USER_DLOPEN_DYN_H_
17+
#define _USER_DLOPEN_DYN_H_
18+
19+
int hello(void);
20+
21+
#endif

_user/dlopen/main.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Phoenix-RTOS
3+
*
4+
* dlopen
5+
*
6+
* Example of user application using dlopen.
7+
*
8+
* Copyright 2024 Phoenix Systems
9+
* Author: Hubert Badocha
10+
*
11+
* This file is part of Phoenix-RTOS.
12+
*
13+
* %LICENSE%
14+
*/
15+
16+
#include <stddef.h>
17+
#include <stdio.h>
18+
#include <dlfcn.h>
19+
#include <sys/debug.h>
20+
21+
int main(void)
22+
{
23+
void *handle = dlopen("/usr/lib/libhello.so", RTLD_LAZY);
24+
if (handle == NULL) {
25+
printf("%s\n", dlerror());
26+
return 1;
27+
}
28+
int (*hello)(void) = (int (*)(void))dlsym(handle, "hello");
29+
if (hello == NULL) {
30+
printf("%s\n", dlerror());
31+
(void)dlclose(handle);
32+
return 1;
33+
}
34+
35+
hello();
36+
37+
(void)dlclose(handle);
38+
39+
return 0;
40+
}

_user/sharedlib/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Makefile for user application
3+
#
4+
# Copyright 2024 Phoenix Systems
5+
#
6+
ifeq ($(HAVE_SHLIB), y)
7+
8+
NAME := libdyn
9+
LOCAL_HEADERS := dyn.h
10+
LOCAL_SRCS := dyn.c
11+
12+
include $(shared-lib.mk)
13+
14+
15+
NAME := sharedlib
16+
LOCAL_SRCS := main.c
17+
DEP_LIBS_SHARED := libdyn
18+
19+
include $(binary-dyn.mk)
20+
21+
endif

_user/sharedlib/dyn.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Phoenix-RTOS
3+
*
4+
* sharedlib
5+
*
6+
* Example of user application using shared libraries.
7+
*
8+
* Copyright 2024 Phoenix Systems
9+
* Author: Hubert Badocha
10+
*
11+
* This file is part of Phoenix-RTOS.
12+
*
13+
* %LICENSE%
14+
*/
15+
16+
#include "dyn.h"
17+
18+
19+
extern void *_DYNAMIC;
20+
21+
22+
void *dyn(void)
23+
{
24+
return &_DYNAMIC;
25+
}

_user/sharedlib/dyn.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Phoenix-RTOS
3+
*
4+
* sharedlib
5+
*
6+
* Example of user application using shared libraries.
7+
*
8+
* Copyright 2024 Phoenix Systems
9+
* Author: Hubert Badocha
10+
*
11+
* This file is part of Phoenix-RTOS.
12+
*
13+
* %LICENSE%
14+
*/
15+
16+
17+
#ifndef _USER_SHAREDLIB_DYN_H_
18+
#define _USER_SHAREDLIB_DYN_H_
19+
20+
void *dyn(void);
21+
22+
#endif

_user/sharedlib/main.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Phoenix-RTOS
3+
*
4+
* sharedlib
5+
*
6+
* Example of user application using shared libraries.
7+
*
8+
* Copyright 2024 Phoenix Systems
9+
* Author: Hubert Badocha
10+
*
11+
* This file is part of Phoenix-RTOS.
12+
*
13+
* %LICENSE%
14+
*/
15+
16+
#include <stdio.h>
17+
18+
#include "dyn.h"
19+
20+
int main(void)
21+
{
22+
printf("Dynamic section pointer %p\n", dyn());
23+
24+
return 0;
25+
}

phoenix-rtos-tests

Submodule phoenix-rtos-tests updated 69 files

phoenix-rtos-utils

Submodule phoenix-rtos-utils updated 101 files

0 commit comments

Comments
 (0)