Created
February 11, 2016 00:05
-
-
Save steffengy/45ca2e17dd90592358b2 to your computer and use it in GitHub Desktop.
9.5 static build attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0c9bdf00d985fade4fb324b145e8f52c3defa857 Mon Sep 17 00:00:00 2001 | |
From: Steffen <[email protected]> | |
Date: Thu, 11 Feb 2016 01:04:27 +0100 | |
Subject: [PATCH] emulated dynloader: static build of hopefully all essential | |
core components | |
--- | |
src/Makefile | 5 +- | |
src/Makefile.global.in | 2 +- | |
src/Makefile.shlib | 24 ++- | |
src/backend/Makefile | 4 +- | |
src/backend/catalog/pg_proc.c | 2 +- | |
src/backend/port/Makefile | 38 +++- | |
src/backend/port/dynloader/linux.c | 374 +++++++++++++++++++++++++++++-------- | |
src/backend/utils/fmgr/dfmgr.c | 119 +----------- | |
src/backend/utils/fmgr/fmgr.c | 37 +--- | |
src/include/fmgr.h | 11 +- | |
10 files changed, 360 insertions(+), 256 deletions(-) | |
diff --git a/src/Makefile b/src/Makefile | |
index e859826..344dc56 100644 | |
--- a/src/Makefile | |
+++ b/src/Makefile | |
@@ -16,16 +16,15 @@ SUBDIRS = \ | |
common \ | |
port \ | |
timezone \ | |
- backend \ | |
backend/utils/mb/conversion_procs \ | |
backend/snowball \ | |
+ backend \ | |
+ pl \ | |
include \ | |
interfaces \ | |
backend/replication/libpqwalreceiver \ | |
bin \ | |
- pl \ | |
makefiles \ | |
- test/regress | |
# There are too many interdependencies between the subdirectories, so | |
# don't attempt parallel make here. | |
diff --git a/src/Makefile.global.in b/src/Makefile.global.in | |
index 68252fd..20d955d 100644 | |
--- a/src/Makefile.global.in | |
+++ b/src/Makefile.global.in | |
@@ -238,7 +238,7 @@ endif # not PGXS | |
CC = @CC@ | |
GCC = @GCC@ | |
SUN_STUDIO_CC = @SUN_STUDIO_CC@ | |
-CFLAGS = @CFLAGS@ | |
+CFLAGS = @CFLAGS@ -static | |
CFLAGS_VECTOR = @CFLAGS_VECTOR@ | |
CFLAGS_SSE42 = @CFLAGS_SSE42@ | |
diff --git a/src/Makefile.shlib b/src/Makefile.shlib | |
index 86db52f..ac604de 100644 | |
--- a/src/Makefile.shlib | |
+++ b/src/Makefile.shlib | |
@@ -73,19 +73,19 @@ LINK.static = $(AR) $(AROPT) | |
-ifdef SO_MAJOR_VERSION | |
+# ifdef SO_MAJOR_VERSION | |
# Default library naming convention used by the majority of platforms | |
-shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) | |
-shlib_major = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) | |
-shlib_bare = lib$(NAME)$(DLSUFFIX) | |
+#shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) | |
+#shlib_major = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) | |
+#shlib_bare = lib$(NAME)$(DLSUFFIX) | |
# Testing the soname variable is a reliable way to determine whether a | |
# linkable library is being built. | |
-soname = $(shlib_major) | |
-pkgconfigdir = $(libdir)/pkgconfig | |
-else | |
+# soname = $(shlib_major) | |
+#pkgconfigdir = $(libdir)/pkgconfig | |
+#else | |
# Naming convention for dynamically loadable modules | |
-shlib = $(NAME)$(DLSUFFIX) | |
-endif | |
+#shlib = $(NAME)$(DLSUFFIX) | |
+# endif | |
stlib = lib$(NAME).a | |
ifndef soname | |
@@ -293,7 +293,8 @@ endif | |
all-static-lib: $(stlib) | |
-all-shared-lib: $(shlib) | |
+# all-shared-lib: $(shlib) | |
+all-shared-lib: all-static-lib | |
ifndef haslibarule | |
$(stlib): $(OBJS) | $(SHLIB_PREREQS) | |
@@ -453,11 +454,8 @@ endif # SHLIB_EXPORTS | |
## | |
.PHONY: install-lib install-lib-static install-lib-shared installdirs-lib | |
-install-lib: install-lib-shared | |
-ifdef soname | |
install-lib: install-lib-static | |
install-lib: install-lib-pc | |
-endif | |
install-lib-pc: lib$(NAME).pc installdirs-lib | |
$(INSTALL_DATA) $< '$(DESTDIR)$(pkgconfigdir)/lib$(NAME).pc' | |
diff --git a/src/backend/Makefile b/src/backend/Makefile | |
index 98b978f..0f07d38 100644 | |
--- a/src/backend/Makefile | |
+++ b/src/backend/Makefile | |
@@ -17,9 +17,9 @@ subdir = src/backend | |
top_builddir = ../.. | |
include $(top_builddir)/src/Makefile.global | |
-SUBDIRS = access bootstrap catalog parser commands executor foreign lib libpq \ | |
+SUBDIRS = utils access bootstrap catalog parser commands executor foreign lib libpq \ | |
main nodes optimizer port postmaster regex replication rewrite \ | |
- storage tcop tsearch utils $(top_builddir)/src/timezone | |
+ storage tcop tsearch $(top_builddir)/src/timezone | |
include $(srcdir)/common.mk | |
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c | |
index 7765be4..094c16f 100644 | |
--- a/src/backend/catalog/pg_proc.c | |
+++ b/src/backend/catalog/pg_proc.c | |
@@ -821,7 +821,7 @@ fmgr_c_validator(PG_FUNCTION_ARGS) | |
probin = TextDatumGetCString(tmp); | |
(void) load_external_function(probin, prosrc, true, &libraryhandle); | |
- (void) fetch_finfo_record(libraryhandle, prosrc); | |
+ //(void) fetch_finfo_record(libraryhandle, prosrc); | |
ReleaseSysCache(tuple); | |
diff --git a/src/backend/port/Makefile b/src/backend/port/Makefile | |
index c6b1d20..69477f9 100644 | |
--- a/src/backend/port/Makefile | |
+++ b/src/backend/port/Makefile | |
@@ -19,9 +19,42 @@ | |
subdir = src/backend/port | |
top_builddir = ../../.. | |
+ | |
include $(top_builddir)/src/Makefile.global | |
-OBJS = atomics.o dynloader.o pg_sema.o pg_shmem.o pg_latch.o $(TAS) | |
+STATIC_PLUGINS = $(top_srcdir)/src/backend/utils/mb/conversion_procs/ascii_and_mic/libascii_and_mic.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/libcyrillic_and_mic.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/libeuc_cn_and_mic.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/libeuc_jp_and_sjis.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/libeuc_kr_and_mic.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/libeuc_tw_and_big5.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/latin2_and_win1250/liblatin2_and_win1250.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/latin_and_mic/liblatin_and_mic.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_ascii/libutf8_and_ascii.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_big5/libutf8_and_big5.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/libutf8_and_cyrillic.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/libutf8_and_euc_cn.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/libutf8_and_euc_jp.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/libutf8_and_euc_kr.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/libutf8_and_euc_tw.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/libutf8_and_gb18030.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_gbk/libutf8_and_gbk.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/libutf8_and_iso8859.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/libutf8_and_iso8859_1.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_johab/libutf8_and_johab.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_sjis/libutf8_and_sjis.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_win/libutf8_and_win.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_uhc/libutf8_and_uhc.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_euc2004/libutf8_and_euc2004.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/utf8_and_sjis2004/libutf8_and_sjis2004.a \ | |
+ $(top_srcdir)/src/backend/utils/mb/conversion_procs/euc2004_sjis2004/libeuc2004_sjis2004.a \ | |
+ $(top_srcdir)/src/backend/snowball/libdict_snowball.a \ | |
+ $(top_srcdir)/src/pl/plpgsql/src/libplpgsql.a | |
+ | |
+$(top_srcdir)/src/pl/plpgsql/src/libplpgsql.a: | |
+ $(MAKE) -C $(top_srcdir)/src/pl/plpgsql/ all | |
+ | |
+OBJS = atomics.o dynloader.o pg_sema.o pg_shmem.o pg_latch.o $(STATIC_PLUGINS) $(TAS) | |
ifeq ($(PORTNAME), darwin) | |
SUBDIRS += darwin | |
@@ -42,6 +75,9 @@ else | |
$(CC) $(CFLAGS) -c $< | |
endif | |
+dynloader.o: dynloader.c | |
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -c dynloader.c -o $@ | |
+ | |
distclean clean: | |
rm -f tas_cpp.s | |
$(MAKE) -C darwin clean | |
diff --git a/src/backend/port/dynloader/linux.c b/src/backend/port/dynloader/linux.c | |
index 4c308d1..7802872 100644 | |
--- a/src/backend/port/dynloader/linux.c | |
+++ b/src/backend/port/dynloader/linux.c | |
@@ -25,109 +25,317 @@ | |
#include "dynloader.h" | |
#include "miscadmin.h" | |
+#define PG_DYSTATIC(name) extern Datum name(PG_FUNCTION_ARGS); | |
+#define PG_DYSTATIC_IF(name) if (strcmp(funcname, #name) == 0) ptr = &name | |
+ | |
+//check if filename ends with name | |
+#define PG_DYSTATIC_LIB(lit_name, handle) do { \ | |
+ char *name = #lit_name; \ | |
+ int file_len = strlen(filename); \ | |
+ int name_len = strlen(name); \ | |
+ if (file_len >= name_len && strcmp(filename + file_len - name_len, name) == 0) return (PGFunction)(void *)handle; \ | |
+} while(0) | |
+ | |
+PG_DYSTATIC(ascii_to_mic); | |
+PG_DYSTATIC(mic_to_ascii); | |
+// cyrillic_and_mic | |
+PG_DYSTATIC(koi8r_to_mic); | |
+PG_DYSTATIC(mic_to_koi8r); | |
+PG_DYSTATIC(iso_to_mic); | |
+PG_DYSTATIC(mic_to_iso); | |
+PG_DYSTATIC(win1251_to_mic); | |
+PG_DYSTATIC(mic_to_win1251); | |
+PG_DYSTATIC(win866_to_mic); | |
+PG_DYSTATIC(mic_to_win866); | |
+PG_DYSTATIC(koi8r_to_win1251); | |
+PG_DYSTATIC(win1251_to_koi8r); | |
+PG_DYSTATIC(koi8r_to_win866); | |
+PG_DYSTATIC(win866_to_koi8r); | |
+PG_DYSTATIC(win866_to_win1251); | |
+PG_DYSTATIC(win1251_to_win866); | |
+PG_DYSTATIC(iso_to_koi8r); | |
+PG_DYSTATIC(koi8r_to_iso); | |
+PG_DYSTATIC(iso_to_win1251); | |
+PG_DYSTATIC(win1251_to_iso); | |
+PG_DYSTATIC(iso_to_win866); | |
+PG_DYSTATIC(win866_to_iso); | |
+ | |
+PG_DYSTATIC(euc_cn_to_mic); | |
+PG_DYSTATIC(mic_to_euc_cn); | |
+ | |
+PG_DYSTATIC(euc_jp_to_sjis); | |
+PG_DYSTATIC(sjis_to_euc_jp); | |
+PG_DYSTATIC(euc_jp_to_mic); | |
+PG_DYSTATIC(mic_to_euc_jp); | |
+PG_DYSTATIC(sjis_to_mic); | |
+PG_DYSTATIC(mic_to_sjis); | |
+ | |
+PG_DYSTATIC(euc_kr_to_mic); | |
+PG_DYSTATIC(mic_to_euc_kr); | |
+ | |
+PG_DYSTATIC(euc_tw_to_big5); | |
+PG_DYSTATIC(big5_to_euc_tw); | |
+PG_DYSTATIC(euc_tw_to_mic); | |
+PG_DYSTATIC(mic_to_euc_tw); | |
+PG_DYSTATIC(big5_to_mic); | |
+PG_DYSTATIC(mic_to_big5); | |
+ | |
+PG_DYSTATIC(euc_jis_2004_to_shift_jis_2004); | |
+PG_DYSTATIC(shift_jis_2004_to_euc_jis_2004); | |
+ | |
+PG_DYSTATIC(latin1_to_mic); | |
+PG_DYSTATIC(mic_to_latin1); | |
+PG_DYSTATIC(latin3_to_mic); | |
+PG_DYSTATIC(mic_to_latin3); | |
+PG_DYSTATIC(latin4_to_mic); | |
+PG_DYSTATIC(mic_to_latin4); | |
+ | |
+PG_DYSTATIC(latin2_to_mic); | |
+PG_DYSTATIC(mic_to_latin2); | |
+PG_DYSTATIC(win1250_to_mic); | |
+PG_DYSTATIC(mic_to_win1250); | |
+PG_DYSTATIC(latin2_to_win1250); | |
+PG_DYSTATIC(win1250_to_latin2); | |
+ | |
+PG_DYSTATIC(ascii_to_utf8); | |
+PG_DYSTATIC(utf8_to_ascii); | |
+ | |
+PG_DYSTATIC(big5_to_utf8); | |
+PG_DYSTATIC(utf8_to_big5); | |
+ | |
+PG_DYSTATIC(utf8_to_koi8r); | |
+PG_DYSTATIC(koi8r_to_utf8); | |
+PG_DYSTATIC(utf8_to_koi8u); | |
+PG_DYSTATIC(koi8u_to_utf8); | |
+ | |
+PG_DYSTATIC(euc_jis_2004_to_utf8); | |
+PG_DYSTATIC(utf8_to_euc_jis_2004); | |
+ | |
+PG_DYSTATIC(euc_cn_to_utf8); | |
+PG_DYSTATIC(utf8_to_euc_cn); | |
+ | |
+PG_DYSTATIC(euc_jp_to_utf8); | |
+PG_DYSTATIC(utf8_to_euc_jp); | |
+ | |
+PG_DYSTATIC(euc_kr_to_utf8); | |
+PG_DYSTATIC(utf8_to_euc_kr); | |
+ | |
+PG_DYSTATIC(euc_tw_to_utf8); | |
+PG_DYSTATIC(utf8_to_euc_tw); | |
+ | |
+PG_DYSTATIC(gb18030_to_utf8); | |
+PG_DYSTATIC(utf8_to_gb18030); | |
+ | |
+PG_DYSTATIC(gbk_to_utf8); | |
+PG_DYSTATIC(utf8_to_gbk); | |
+ | |
+PG_DYSTATIC(iso8859_to_utf8); | |
+PG_DYSTATIC(utf8_to_iso8859); | |
+ | |
+PG_DYSTATIC(iso8859_1_to_utf8); | |
+PG_DYSTATIC(utf8_to_iso8859_1); | |
+ | |
+PG_DYSTATIC(johab_to_utf8); | |
+PG_DYSTATIC(utf8_to_johab); | |
+ | |
+PG_DYSTATIC(sjis_to_utf8); | |
+PG_DYSTATIC(utf8_to_sjis); | |
+ | |
+PG_DYSTATIC(shift_jis_2004_to_utf8); | |
+PG_DYSTATIC(utf8_to_shift_jis_2004); | |
+ | |
+PG_DYSTATIC(uhc_to_utf8); | |
+PG_DYSTATIC(utf8_to_uhc); | |
+ | |
+PG_DYSTATIC(win_to_utf8); | |
+PG_DYSTATIC(utf8_to_win); | |
+ | |
+// SNOWBALL | |
+PG_DYSTATIC(dsnowball_init); | |
+PG_DYSTATIC(dsnowball_lexize); | |
+ | |
+//PLPGSQL | |
+PG_DYSTATIC(plpgsql_call_handler); | |
+PG_DYSTATIC(plpgsql_inline_handler); | |
+PG_DYSTATIC(plpgsql_validator); | |
-#ifndef HAVE_DLOPEN | |
void * | |
pg_dlopen(char *filename) | |
{ | |
-#ifndef HAVE_DLD_H | |
- elog(ERROR, "dynamic load not supported"); | |
+ PG_DYSTATIC_LIB(ascii_and_mic, 0x01); | |
+ PG_DYSTATIC_LIB(cyrillic_and_mic, 0x02); | |
+ PG_DYSTATIC_LIB(euc_cn_and_mic, 0x03); | |
+ PG_DYSTATIC_LIB(euc_jp_and_sjis, 0x04); | |
+ PG_DYSTATIC_LIB(euc_kr_and_mic, 0x05); | |
+ PG_DYSTATIC_LIB(euc_tw_and_big5, 0x06); | |
+ PG_DYSTATIC_LIB(euc2004_sjis2004, 0x07); | |
+ PG_DYSTATIC_LIB(latin_and_mic, 0x08); | |
+ PG_DYSTATIC_LIB(latin2_and_win1250, 0x09); | |
+ PG_DYSTATIC_LIB(utf8_and_ascii, 0x0A); | |
+ PG_DYSTATIC_LIB(utf8_and_big5, 0x0B); | |
+ PG_DYSTATIC_LIB(utf8_and_cyrillic, 0x0C); | |
+ PG_DYSTATIC_LIB(utf8_and_euc_cn, 0x0D); | |
+ PG_DYSTATIC_LIB(utf8_and_euc_jp, 0x0E); | |
+ PG_DYSTATIC_LIB(utf8_and_euc_kr, 0x0F); | |
+ PG_DYSTATIC_LIB(utf8_and_euc_tw, 0x10); | |
+ PG_DYSTATIC_LIB(utf8_and_euc2004, 0x11); | |
+ PG_DYSTATIC_LIB(utf8_and_gb18030, 0x12); | |
+ PG_DYSTATIC_LIB(utf8_and_gbk, 0x13); | |
+ PG_DYSTATIC_LIB(utf8_and_iso8859, 0x14); | |
+ PG_DYSTATIC_LIB(utf8_and_iso8859_1, 0x15); | |
+ PG_DYSTATIC_LIB(utf8_and_johab, 0x16); | |
+ PG_DYSTATIC_LIB(utf8_and_sjis, 0x17); | |
+ PG_DYSTATIC_LIB(utf8_and_sjis2004, 0x18); | |
+ PG_DYSTATIC_LIB(utf8_and_uhc, 0x19); | |
+ PG_DYSTATIC_LIB(utf8_and_win, 0x1A); | |
+ | |
+ //snowball | |
+ PG_DYSTATIC_LIB(snowball, 0x1B); | |
+ //plpgsql | |
+ PG_DYSTATIC_LIB(plpgsql, 0x1C); | |
+ | |
+ elog(ERROR, "dynamic loading of %s not supported %p", filename, ascii_to_mic); | |
return NULL; | |
-#else | |
- static int dl_initialized = 0; | |
- | |
- /* | |
- * initializes the dynamic loader with the executable's pathname. (only | |
- * needs to do this the first time pg_dlopen is called.) | |
- */ | |
- if (!dl_initialized) | |
- { | |
- if (dld_init(dld_find_executable(my_exec_path))) | |
- return NULL; | |
- | |
- /* | |
- * if there are undefined symbols, we want dl to search from the | |
- * following libraries also. | |
- */ | |
- dl_initialized = 1; | |
- } | |
- | |
- /* | |
- * link the file, then check for undefined symbols! | |
- */ | |
- if (dld_link(filename)) | |
- return NULL; | |
- | |
- /* | |
- * If undefined symbols: try to link with the C and math libraries! This | |
- * could be smarter, if the dynamic linker was able to handle shared libs! | |
- */ | |
- if (dld_undefined_sym_count > 0) | |
- { | |
- if (dld_link("/usr/lib/libc.a")) | |
- { | |
- elog(WARNING, "could not link C library"); | |
- return NULL; | |
- } | |
- if (dld_undefined_sym_count > 0) | |
- { | |
- if (dld_link("/usr/lib/libm.a")) | |
- { | |
- elog(WARNING, "could not link math library"); | |
- return NULL; | |
- } | |
- if (dld_undefined_sym_count > 0) | |
- { | |
- int count = dld_undefined_sym_count; | |
- char **list = dld_list_undefined_sym(); | |
- | |
- /* list the undefined symbols, if any */ | |
- do | |
- { | |
- elog(WARNING, "\"%s\" is undefined", *list); | |
- list++; | |
- count--; | |
- } while (count > 0); | |
- | |
- dld_unlink_by_file(filename, 1); | |
- return NULL; | |
- } | |
- } | |
- } | |
- | |
- return (void *) strdup(filename); | |
-#endif | |
} | |
PGFunction | |
pg_dlsym(void *handle, char *funcname) | |
{ | |
-#ifndef HAVE_DLD_H | |
- return NULL; | |
-#else | |
- return (PGFunction) dld_get_func((funcname)); | |
-#endif | |
+ void *ptr = NULL; | |
+ if (handle == (void *)0x01) { | |
+ PG_DYSTATIC_IF(ascii_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_ascii); | |
+ } else if (handle == (void *)0x02) { | |
+ PG_DYSTATIC_IF(koi8r_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_koi8r); | |
+ PG_DYSTATIC_IF(iso_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_iso); | |
+ PG_DYSTATIC_IF(win1251_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_win1251); | |
+ PG_DYSTATIC_IF(win866_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_win866); | |
+ PG_DYSTATIC_IF(koi8r_to_win1251); | |
+ PG_DYSTATIC_IF(win1251_to_koi8r); | |
+ PG_DYSTATIC_IF(koi8r_to_win866); | |
+ PG_DYSTATIC_IF(win866_to_koi8r); | |
+ PG_DYSTATIC_IF(win866_to_win1251); | |
+ PG_DYSTATIC_IF(win1251_to_win866); | |
+ PG_DYSTATIC_IF(iso_to_koi8r); | |
+ PG_DYSTATIC_IF(koi8r_to_iso); | |
+ PG_DYSTATIC_IF(iso_to_win1251); | |
+ PG_DYSTATIC_IF(win1251_to_iso); | |
+ PG_DYSTATIC_IF(iso_to_win866); | |
+ PG_DYSTATIC_IF(win866_to_iso); | |
+ } else if (handle == (void *)0x03) { | |
+ PG_DYSTATIC_IF(euc_cn_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_euc_cn); | |
+ } else if (handle == (void *)0x04) { | |
+ PG_DYSTATIC_IF(euc_jp_to_sjis); | |
+ PG_DYSTATIC_IF(sjis_to_euc_jp); | |
+ PG_DYSTATIC_IF(euc_jp_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_euc_jp); | |
+ PG_DYSTATIC_IF(sjis_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_sjis); | |
+ } else if (handle == (void *)0x05) { | |
+ PG_DYSTATIC_IF(euc_kr_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_euc_kr); | |
+ } else if (handle == (void *)0x06) { | |
+ PG_DYSTATIC_IF(euc_tw_to_big5); | |
+ PG_DYSTATIC_IF(big5_to_euc_tw); | |
+ PG_DYSTATIC_IF(euc_tw_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_euc_tw); | |
+ PG_DYSTATIC_IF(big5_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_big5); | |
+ } else if (handle == (void *)0x07) { | |
+ PG_DYSTATIC_IF(euc_jis_2004_to_shift_jis_2004); | |
+ PG_DYSTATIC_IF(shift_jis_2004_to_euc_jis_2004); | |
+ } else if (handle == (void *)0x08) { | |
+ PG_DYSTATIC_IF(latin1_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_latin1); | |
+ PG_DYSTATIC_IF(latin3_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_latin3); | |
+ PG_DYSTATIC_IF(latin4_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_latin4); | |
+ } else if (handle == (void *)0x09) { | |
+ PG_DYSTATIC_IF(latin2_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_latin2); | |
+ PG_DYSTATIC_IF(win1250_to_mic); | |
+ PG_DYSTATIC_IF(mic_to_win1250); | |
+ PG_DYSTATIC_IF(latin2_to_win1250); | |
+ PG_DYSTATIC_IF(win1250_to_latin2); | |
+ } else if (handle == (void *)0x0A) { | |
+ PG_DYSTATIC_IF(ascii_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_ascii); | |
+ } else if (handle == (void *)0x0B) { | |
+ PG_DYSTATIC_IF(big5_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_big5); | |
+ } else if (handle == (void *)0x0C) { | |
+ PG_DYSTATIC_IF(utf8_to_koi8r); | |
+ PG_DYSTATIC_IF(koi8r_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_koi8u); | |
+ PG_DYSTATIC_IF(koi8u_to_utf8); | |
+ } else if (handle == (void *)0x0D) { | |
+ PG_DYSTATIC_IF(euc_cn_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_euc_cn); | |
+ } else if (handle == (void *)0x0E) { | |
+ PG_DYSTATIC_IF(euc_jp_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_euc_jp); | |
+ } else if (handle == (void *)0x0F) { | |
+ PG_DYSTATIC_IF(euc_kr_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_euc_kr); | |
+ } else if (handle == (void *)0x10) { | |
+ PG_DYSTATIC_IF(euc_tw_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_euc_tw); | |
+ } else if (handle == (void *)0x11) { | |
+ PG_DYSTATIC_IF(euc_jis_2004_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_euc_jis_2004); | |
+ } else if (handle == (void *)0x12) { | |
+ PG_DYSTATIC_IF(gb18030_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_gb18030); | |
+ } else if (handle == (void *)0x13) { | |
+ PG_DYSTATIC_IF(gbk_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_gbk); | |
+ } else if (handle == (void *)0x14) { | |
+ PG_DYSTATIC_IF(iso8859_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_iso8859); | |
+ } else if (handle == (void *)0x15) { | |
+ PG_DYSTATIC_IF(iso8859_1_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_iso8859_1); | |
+ } else if (handle == (void *)0x16) { | |
+ PG_DYSTATIC_IF(johab_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_johab); | |
+ } else if (handle == (void *)0x17) { | |
+ PG_DYSTATIC_IF(sjis_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_sjis); | |
+ } else if (handle == (void *)0x18) { | |
+ PG_DYSTATIC_IF(shift_jis_2004_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_shift_jis_2004); | |
+ } else if (handle == (void *)0x19) { | |
+ PG_DYSTATIC_IF(uhc_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_uhc); | |
+ } else if (handle == (void *)0x1A) { | |
+ PG_DYSTATIC_IF(win_to_utf8); | |
+ PG_DYSTATIC_IF(utf8_to_win); | |
+ } else if (handle == (void *)0x1B) { | |
+ PG_DYSTATIC_IF(dsnowball_init); | |
+ PG_DYSTATIC_IF(dsnowball_lexize); | |
+ } else if (handle == (void *)0x1C) { | |
+ PG_DYSTATIC_IF(plpgsql_call_handler); | |
+ PG_DYSTATIC_IF(plpgsql_inline_handler); | |
+ PG_DYSTATIC_IF(plpgsql_validator); | |
+ } | |
+ return (PGFunction)ptr; | |
} | |
void | |
pg_dlclose(void *handle) | |
{ | |
-#ifndef HAVE_DLD_H | |
-#else | |
- dld_unlink_by_file(handle, 1); | |
- free(handle); | |
-#endif | |
+ | |
} | |
char * | |
pg_dlerror(void) | |
{ | |
-#ifndef HAVE_DLD_H | |
return "dynaloader unspported"; | |
-#else | |
- return dld_strerror(dld_errno); | |
-#endif | |
} | |
- | |
-#endif /* !HAVE_DLOPEN */ | |
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c | |
index a0be31d..24fdbb0 100644 | |
--- a/src/backend/utils/fmgr/dfmgr.c | |
+++ b/src/backend/utils/fmgr/dfmgr.c | |
@@ -170,120 +170,15 @@ lookup_external_function(void *filehandle, char *funcname) | |
static void * | |
internal_load_library(const char *libname) | |
{ | |
- DynamicFileList *file_scanner; | |
- PGModuleMagicFunction magic_func; | |
- char *load_error; | |
- struct stat stat_buf; | |
PG_init_t PG_init; | |
- | |
- /* | |
- * Scan the list of loaded FILES to see if the file has been loaded. | |
- */ | |
- for (file_scanner = file_list; | |
- file_scanner != NULL && | |
- strcmp(libname, file_scanner->filename) != 0; | |
- file_scanner = file_scanner->next) | |
- ; | |
- | |
- if (file_scanner == NULL) | |
- { | |
- /* | |
- * Check for same files - different paths (ie, symlink or link) | |
- */ | |
- if (stat(libname, &stat_buf) == -1) | |
- ereport(ERROR, | |
- (errcode_for_file_access(), | |
- errmsg("could not access file \"%s\": %m", | |
- libname))); | |
- | |
- for (file_scanner = file_list; | |
- file_scanner != NULL && | |
- !SAME_INODE(stat_buf, *file_scanner); | |
- file_scanner = file_scanner->next) | |
- ; | |
- } | |
- | |
- if (file_scanner == NULL) | |
- { | |
- /* | |
- * File not loaded yet. | |
- */ | |
- file_scanner = (DynamicFileList *) | |
- malloc(offsetof(DynamicFileList, filename) +strlen(libname) + 1); | |
- if (file_scanner == NULL) | |
- ereport(ERROR, | |
- (errcode(ERRCODE_OUT_OF_MEMORY), | |
- errmsg("out of memory"))); | |
- | |
- MemSet(file_scanner, 0, offsetof(DynamicFileList, filename)); | |
- strcpy(file_scanner->filename, libname); | |
- file_scanner->device = stat_buf.st_dev; | |
-#ifndef WIN32 | |
- file_scanner->inode = stat_buf.st_ino; | |
-#endif | |
- file_scanner->next = NULL; | |
- | |
- file_scanner->handle = pg_dlopen(file_scanner->filename); | |
- if (file_scanner->handle == NULL) | |
- { | |
- load_error = (char *) pg_dlerror(); | |
- free((char *) file_scanner); | |
- /* errcode_for_file_access might not be appropriate here? */ | |
- ereport(ERROR, | |
- (errcode_for_file_access(), | |
- errmsg("could not load library \"%s\": %s", | |
- libname, load_error))); | |
- } | |
- | |
- /* Check the magic function to determine compatibility */ | |
- magic_func = (PGModuleMagicFunction) | |
- pg_dlsym(file_scanner->handle, PG_MAGIC_FUNCTION_NAME_STRING); | |
- if (magic_func) | |
- { | |
- const Pg_magic_struct *magic_data_ptr = (*magic_func) (); | |
- | |
- if (magic_data_ptr->len != magic_data.len || | |
- memcmp(magic_data_ptr, &magic_data, magic_data.len) != 0) | |
- { | |
- /* copy data block before unlinking library */ | |
- Pg_magic_struct module_magic_data = *magic_data_ptr; | |
- | |
- /* try to unlink library */ | |
- pg_dlclose(file_scanner->handle); | |
- free((char *) file_scanner); | |
- | |
- /* issue suitable complaint */ | |
- incompatible_module_error(libname, &module_magic_data); | |
- } | |
- } | |
- else | |
- { | |
- /* try to unlink library */ | |
- pg_dlclose(file_scanner->handle); | |
- free((char *) file_scanner); | |
- /* complain */ | |
- ereport(ERROR, | |
- (errmsg("incompatible library \"%s\": missing magic block", | |
- libname), | |
- errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro."))); | |
- } | |
- | |
- /* | |
- * If the library has a _PG_init() function, call it. | |
- */ | |
- PG_init = (PG_init_t) pg_dlsym(file_scanner->handle, "_PG_init"); | |
- if (PG_init) | |
- (*PG_init) (); | |
- | |
- /* OK to link it into list */ | |
- if (file_list == NULL) | |
- file_list = file_scanner; | |
- else | |
- file_tail->next = file_scanner; | |
- file_tail = file_scanner; | |
+ void *handle = pg_dlopen(libname); | |
+ if (handle == NULL) { | |
+ return NULL; | |
} | |
- | |
- return file_scanner->handle; | |
+ PG_init = (PG_init_t) pg_dlsym(handle, "_PG_init"); | |
+ if (PG_init) | |
+ (*PG_init) (); | |
+ return handle; | |
} | |
/* | |
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c | |
index 51f3d1b..3af87c8 100644 | |
--- a/src/backend/utils/fmgr/fmgr.c | |
+++ b/src/backend/utils/fmgr/fmgr.c | |
@@ -90,7 +90,7 @@ static void fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedur | |
static void fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple); | |
static CFuncHashTabEntry *lookup_C_func(HeapTuple procedureTuple); | |
static void record_C_func(HeapTuple procedureTuple, | |
- PGFunction user_fn, const Pg_finfo_record *inforec); | |
+ PGFunction user_fn); | |
static Datum fmgr_oldstyle(PG_FUNCTION_ARGS); | |
static Datum fmgr_security_definer(PG_FUNCTION_ARGS); | |
@@ -352,41 +352,16 @@ fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple) | |
&libraryhandle); | |
/* Get the function information record (real or default) */ | |
- inforec = fetch_finfo_record(libraryhandle, prosrcstring); | |
/* Cache the addresses for later calls */ | |
- record_C_func(procedureTuple, user_fn, inforec); | |
+ record_C_func(procedureTuple, user_fn); | |
pfree(prosrcstring); | |
pfree(probinstring); | |
} | |
- switch (inforec->api_version) | |
- { | |
- case 0: | |
- /* Old style: need to use a handler */ | |
- finfo->fn_addr = fmgr_oldstyle; | |
- fnextra = (Oldstyle_fnextra *) | |
- MemoryContextAllocZero(finfo->fn_mcxt, | |
- sizeof(Oldstyle_fnextra)); | |
- finfo->fn_extra = (void *) fnextra; | |
- fnextra->func = (func_ptr) user_fn; | |
- for (i = 0; i < procedureStruct->pronargs; i++) | |
- { | |
- fnextra->arg_toastable[i] = | |
- TypeIsToastable(procedureStruct->proargtypes.values[i]); | |
- } | |
- break; | |
- case 1: | |
- /* New style: call directly */ | |
- finfo->fn_addr = user_fn; | |
- break; | |
- default: | |
- /* Shouldn't get here if fetch_finfo_record did its job */ | |
- elog(ERROR, "unrecognized function API version: %d", | |
- inforec->api_version); | |
- break; | |
- } | |
+ /* api_version=1: New style: call directly */ | |
+ finfo->fn_addr = user_fn; | |
} | |
/* | |
@@ -526,7 +501,7 @@ lookup_C_func(HeapTuple procedureTuple) | |
*/ | |
static void | |
record_C_func(HeapTuple procedureTuple, | |
- PGFunction user_fn, const Pg_finfo_record *inforec) | |
+ PGFunction user_fn) | |
{ | |
Oid fn_oid = HeapTupleGetOid(procedureTuple); | |
CFuncHashTabEntry *entry; | |
@@ -555,7 +530,7 @@ record_C_func(HeapTuple procedureTuple, | |
entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data); | |
entry->fn_tid = procedureTuple->t_self; | |
entry->user_fn = user_fn; | |
- entry->inforec = inforec; | |
+ entry->inforec = NULL; | |
} | |
/* | |
diff --git a/src/include/fmgr.h b/src/include/fmgr.h | |
index 808d142..f00cb78 100644 | |
--- a/src/include/fmgr.h | |
+++ b/src/include/fmgr.h | |
@@ -417,15 +417,8 @@ typedef const Pg_magic_struct *(*PGModuleMagicFunction) (void); | |
#define PG_MAGIC_FUNCTION_NAME Pg_magic_func | |
#define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func" | |
-#define PG_MODULE_MAGIC \ | |
-extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \ | |
-const Pg_magic_struct * \ | |
-PG_MAGIC_FUNCTION_NAME(void) \ | |
-{ \ | |
- static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \ | |
- return &Pg_magic_data; \ | |
-} \ | |
-extern int no_such_variable | |
+//removed for static | |
+#define PG_MODULE_MAGIC extern int no_such_variable | |
/*------------------------------------------------------------------------- | |
-- | |
2.6.3.windows.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment