1N/Aset prototyped
1N/Ahdr dl,dlfcn,dll,rld_interface,mach-o/dyld
1N/Asys ldr
1N/Alib dlopen -ldl
1N/Alib dllload,loadbind,shl_load -ldl
1N/Atst dll_DYNAMIC link{
1N/A #include <sys/types.h>
1N/A #include <link.h>
1N/A extern struct link_dynamic _DYNAMIC;
1N/A int
1N/A main()
1N/A {
1N/A return _DYNAMIC.ld_version;
1N/A }
1N/A}end
1N/Atst run{
1N/A lib=
1N/A for d in /shlib /usr/shlib /lib /usr/lib
1N/A do if test -d $d
1N/A then for s in "*.*" "*[!a]*"
1N/A do for b in libc
1N/A do for i in $d/$b.$s
1N/A do if test -f $i
1N/A then lib=$i
1N/A fi
1N/A done
1N/A case $lib in
1N/A ?*) break 3 ;;
1N/A esac
1N/A done
1N/A done
1N/A fi
1N/A done
1N/A case $lib in
1N/A *.[0-9]*.[0-9]*)
1N/A i=`echo $lib | sed 's,\([^0-9]*[0-9]*\).*,\1,'`
1N/A if test -f $i
1N/A then lib=$i
1N/A fi
1N/A ;;
1N/A esac
1N/A # some run time linkers barf with /lib/xxx if
1N/A # /usr/lib/xxx is there
1N/A case $lib in
1N/A /usr*) ;;
1N/A *) if test -f /usr$lib
1N/A then lib=/usr$lib
1N/A fi
1N/A ;;
1N/A esac
1N/A case $lib in
1N/A "") lib=/lib/libc.so.1 ;;
1N/A esac
1N/A case $lib in
1N/A /usr/lib/*)
1N/A case `package` in
1N/A sgi.mips3)
1N/A abi=/lib32
1N/A ;;
1N/A sgi.mips4)
1N/A abi=/lib64
1N/A ;;
1N/A *) abi=
1N/A ;;
1N/A esac
1N/A case $abi in
1N/A ?*) if test -d $abi
1N/A then lib=`echo $lib | sed 's,/usr/lib/,,'`
1N/A lib=$abi/$lib
1N/A fi
1N/A ;;
1N/A esac
1N/A ;;
1N/A esac
1N/A echo "#define _DLL_NEXT_PATH \"$lib\""
1N/A}end
1N/Atst - output{
1N/A #if defined(__MVS__) && !defined(__SUSV3)
1N/A #define __SUSV3 1
1N/A #endif
1N/A #if _hdr_dlfcn && _lib_dlopen
1N/A #include <dlfcn.h>
1N/A #endif
1N/A #if _hdr_rld_interface
1N/A #include <rld_interface.h>
1N/A #endif
1N/A int
1N/A main()
1N/A {
1N/A int i;
1N/A #if _hdr_rld_interface
1N/A void* dll;
1N/A static char* local[] = { "__elf_header", "_call_add_gp_range", "_etext" };
1N/A #endif
1N/A printf("\n");
1N/A printf("#if defined(__MVS__) && !defined(__SUSV3)\n");
1N/A printf("#define __SUSV3 1\n");
1N/A printf("#endif\n");
1N/A #if _hdr_dlfcn && _lib_dlopen
1N/A printf("#include <dlfcn.h>\n");
1N/A #endif
1N/A #ifndef RTLD_LAZY
1N/A i = 0;
1N/A printf("\n");
1N/A printf("#define RTLD_LAZY 1\n");
1N/A #else
1N/A i = 1;
1N/A #endif
1N/A #ifndef RTLD_NOW
1N/A if (i)
1N/A {
1N/A i = 0;
1N/A printf("\n");
1N/A }
1N/A printf("#define RTLD_NOW 2\n");
1N/A #endif
1N/A #ifndef RTLD_GLOBAL
1N/A if (i)
1N/A {
1N/A i = 0;
1N/A printf("\n");
1N/A }
1N/A printf("#define RTLD_GLOBAL 0\n");
1N/A #endif
1N/A #ifndef RTLD_LOCAL
1N/A if (i)
1N/A {
1N/A i = 0;
1N/A printf("\n");
1N/A }
1N/A printf("#define RTLD_LOCAL 0\n");
1N/A #endif
1N/A #ifndef RTLD_PARENT
1N/A if (i)
1N/A {
1N/A i = 0;
1N/A printf("\n");
1N/A }
1N/A printf("#define RTLD_PARENT 0\n");
1N/A #endif
1N/A #if defined(_hdr_mach_o_dyld) && !defined(RTLD_NEXT)
1N/A if (i)
1N/A {
1N/A i = 0;
1N/A printf("\n");
1N/A }
1N/A printf("#define RTLD_NEXT ((void*)16)\n");
1N/A #endif
1N/A #if _hdr_rld_interface
1N/A if (!(dll = dlopen(0, RTLD_LAZY)))
1N/A i = -1;
1N/A else
1N/A {
1N/A for (i = 0; i < sizeof(local) / sizeof(local[0]); i++)
1N/A if (dlsym(dll, local[i]))
1N/A break;
1N/A if (i >= sizeof(local) / sizeof(local[0]))
1N/A i = -1;
1N/A }
1N/A if (i >= 0)
1N/A {
1N/A printf("\n");
1N/A printf("#define _DLL_RLD_SYM %s\n", local[i]);
1N/A printf("#define _DLL_RLD_SYM_STR \"%s\"\n", local[i]);
1N/A printf("#define _DLL_RLD_SYM_TYPE void*\n");
1N/A }
1N/A #endif
1N/A printf("\n");
1N/A printf("#define DLL_INFO_PREVER 0x0001 /* pre-suffix style version */\n");
1N/A printf("#define DLL_INFO_DOTVER 0x0002 /* post-suffix style version */\n");
1N/A printf("\n");
1N/A printf("typedef unsigned long (*Dll_plugin_version_f)(void);\n");
1N/A printf("\n");
1N/A printf("typedef struct Dllinfo_s\n");
1N/A printf("{\n");
1N/A printf(" char** sibling; /* sibling dirs on $PATH */\n");
1N/A printf(" char* prefix; /* library name prefix */\n");
1N/A printf(" char* suffix; /* library name suffix */\n");
1N/A printf(" char* env; /* library path env var */\n");
1N/A printf(" int flags; /* DLL_INFO_* flags */\n");
1N/A printf("#ifdef _DLLINFO_PRIVATE_\n");
1N/A printf(" _DLLINFO_PRIVATE_\n");
1N/A printf("#endif\n");
1N/A printf("} Dllinfo_t;\n");
1N/A printf("\n");
1N/A printf("typedef struct Dllent_s\n");
1N/A printf("{\n");
1N/A printf(" char* path;\n");
1N/A printf(" char* name;\n");
1N/A printf("#ifdef _DLLENT_PRIVATE_\n");
1N/A printf(" _DLLENT_PRIVATE_\n");
1N/A printf("#endif\n");
1N/A printf("} Dllent_t;\n");
1N/A printf("\n");
1N/A printf("typedef struct Dllscan_s\n");
1N/A printf("{\n");
1N/A printf(" void* pad;\n");
1N/A printf("#ifdef _DLLSCAN_PRIVATE_\n");
1N/A printf(" _DLLSCAN_PRIVATE_\n");
1N/A printf("#endif\n");
1N/A printf("} Dllscan_t;\n");
1N/A #if !_hdr_dlfcn || !_lib_dlopen
1N/A printf("\n");
1N/A printf("extern void* dlopen(const char*, int);\n");
1N/A printf("extern void* dlsym(void*, const char*);\n");
1N/A printf("extern int dlclose(void*);\n");
1N/A printf("extern char* dlerror(void);\n");
1N/A #endif
1N/A printf("\n");
1N/A printf("#if _BLD_dll && defined(__EXPORT__)\n");
1N/A printf("#define extern __EXPORT__\n");
1N/A printf("#endif\n");
1N/A printf("\n");
1N/A printf("extern Dllinfo_t* dllinfo(void);\n");
1N/A printf("extern void* dllplugin(const char*, const char*, const char*, unsigned long, unsigned long*, int, char*, size_t);\n");
1N/A printf("extern void* dllplug(const char*, const char*, const char*, int, char*, size_t);\n");
1N/A printf("extern void* dllfind(const char*, const char*, int, char*, size_t);\n");
1N/A printf("extern void* dllopen(const char*, int);\n");
1N/A printf("extern void* dllnext(int);\n");
1N/A printf("extern void* dlllook(void*, const char*);\n");
1N/A printf("extern int dllcheck(void*, const char*, unsigned long, unsigned long*);\n");
1N/A printf("extern unsigned long dllversion(void*, const char*);\n");
1N/A printf("extern char* dllerror(int);\n");
1N/A #if _hdr_rld_interface
1N/A if (i >= 0)
1N/A {
1N/A printf("\n");
1N/A printf("extern void* _dll_next(int, _DLL_RLD_SYM_TYPE*);\n");
1N/A printf("#define dllnext(f) _dll_next(f, &_DLL_RLD_SYM)\n");
1N/A }
1N/A #endif
1N/A printf("\n");
1N/A printf("extern Dllscan_t* dllsopen(const char*, const char*, const char*);\n");
1N/A printf("extern Dllent_t* dllsread(Dllscan_t*);\n");
1N/A printf("extern int dllsclose(Dllscan_t*);\n");
1N/A printf("\n");
1N/A printf("#undef extern\n");
1N/A #if _hdr_rld_interface
1N/A if (i >= 0)
1N/A {
1N/A printf("\n");
1N/A printf("extern _DLL_RLD_SYM_TYPE _DLL_RLD_SYM;\n");
1N/A }
1N/A #endif
1N/A printf("\n");
1N/A return 0;
1N/A }
1N/A}end