diff --git a/.buildconfig b/.buildconfig index 203f80fa..5d5919e5 100644 --- a/.buildconfig +++ b/.buildconfig @@ -1,2 +1,2 @@ PG_VERSION=16.4 -SDK_VERSION=3.1.68.0bi +SDK_VERSION=3.1.68.1bi diff --git a/cibuild/linkwasi.sh b/cibuild/linkwasi.sh index 6ac4199b..07f5153d 100755 --- a/cibuild/linkwasi.sh +++ b/cibuild/linkwasi.sh @@ -770,19 +770,24 @@ llvm-ar cr ../../libpglite.a $PGOBJ # just linking + + $CC -o postgres \ - -O2 -g0 main/main.o \ - ../../libpglite.a \ + -fno-strict-aliasing \ + -fwrapv \ + \ + -O2 ../../src/common/libpgcommon_srv.a ../../src/port/libpgport_srv.a \ + \ + ../../libpglite.a main/main.o ../../wasi_dlfcn.o \ \ - ../../src/common/libpgcommon_srv.a \ - ../../src/port/libpgport_srv.a \ - ../../wasi_dlfcn.o \ ../../src/backend/snowball/libdict_snowball.a \ ../../src/pl/plpgsql/src/libplpgsql.a \ -lz -lm -lwasi-emulated-mman -lwasi-emulated-signal -lc \ -Wl,--export=pg_initdb \ -Wl,--export=interactive_one \ -Wl,--export=use_socketfile \ + -Wl,--export=interactive_write \ + -Wl,--export=interactive_read -Wl,--global-base=33554432 cp -vf postgres postgres.wasi || exit 192 diff --git a/patches/imports/plpgsql b/patches/imports/plpgsql index 8037e742..aed9b9d4 100644 --- a/patches/imports/plpgsql +++ b/patches/imports/plpgsql @@ -1,3 +1,6 @@ +___stack_pointer +___memory_base +___table_base _SearchSysCache1 _errstart_cold _errmsg_internal @@ -105,28 +108,10 @@ _SPI_copytuple _expanded_record_lookup_field _FreeExecutorState _ResourceOwnerReleaseAllPlanCacheRefs -_invoke_vi -___wasm_setjmp_test -_setTempRet0 -_getTempRet0 -_invoke_viiiiii -_invoke_viii -_invoke_viiii -_invoke_iiiiii -_invoke_iii -_invoke_ii -___wasm_setjmp +_BeginInternalSubTransaction _get_typlenbyval _datumTransfer -_invoke_iiii -_invoke_v -_invoke_i -_ReThrowError -_unpack_sql_state -_cstring_to_text -_invoke_viiiii -_MemoryContextGetParent -_emscripten_longjmp +_ReleaseCurrentSubTransaction _CreateExecutorState _ResourceOwnerCreate _CreateExprContext @@ -134,6 +119,8 @@ _GetCurrentSubTransactionId _SPI_plan_get_plan_sources _SPI_execute_plan_extended _SPI_result_code_string +_cstring_to_text +_unpack_sql_state _GetErrorContextStack _Int64GetDatum _SPI_cursor_close @@ -143,6 +130,7 @@ _get_element_type _pg_detoast_datum_copy _array_create_iterator _array_iterate +_MemoryContextGetParent _MakeExpandedObjectReadOnlyInternal _tuplestore_putvalues _tuplestore_puttuple @@ -163,6 +151,7 @@ _SPI_commit_and_chain _SPI_commit _SPI_rollback_and_chain _SPI_rollback +_ReThrowError _err_generic_string _SPI_prepare_extended _SPI_keepplan @@ -208,9 +197,9 @@ _SPI_freeplan _MemoryContextDelete _pg_printf _fflush +_list_free _get_collation_oid _memmove -_list_free _typeStringToTypeName _raw_parser _quote_identifier @@ -230,12 +219,11 @@ _RegisterSubXactCallback _find_rendezvous_variable _pg_strcasecmp _SplitIdentifierString -___errno_location _pre_format_elog_string _format_elog_string _guc_malloc -_invoke_vii -_invoke_iiiiiii +_SPI_connect_ext +_ResourceOwnerDelete _SPI_finish _CheckFunctionValidatorAccess _get_typtype @@ -248,9 +236,6 @@ _internalerrquery _strchr _scanner_init _scanner_finish -___stack_pointer -___memory_base -___table_base _error_context_stack _TopMemoryContext _CurrentMemoryContext @@ -258,15 +243,7 @@ _check_function_bodies _InterruptPending _CurrentResourceOwner _plpgsql_parser_setup -___THREW__ -___threwValue -_BeginInternalSubTransaction _PG_exception_stack -_ReleaseCurrentSubTransaction -_CopyErrorData -_FlushErrorState -_RollbackAndReleaseCurrentSubTransaction -_MemoryContextDeleteChildren _MyProc _TopTransactionContext _TopTransactionResourceOwner @@ -276,8 +253,5 @@ _SPI_result _namein _work_mem _stdout +_errno _GUC_check_errdetail_string -_SPI_connect_ext -_plpgsql_compile -_ResourceOwnerDelete -_pg_re_throw diff --git a/patches/interactive_one.c b/patches/interactive_one.c index 5c246ed5..313a3155 100644 --- a/patches/interactive_one.c +++ b/patches/interactive_one.c @@ -208,7 +208,7 @@ interactive_one() { } - } // is_node + } // is_node && is_repl doing_extended_query_message = false; @@ -362,7 +362,7 @@ printf("# 352 : node+repl is wire : %c\n", firstchar); } // ok lck - } // is_node + is_repl + } // is_node && is_repl if (cma_rsize) { PDEBUG("wire message in cma buffer !"); diff --git a/patches/postgresql-wasm-16.4/src-backend-utils-fmgr-dfmgr.c.diff b/patches/postgresql-wasm-16.4/src-backend-utils-fmgr-dfmgr.c.diff new file mode 100644 index 00000000..33611068 --- /dev/null +++ b/patches/postgresql-wasm-16.4/src-backend-utils-fmgr-dfmgr.c.diff @@ -0,0 +1,19 @@ +--- postgresql/src/backend/utils/fmgr/dfmgr.c ++++ postgresql-wasm/src/backend/utils/fmgr/dfmgr.c +@@ -121,12 +121,15 @@ + + /* Look up the function within the library. */ + retval = dlsym(lib_handle, funcname); +- ++#if !defined(__wasi__) + if (retval == NULL && signalNotFound) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_FUNCTION), + errmsg("could not find function \"%s\" in file \"%s\"", + funcname, fullname))); ++#else ++ fprintf(stderr, "could not find function \"%s\" in file \"%s\" rv=%p snf=%b\n", funcname, fullname, retval, signalNotFound); ++#endif + + pfree(fullname); + return retval; diff --git a/patches/postgresql-wasm/src-include-port-wasi.h.diff b/patches/postgresql-wasm/src-include-port-wasi.h.diff index 0bd807ff..5df273e5 100644 --- a/patches/postgresql-wasm/src-include-port-wasi.h.diff +++ b/patches/postgresql-wasm/src-include-port-wasi.h.diff @@ -1,6 +1,6 @@ --- postgresql/src/include/port/wasi.h +++ postgresql-wasm/src/include/port/wasi.h -@@ -0,0 +1,271 @@ +@@ -0,0 +1,245 @@ +#ifndef I_WASI +#define I_WASI + @@ -181,7 +181,7 @@ + +static int +semget(key_t key, int nsems, int semflg) { -+#if PGDEBUG ++#if 0 // PGDEBUG + printf("# 213: semget(key_t key = %d, int nsems=%d, int semflg=%d)\n", key, nsems, semflg); +#endif + return 1; @@ -194,29 +194,8 @@ + + + -+ -+ -+ -+ -+ +#include -+/* -+static void * -+mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { -+#if PGDEBUG -+ printf("# 227: mmap(void* %p, size_t length=%d, int prot=%d, int flags=%d, int fd=%d, off_t offset=%d)\n", addr, length,prot,flags,fd,offset); -+#endif -+ return NULL; -+ -+} -+ -+static int -+munmap(void *addr, size_t length) { -+ puts("# 228: munmap"); -+ return 0; -+} + -+*/ +static int +shm_open(const char *name, int oflag, mode_t mode) { + char tmpnam[128]; @@ -258,11 +237,6 @@ + puts("# 259: tzset(void) STUB"); +} + -+ -+// HACK TODO FIXME ! -+ -+// #define getpwuid(...) (NULL) -+ +#if defined(PG_INITDB) || defined(FE_UTILS_PRINT) || defined(PG_DUMP_PARALLEL) +static void +__SIG_IGN(int param) { diff --git a/patches/wasi_dlfcn.c b/patches/wasi_dlfcn.c index f2a4a433..44dac9e5 100644 --- a/patches/wasi_dlfcn.c +++ b/patches/wasi_dlfcn.c @@ -151,9 +151,10 @@ dlopen(const char *filename, int flags) { void * dlsym(void *__restrict handle, const char *__restrict symbol) { void *sym = NULL; - if ( !strcmp(symbol, "Pg_magic_func") ) - //sym = &STUB_Pg_magic_func; - return &STUB_Pg_magic_func; + if ( !strcmp(symbol, "Pg_magic_func") ) { + sym = &STUB_Pg_magic_func; + goto report; + } if ( !strcmp(symbol, "_PG_init") ) // sym = &STUB__PG_init; @@ -185,10 +186,11 @@ dlsym(void *__restrict handle, const char *__restrict symbol) { return &plpgsql_inline_handler; if ( !strcmp(symbol, "plpgsql_validator") ) { - return &plpgsql_validator; + sym = &plpgsql_validator; + goto report; } - +report:; fprintf(stderr, "void *dlsym(void *handle = %p, const char *symbol = %s) => %p\n", handle, symbol, sym); return sym; } diff --git a/patches/wasi_port.c b/patches/wasi_port.c index 2e8dfbd8..9c14ee23 100644 --- a/patches/wasi_port.c +++ b/patches/wasi_port.c @@ -112,7 +112,7 @@ sigemptyset(sigset_t *set) { int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { - puts("# 96: sigaction 0"); + puts("# 96: sigaction STUB"); return 0; }