xref: /onnv-gate/usr/src/lib/libdll/common/features/dll (revision 10898:1883b621b3ea)
14887Schinset	prototyped
24887Schinhdr	dl,dlfcn,dll,rld_interface,mach-o/dyld
34887Schinsys	ldr
44887Schinlib	dlopen -ldl
54887Schinlib	dllload,loadbind,shl_load -ldl
64887Schintst	dll_DYNAMIC link{
74887Schin	#include <sys/types.h>
84887Schin	#include <link.h>
94887Schin	extern struct link_dynamic _DYNAMIC;
104887Schin	int
114887Schin	main()
124887Schin	{
134887Schin		return _DYNAMIC.ld_version;
144887Schin	}
154887Schin}end
164887Schintst	run{
174887Schin	lib=
184887Schin	for d in  /shlib /usr/shlib /lib /usr/lib
194887Schin	do	if	test -d $d
204887Schin		then	for s in "*.*" "*[!a]*"
214887Schin			do	for b in libc
224887Schin				do	for i in $d/$b.$s
234887Schin					do	if	test -f $i
244887Schin						then	lib=$i
254887Schin						fi
264887Schin					done
274887Schin					case $lib in
284887Schin					?*)	break 3 ;;
294887Schin					esac
304887Schin				done
314887Schin			done
324887Schin		fi
334887Schin	done
344887Schin	case $lib in
354887Schin	*.[0-9]*.[0-9]*)
364887Schin		i=`echo $lib | sed 's,\([^0-9]*[0-9]*\).*,\1,'`
374887Schin		if	test -f $i
384887Schin		then	lib=$i
394887Schin		fi
404887Schin		;;
414887Schin	esac
424887Schin	# some run time linkers barf with /lib/xxx if
434887Schin	# /usr/lib/xxx is there
444887Schin	case $lib in
454887Schin	/usr*)	;;
464887Schin	*)	if	test -f /usr$lib
474887Schin		then	lib=/usr$lib
484887Schin		fi
494887Schin		;;
504887Schin	esac
514887Schin	case $lib in
524887Schin	"")	lib=/lib/libc.so.1 ;;
534887Schin	esac
544887Schin	case $lib in
554887Schin	/usr/lib/*)
564887Schin		case `package` in
574887Schin		sgi.mips3)
584887Schin			abi=/lib32
594887Schin			;;
604887Schin		sgi.mips4)
614887Schin			abi=/lib64
624887Schin			;;
634887Schin		*)	abi=
644887Schin			;;
654887Schin		esac
664887Schin		case $abi in
674887Schin		?*)	if	test -d $abi
684887Schin			then	lib=`echo $lib | sed 's,/usr/lib/,,'`
694887Schin				lib=$abi/$lib
704887Schin			fi
714887Schin			;;
724887Schin		esac
734887Schin		;;
744887Schin	esac
754887Schin	echo "#define _DLL_NEXT_PATH	\"$lib\""
764887Schin}end
774887Schintst	- output{
78*10898Sroland.mainz@nrubsig.org	#if defined(__MVS__) && !defined(__SUSV3)
79*10898Sroland.mainz@nrubsig.org	#define __SUSV3		1
80*10898Sroland.mainz@nrubsig.org	#endif
814887Schin	#if _hdr_dlfcn && _lib_dlopen
824887Schin	#include <dlfcn.h>
834887Schin	#endif
844887Schin	#if _hdr_rld_interface
854887Schin	#include <rld_interface.h>
864887Schin	#endif
874887Schin	int
884887Schin	main()
894887Schin	{
904887Schin		int		i;
914887Schin	#if _hdr_rld_interface
924887Schin		void*		dll;
934887Schin		static char*	local[] = { "__elf_header", "_call_add_gp_range", "_etext" };
944887Schin	#endif
954887Schin		printf("\n");
96*10898Sroland.mainz@nrubsig.org		printf("#if defined(__MVS__) && !defined(__SUSV3)\n");
97*10898Sroland.mainz@nrubsig.org		printf("#define __SUSV3		1\n");
98*10898Sroland.mainz@nrubsig.org		printf("#endif\n");
994887Schin	#if _hdr_dlfcn && _lib_dlopen
1004887Schin		printf("#include <dlfcn.h>\n");
1014887Schin	#endif
1024887Schin	#ifndef RTLD_LAZY
1034887Schin		i = 0;
1044887Schin		printf("\n");
1054887Schin		printf("#define RTLD_LAZY	1\n");
1064887Schin	#else
1074887Schin		i = 1;
1084887Schin	#endif
1094887Schin	#ifndef RTLD_NOW
1104887Schin		if (i)
1114887Schin		{
1124887Schin			i = 0;
1134887Schin			printf("\n");
1144887Schin		}
1154887Schin		printf("#define RTLD_NOW	2\n");
1164887Schin	#endif
1174887Schin	#ifndef RTLD_GLOBAL
1184887Schin		if (i)
1194887Schin		{
1204887Schin			i = 0;
1214887Schin			printf("\n");
1224887Schin		}
1234887Schin		printf("#define RTLD_GLOBAL	0\n");
1244887Schin	#endif
1254887Schin	#ifndef RTLD_LOCAL
1264887Schin		if (i)
1274887Schin		{
1284887Schin			i = 0;
1294887Schin			printf("\n");
1304887Schin		}
1314887Schin		printf("#define RTLD_LOCAL	0\n");
1324887Schin	#endif
1334887Schin	#ifndef RTLD_PARENT
1344887Schin		if (i)
1354887Schin		{
1364887Schin			i = 0;
1374887Schin			printf("\n");
1384887Schin		}
1394887Schin		printf("#define RTLD_PARENT	0\n");
1404887Schin	#endif
1414887Schin	#if defined(_hdr_mach_o_dyld) && !defined(RTLD_NEXT)
1424887Schin		if (i)
1434887Schin		{
1444887Schin			i = 0;
1454887Schin			printf("\n");
1464887Schin		}
1474887Schin		printf("#define RTLD_NEXT	((void*)16)\n");
1484887Schin	#endif
1494887Schin	#if _hdr_rld_interface
1504887Schin		if (!(dll = dlopen(0, RTLD_LAZY)))
1514887Schin			i = -1;
1524887Schin		else
1534887Schin		{
1544887Schin			for (i = 0; i < sizeof(local) / sizeof(local[0]); i++)
1554887Schin				if (dlsym(dll, local[i]))
1564887Schin					break;
1574887Schin			if (i >= sizeof(local) / sizeof(local[0]))
1584887Schin				i = -1;
1594887Schin		}
1604887Schin		if (i >= 0)
1614887Schin		{
1624887Schin			printf("\n");
1634887Schin			printf("#define _DLL_RLD_SYM		%s\n", local[i]);
1644887Schin			printf("#define _DLL_RLD_SYM_STR	\"%s\"\n", local[i]);
1654887Schin			printf("#define _DLL_RLD_SYM_TYPE	void*\n");
1664887Schin		}
1674887Schin	#endif
1684887Schin		printf("\n");
1694887Schin		printf("#define DLL_INFO_PREVER	0x0001	/* pre-suffix style version */\n");
1704887Schin		printf("#define DLL_INFO_DOTVER	0x0002	/* post-suffix style version */\n");
1714887Schin		printf("\n");
1724887Schin		printf("typedef struct Dllinfo_s\n");
1734887Schin		printf("{\n");
1744887Schin		printf("	char**	sibling;	/* sibling dirs on $PATH */\n");
1754887Schin		printf("	char*	prefix;		/* library name prefix */\n");
1764887Schin		printf("	char*	suffix;		/* library name suffix */\n");
1774887Schin		printf("	char*	env;		/* library path env var */\n");
1784887Schin		printf("	int	flags;		/* DLL_INFO_* flags */\n");
1794887Schin		printf("#ifdef _DLLINFO_PRIVATE_\n");
1804887Schin		printf("	_DLLINFO_PRIVATE_\n");
1814887Schin		printf("#endif\n");
1824887Schin		printf("} Dllinfo_t;\n");
1834887Schin		printf("\n");
1844887Schin		printf("typedef struct Dllent_s\n");
1854887Schin		printf("{\n");
1864887Schin		printf("	char*		path;\n");
1874887Schin		printf("	char*		name;\n");
1884887Schin		printf("#ifdef _DLLENT_PRIVATE_\n");
1894887Schin		printf("	_DLLENT_PRIVATE_\n");
1904887Schin		printf("#endif\n");
1914887Schin		printf("} Dllent_t;\n");
1924887Schin		printf("\n");
1934887Schin		printf("typedef struct Dllscan_s\n");
1944887Schin		printf("{\n");
1954887Schin		printf("	void*		pad;\n");
1964887Schin		printf("#ifdef _DLLSCAN_PRIVATE_\n");
1974887Schin		printf("	_DLLSCAN_PRIVATE_\n");
1984887Schin		printf("#endif\n");
1994887Schin		printf("} Dllscan_t;\n");
2004887Schin	#if !_hdr_dlfcn || !_lib_dlopen
2014887Schin		printf("\n");
2024887Schin		printf("extern void*		dlopen(const char*, int);\n");
2034887Schin		printf("extern void*		dlsym(void*, const char*);\n");
2044887Schin		printf("extern int		dlclose(void*);\n");
2054887Schin		printf("extern char*		dlerror(void);\n");
2064887Schin	#endif
2074887Schin		printf("\n");
2084887Schin		printf("#if _BLD_dll && defined(__EXPORT__)\n");
2094887Schin		printf("#define extern          __EXPORT__\n");
2104887Schin		printf("#endif\n");
2114887Schin		printf("\n");
2124887Schin		printf("extern Dllinfo_t*	dllinfo(void);\n");
2134887Schin		printf("extern void*		dllplug(const char*, const char*, const char*, int, char*, size_t);\n");
2144887Schin		printf("extern void*		dllfind(const char*, const char*, int, char*, size_t);\n");
215*10898Sroland.mainz@nrubsig.org		printf("extern void*		dllopen(const char*, int);\n");
2164887Schin		printf("extern void*		dllnext(int);\n");
2174887Schin		printf("extern void*		dlllook(void*, const char*);\n");
2184887Schin	#if _hdr_rld_interface
2194887Schin		if (i >= 0)
2204887Schin		{
2214887Schin			printf("\n");
2224887Schin			printf("extern void*		_dll_next(int, _DLL_RLD_SYM_TYPE*);\n");
2234887Schin			printf("#define dllnext(f)	_dll_next(f, &_DLL_RLD_SYM)\n");
2244887Schin		}
2254887Schin	#endif
2264887Schin		printf("\n");
2274887Schin		printf("extern Dllscan_t*	dllsopen(const char*, const char*, const char*);\n");
2284887Schin		printf("extern Dllent_t*	dllsread(Dllscan_t*);\n");
2294887Schin		printf("extern int		dllsclose(Dllscan_t*);\n");
2304887Schin		printf("\n");
2314887Schin		printf("#undef  extern\n");
2324887Schin	#if _hdr_rld_interface
2334887Schin		if (i >= 0)
2344887Schin		{
2354887Schin			printf("\n");
2364887Schin			printf("extern _DLL_RLD_SYM_TYPE _DLL_RLD_SYM;\n");
2374887Schin		}
2384887Schin	#endif
2394887Schin		printf("\n");
2404887Schin		return 0;
2414887Schin	}
2424887Schin}end
243