xref: /titanic_44/usr/src/lib/libdll/common/features/dll (revision a776e90690d98f629ab57f6493ff5949af9d65bd)
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 _hdr_dlfcn && _lib_dlopen
79	#include <dlfcn.h>
80	#endif
81	#if _hdr_rld_interface
82	#include <rld_interface.h>
83	#endif
84	int
85	main()
86	{
87		int		i;
88	#if _hdr_rld_interface
89		void*		dll;
90		static char*	local[] = { "__elf_header", "_call_add_gp_range", "_etext" };
91	#endif
92		printf("\n");
93	#if _hdr_dlfcn && _lib_dlopen
94		printf("#include <dlfcn.h>\n");
95	#endif
96	#ifndef RTLD_LAZY
97		i = 0;
98		printf("\n");
99		printf("#define RTLD_LAZY	1\n");
100	#else
101		i = 1;
102	#endif
103	#ifndef RTLD_NOW
104		if (i)
105		{
106			i = 0;
107			printf("\n");
108		}
109		printf("#define RTLD_NOW	2\n");
110	#endif
111	#ifndef RTLD_GLOBAL
112		if (i)
113		{
114			i = 0;
115			printf("\n");
116		}
117		printf("#define RTLD_GLOBAL	0\n");
118	#endif
119	#ifndef RTLD_LOCAL
120		if (i)
121		{
122			i = 0;
123			printf("\n");
124		}
125		printf("#define RTLD_LOCAL	0\n");
126	#endif
127	#ifndef RTLD_PARENT
128		if (i)
129		{
130			i = 0;
131			printf("\n");
132		}
133		printf("#define RTLD_PARENT	0\n");
134	#endif
135	#if defined(_hdr_mach_o_dyld) && !defined(RTLD_NEXT)
136		if (i)
137		{
138			i = 0;
139			printf("\n");
140		}
141		printf("#define RTLD_NEXT	((void*)16)\n");
142	#endif
143	#if _hdr_rld_interface
144		if (!(dll = dlopen(0, RTLD_LAZY)))
145			i = -1;
146		else
147		{
148			for (i = 0; i < sizeof(local) / sizeof(local[0]); i++)
149				if (dlsym(dll, local[i]))
150					break;
151			if (i >= sizeof(local) / sizeof(local[0]))
152				i = -1;
153		}
154		if (i >= 0)
155		{
156			printf("\n");
157			printf("#define _DLL_RLD_SYM		%s\n", local[i]);
158			printf("#define _DLL_RLD_SYM_STR	\"%s\"\n", local[i]);
159			printf("#define _DLL_RLD_SYM_TYPE	void*\n");
160		}
161	#endif
162		printf("\n");
163		printf("#define DLL_INFO_PREVER	0x0001	/* pre-suffix style version */\n");
164		printf("#define DLL_INFO_DOTVER	0x0002	/* post-suffix style version */\n");
165		printf("\n");
166		printf("typedef struct Dllinfo_s\n");
167		printf("{\n");
168		printf("	char**	sibling;	/* sibling dirs on $PATH */\n");
169		printf("	char*	prefix;		/* library name prefix */\n");
170		printf("	char*	suffix;		/* library name suffix */\n");
171		printf("	char*	env;		/* library path env var */\n");
172		printf("	int	flags;		/* DLL_INFO_* flags */\n");
173		printf("#ifdef _DLLINFO_PRIVATE_\n");
174		printf("	_DLLINFO_PRIVATE_\n");
175		printf("#endif\n");
176		printf("} Dllinfo_t;\n");
177		printf("\n");
178		printf("typedef struct Dllent_s\n");
179		printf("{\n");
180		printf("	char*		path;\n");
181		printf("	char*		name;\n");
182		printf("#ifdef _DLLENT_PRIVATE_\n");
183		printf("	_DLLENT_PRIVATE_\n");
184		printf("#endif\n");
185		printf("} Dllent_t;\n");
186		printf("\n");
187		printf("typedef struct Dllscan_s\n");
188		printf("{\n");
189		printf("	void*		pad;\n");
190		printf("#ifdef _DLLSCAN_PRIVATE_\n");
191		printf("	_DLLSCAN_PRIVATE_\n");
192		printf("#endif\n");
193		printf("} Dllscan_t;\n");
194	#if !_hdr_dlfcn || !_lib_dlopen
195		printf("\n");
196		printf("extern void*		dlopen(const char*, int);\n");
197		printf("extern void*		dlsym(void*, const char*);\n");
198		printf("extern int		dlclose(void*);\n");
199		printf("extern char*		dlerror(void);\n");
200	#endif
201		printf("\n");
202		printf("#if _BLD_dll && defined(__EXPORT__)\n");
203		printf("#define extern          __EXPORT__\n");
204		printf("#endif\n");
205		printf("\n");
206		printf("extern Dllinfo_t*	dllinfo(void);\n");
207		printf("extern void*		dllplug(const char*, const char*, const char*, int, char*, size_t);\n");
208		printf("extern void*		dllfind(const char*, const char*, int, char*, size_t);\n");
209		printf("extern void*		dllnext(int);\n");
210		printf("extern void*		dlllook(void*, const char*);\n");
211	#if _hdr_rld_interface
212		if (i >= 0)
213		{
214			printf("\n");
215			printf("extern void*		_dll_next(int, _DLL_RLD_SYM_TYPE*);\n");
216			printf("#define dllnext(f)	_dll_next(f, &_DLL_RLD_SYM)\n");
217		}
218	#endif
219		printf("\n");
220		printf("extern Dllscan_t*	dllsopen(const char*, const char*, const char*);\n");
221		printf("extern Dllent_t*	dllsread(Dllscan_t*);\n");
222		printf("extern int		dllsclose(Dllscan_t*);\n");
223		printf("\n");
224		printf("#undef  extern\n");
225	#if _hdr_rld_interface
226		if (i >= 0)
227		{
228			printf("\n");
229			printf("extern _DLL_RLD_SYM_TYPE _DLL_RLD_SYM;\n");
230		}
231	#endif
232		printf("\n");
233		return 0;
234	}
235}end
236