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