1 /*-------------------------------------------------------------------------
4 * Dynamic Loader for Postgres for Linux, generated from those for
7 * You need to install the dld library on your Linux system!
9 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/backend/port/dynloader/linux.c
16 *-------------------------------------------------------------------------
25 #include "dynloader.h"
26 #include "miscadmin.h"
32 pg_dlopen(char *filename)
35 elog(ERROR, "dynamic load not supported");
38 static int dl_initialized = 0;
41 * initializes the dynamic loader with the executable's pathname. (only
42 * needs to do this the first time pg_dlopen is called.)
46 if (dld_init(dld_find_executable(my_exec_path)))
50 * if there are undefined symbols, we want dl to search from the
51 * following libraries also.
57 * link the file, then check for undefined symbols!
59 if (dld_link(filename))
63 * If undefined symbols: try to link with the C and math libraries! This
64 * could be smarter, if the dynamic linker was able to handle shared libs!
66 if (dld_undefined_sym_count > 0)
68 if (dld_link("/usr/lib/libc.a"))
70 elog(WARNING, "could not link C library");
73 if (dld_undefined_sym_count > 0)
75 if (dld_link("/usr/lib/libm.a"))
77 elog(WARNING, "could not link math library");
80 if (dld_undefined_sym_count > 0)
82 int count = dld_undefined_sym_count;
83 char **list = dld_list_undefined_sym();
85 /* list the undefined symbols, if any */
88 elog(WARNING, "\"%s\" is undefined", *list);
93 dld_unlink_by_file(filename, 1);
99 return (void *) strdup(filename);
104 pg_dlsym(void *handle, char *funcname)
109 return (PGFunction) dld_get_func((funcname));
114 pg_dlclose(void *handle)
118 dld_unlink_by_file(handle, 1);
127 return "dynaloader unsupported";
129 return dld_strerror(dld_errno);
133 #endif /* !HAVE_DLOPEN */