xref: /titanic_44/usr/src/lib/libdll/common/features/dll (revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5)
1da2e3ebdSchinset	prototyped
2da2e3ebdSchinhdr	dl,dlfcn,dll,rld_interface,mach-o/dyld
3da2e3ebdSchinsys	ldr
4da2e3ebdSchinlib	dlopen -ldl
5da2e3ebdSchinlib	dllload,loadbind,shl_load -ldl
6da2e3ebdSchintst	dll_DYNAMIC link{
7da2e3ebdSchin	#include <sys/types.h>
8da2e3ebdSchin	#include <link.h>
9da2e3ebdSchin	extern struct link_dynamic _DYNAMIC;
10da2e3ebdSchin	int
11da2e3ebdSchin	main()
12da2e3ebdSchin	{
13da2e3ebdSchin		return _DYNAMIC.ld_version;
14da2e3ebdSchin	}
15da2e3ebdSchin}end
16da2e3ebdSchintst	run{
17da2e3ebdSchin	lib=
18da2e3ebdSchin	for d in  /shlib /usr/shlib /lib /usr/lib
19da2e3ebdSchin	do	if	test -d $d
20da2e3ebdSchin		then	for s in "*.*" "*[!a]*"
21da2e3ebdSchin			do	for b in libc
22da2e3ebdSchin				do	for i in $d/$b.$s
23da2e3ebdSchin					do	if	test -f $i
24da2e3ebdSchin						then	lib=$i
25da2e3ebdSchin						fi
26da2e3ebdSchin					done
27da2e3ebdSchin					case $lib in
28da2e3ebdSchin					?*)	break 3 ;;
29da2e3ebdSchin					esac
30da2e3ebdSchin				done
31da2e3ebdSchin			done
32da2e3ebdSchin		fi
33da2e3ebdSchin	done
34da2e3ebdSchin	case $lib in
35da2e3ebdSchin	*.[0-9]*.[0-9]*)
36da2e3ebdSchin		i=`echo $lib | sed 's,\([^0-9]*[0-9]*\).*,\1,'`
37da2e3ebdSchin		if	test -f $i
38da2e3ebdSchin		then	lib=$i
39da2e3ebdSchin		fi
40da2e3ebdSchin		;;
41da2e3ebdSchin	esac
42da2e3ebdSchin	# some run time linkers barf with /lib/xxx if
43da2e3ebdSchin	# /usr/lib/xxx is there
44da2e3ebdSchin	case $lib in
45da2e3ebdSchin	/usr*)	;;
46da2e3ebdSchin	*)	if	test -f /usr$lib
47da2e3ebdSchin		then	lib=/usr$lib
48da2e3ebdSchin		fi
49da2e3ebdSchin		;;
50da2e3ebdSchin	esac
51da2e3ebdSchin	case $lib in
52da2e3ebdSchin	"")	lib=/lib/libc.so.1 ;;
53da2e3ebdSchin	esac
54da2e3ebdSchin	case $lib in
55da2e3ebdSchin	/usr/lib/*)
56da2e3ebdSchin		case `package` in
57da2e3ebdSchin		sgi.mips3)
58da2e3ebdSchin			abi=/lib32
59da2e3ebdSchin			;;
60da2e3ebdSchin		sgi.mips4)
61da2e3ebdSchin			abi=/lib64
62da2e3ebdSchin			;;
63da2e3ebdSchin		*)	abi=
64da2e3ebdSchin			;;
65da2e3ebdSchin		esac
66da2e3ebdSchin		case $abi in
67da2e3ebdSchin		?*)	if	test -d $abi
68da2e3ebdSchin			then	lib=`echo $lib | sed 's,/usr/lib/,,'`
69da2e3ebdSchin				lib=$abi/$lib
70da2e3ebdSchin			fi
71da2e3ebdSchin			;;
72da2e3ebdSchin		esac
73da2e3ebdSchin		;;
74da2e3ebdSchin	esac
75da2e3ebdSchin	echo "#define _DLL_NEXT_PATH	\"$lib\""
76da2e3ebdSchin}end
77da2e3ebdSchintst	- output{
78*34f9b3eeSRoland Mainz	#if defined(__MVS__) && !defined(__SUSV3)
79*34f9b3eeSRoland Mainz	#define __SUSV3		1
80*34f9b3eeSRoland Mainz	#endif
81da2e3ebdSchin	#if _hdr_dlfcn && _lib_dlopen
82da2e3ebdSchin	#include <dlfcn.h>
83da2e3ebdSchin	#endif
84da2e3ebdSchin	#if _hdr_rld_interface
85da2e3ebdSchin	#include <rld_interface.h>
86da2e3ebdSchin	#endif
87da2e3ebdSchin	int
88da2e3ebdSchin	main()
89da2e3ebdSchin	{
90da2e3ebdSchin		int		i;
91da2e3ebdSchin	#if _hdr_rld_interface
92da2e3ebdSchin		void*		dll;
93da2e3ebdSchin		static char*	local[] = { "__elf_header", "_call_add_gp_range", "_etext" };
94da2e3ebdSchin	#endif
95da2e3ebdSchin		printf("\n");
96*34f9b3eeSRoland Mainz		printf("#if defined(__MVS__) && !defined(__SUSV3)\n");
97*34f9b3eeSRoland Mainz		printf("#define __SUSV3		1\n");
98*34f9b3eeSRoland Mainz		printf("#endif\n");
99da2e3ebdSchin	#if _hdr_dlfcn && _lib_dlopen
100da2e3ebdSchin		printf("#include <dlfcn.h>\n");
101da2e3ebdSchin	#endif
102da2e3ebdSchin	#ifndef RTLD_LAZY
103da2e3ebdSchin		i = 0;
104da2e3ebdSchin		printf("\n");
105da2e3ebdSchin		printf("#define RTLD_LAZY	1\n");
106da2e3ebdSchin	#else
107da2e3ebdSchin		i = 1;
108da2e3ebdSchin	#endif
109da2e3ebdSchin	#ifndef RTLD_NOW
110da2e3ebdSchin		if (i)
111da2e3ebdSchin		{
112da2e3ebdSchin			i = 0;
113da2e3ebdSchin			printf("\n");
114da2e3ebdSchin		}
115da2e3ebdSchin		printf("#define RTLD_NOW	2\n");
116da2e3ebdSchin	#endif
117da2e3ebdSchin	#ifndef RTLD_GLOBAL
118da2e3ebdSchin		if (i)
119da2e3ebdSchin		{
120da2e3ebdSchin			i = 0;
121da2e3ebdSchin			printf("\n");
122da2e3ebdSchin		}
123da2e3ebdSchin		printf("#define RTLD_GLOBAL	0\n");
124da2e3ebdSchin	#endif
125da2e3ebdSchin	#ifndef RTLD_LOCAL
126da2e3ebdSchin		if (i)
127da2e3ebdSchin		{
128da2e3ebdSchin			i = 0;
129da2e3ebdSchin			printf("\n");
130da2e3ebdSchin		}
131da2e3ebdSchin		printf("#define RTLD_LOCAL	0\n");
132da2e3ebdSchin	#endif
133da2e3ebdSchin	#ifndef RTLD_PARENT
134da2e3ebdSchin		if (i)
135da2e3ebdSchin		{
136da2e3ebdSchin			i = 0;
137da2e3ebdSchin			printf("\n");
138da2e3ebdSchin		}
139da2e3ebdSchin		printf("#define RTLD_PARENT	0\n");
140da2e3ebdSchin	#endif
141da2e3ebdSchin	#if defined(_hdr_mach_o_dyld) && !defined(RTLD_NEXT)
142da2e3ebdSchin		if (i)
143da2e3ebdSchin		{
144da2e3ebdSchin			i = 0;
145da2e3ebdSchin			printf("\n");
146da2e3ebdSchin		}
147da2e3ebdSchin		printf("#define RTLD_NEXT	((void*)16)\n");
148da2e3ebdSchin	#endif
149da2e3ebdSchin	#if _hdr_rld_interface
150da2e3ebdSchin		if (!(dll = dlopen(0, RTLD_LAZY)))
151da2e3ebdSchin			i = -1;
152da2e3ebdSchin		else
153da2e3ebdSchin		{
154da2e3ebdSchin			for (i = 0; i < sizeof(local) / sizeof(local[0]); i++)
155da2e3ebdSchin				if (dlsym(dll, local[i]))
156da2e3ebdSchin					break;
157da2e3ebdSchin			if (i >= sizeof(local) / sizeof(local[0]))
158da2e3ebdSchin				i = -1;
159da2e3ebdSchin		}
160da2e3ebdSchin		if (i >= 0)
161da2e3ebdSchin		{
162da2e3ebdSchin			printf("\n");
163da2e3ebdSchin			printf("#define _DLL_RLD_SYM		%s\n", local[i]);
164da2e3ebdSchin			printf("#define _DLL_RLD_SYM_STR	\"%s\"\n", local[i]);
165da2e3ebdSchin			printf("#define _DLL_RLD_SYM_TYPE	void*\n");
166da2e3ebdSchin		}
167da2e3ebdSchin	#endif
168da2e3ebdSchin		printf("\n");
169da2e3ebdSchin		printf("#define DLL_INFO_PREVER	0x0001	/* pre-suffix style version */\n");
170da2e3ebdSchin		printf("#define DLL_INFO_DOTVER	0x0002	/* post-suffix style version */\n");
171da2e3ebdSchin		printf("\n");
172da2e3ebdSchin		printf("typedef struct Dllinfo_s\n");
173da2e3ebdSchin		printf("{\n");
174da2e3ebdSchin		printf("	char**	sibling;	/* sibling dirs on $PATH */\n");
175da2e3ebdSchin		printf("	char*	prefix;		/* library name prefix */\n");
176da2e3ebdSchin		printf("	char*	suffix;		/* library name suffix */\n");
177da2e3ebdSchin		printf("	char*	env;		/* library path env var */\n");
178da2e3ebdSchin		printf("	int	flags;		/* DLL_INFO_* flags */\n");
179da2e3ebdSchin		printf("#ifdef _DLLINFO_PRIVATE_\n");
180da2e3ebdSchin		printf("	_DLLINFO_PRIVATE_\n");
181da2e3ebdSchin		printf("#endif\n");
182da2e3ebdSchin		printf("} Dllinfo_t;\n");
183da2e3ebdSchin		printf("\n");
184da2e3ebdSchin		printf("typedef struct Dllent_s\n");
185da2e3ebdSchin		printf("{\n");
186da2e3ebdSchin		printf("	char*		path;\n");
187da2e3ebdSchin		printf("	char*		name;\n");
188da2e3ebdSchin		printf("#ifdef _DLLENT_PRIVATE_\n");
189da2e3ebdSchin		printf("	_DLLENT_PRIVATE_\n");
190da2e3ebdSchin		printf("#endif\n");
191da2e3ebdSchin		printf("} Dllent_t;\n");
192da2e3ebdSchin		printf("\n");
193da2e3ebdSchin		printf("typedef struct Dllscan_s\n");
194da2e3ebdSchin		printf("{\n");
195da2e3ebdSchin		printf("	void*		pad;\n");
196da2e3ebdSchin		printf("#ifdef _DLLSCAN_PRIVATE_\n");
197da2e3ebdSchin		printf("	_DLLSCAN_PRIVATE_\n");
198da2e3ebdSchin		printf("#endif\n");
199da2e3ebdSchin		printf("} Dllscan_t;\n");
200da2e3ebdSchin	#if !_hdr_dlfcn || !_lib_dlopen
201da2e3ebdSchin		printf("\n");
202da2e3ebdSchin		printf("extern void*		dlopen(const char*, int);\n");
203da2e3ebdSchin		printf("extern void*		dlsym(void*, const char*);\n");
204da2e3ebdSchin		printf("extern int		dlclose(void*);\n");
205da2e3ebdSchin		printf("extern char*		dlerror(void);\n");
206da2e3ebdSchin	#endif
207da2e3ebdSchin		printf("\n");
208da2e3ebdSchin		printf("#if _BLD_dll && defined(__EXPORT__)\n");
209da2e3ebdSchin		printf("#define extern          __EXPORT__\n");
210da2e3ebdSchin		printf("#endif\n");
211da2e3ebdSchin		printf("\n");
212da2e3ebdSchin		printf("extern Dllinfo_t*	dllinfo(void);\n");
213da2e3ebdSchin		printf("extern void*		dllplug(const char*, const char*, const char*, int, char*, size_t);\n");
214da2e3ebdSchin		printf("extern void*		dllfind(const char*, const char*, int, char*, size_t);\n");
215*34f9b3eeSRoland Mainz		printf("extern void*		dllopen(const char*, int);\n");
216da2e3ebdSchin		printf("extern void*		dllnext(int);\n");
217da2e3ebdSchin		printf("extern void*		dlllook(void*, const char*);\n");
218da2e3ebdSchin	#if _hdr_rld_interface
219da2e3ebdSchin		if (i >= 0)
220da2e3ebdSchin		{
221da2e3ebdSchin			printf("\n");
222da2e3ebdSchin			printf("extern void*		_dll_next(int, _DLL_RLD_SYM_TYPE*);\n");
223da2e3ebdSchin			printf("#define dllnext(f)	_dll_next(f, &_DLL_RLD_SYM)\n");
224da2e3ebdSchin		}
225da2e3ebdSchin	#endif
226da2e3ebdSchin		printf("\n");
227da2e3ebdSchin		printf("extern Dllscan_t*	dllsopen(const char*, const char*, const char*);\n");
228da2e3ebdSchin		printf("extern Dllent_t*	dllsread(Dllscan_t*);\n");
229da2e3ebdSchin		printf("extern int		dllsclose(Dllscan_t*);\n");
230da2e3ebdSchin		printf("\n");
231da2e3ebdSchin		printf("#undef  extern\n");
232da2e3ebdSchin	#if _hdr_rld_interface
233da2e3ebdSchin		if (i >= 0)
234da2e3ebdSchin		{
235da2e3ebdSchin			printf("\n");
236da2e3ebdSchin			printf("extern _DLL_RLD_SYM_TYPE _DLL_RLD_SYM;\n");
237da2e3ebdSchin		}
238da2e3ebdSchin	#endif
239da2e3ebdSchin		printf("\n");
240da2e3ebdSchin		return 0;
241da2e3ebdSchin	}
242da2e3ebdSchin}end
243