babelfish-for-postgresql / babelfish_extensions

Babelfish for PostgreSQL provides the capability for PostgreSQL to work with applications written for Microsoft SQL Server. Babelfish understands the SQL Server wire-protocol and T-SQL, the Microsoft SQL Server query and procedural language, so you don’t have to switch database drivers or rewrite all of your application queries.
https://babelfishpg.org/
Apache License 2.0
277 stars 93 forks source link

Could not compile extensions with LLVM #2423

Open japinli opened 7 months ago

japinli commented 7 months ago

Hi,

When I tried to compile babelfish_extensions with LLVM, the babelfishpg_tsql could not compiled. Here is a patch to fix the compile errors.

diff --git a/contrib/babelfishpg_tsql/Makefile b/contrib/babelfishpg_tsql/Makefile
index f2ef072a..82abbdd1 100644
--- a/contrib/babelfishpg_tsql/Makefile
+++ b/contrib/babelfishpg_tsql/Makefile
@@ -88,9 +88,9 @@ PG_CXXFLAGS += -g -Werror -Wfloat-conversion
 PG_CXXFLAGS += -Wno-deprecated -Wno-error=attributes -Wno-suggest-attribute=format # disable some warnings from ANTLR runtime header
 PG_CXXFLAGS += -Wno-undef -Wall -Wcpp
 PG_CXXFLAGS += -Wno-register # otherwise C++17 gags on PostgreSQL headers
-PG_CXXFLAGS += -I$(ANTLR4_RUNTIME_INCLUDE_DIR)
 PG_CFLAGS += -g -Werror -Wfloat-conversion
 PG_CFLAGS += -fstack-protector-strong
+PG_CPPFLAGS += -I$(ANTLR4_RUNTIME_INCLUDE_DIR)
 PG_CPPFLAGS += -I$(TSQLSRC) -I$(PG_SRC) -DFAULT_INJECTOR -Wfloat-conversion

 SHLIB_LINK += -L$(ANTLR4_RUNTIME_LIB_DIR) $(ANTLR4_RUNTIME_LIB) -lcrypto
diff --git a/contrib/babelfishpg_tsql/src/backend_parser/parser.c b/contrib/babelfishpg_tsql/src/backend_parser/parser.c
index 37db5620..0420cc6e 100644
--- a/contrib/babelfishpg_tsql/src/backend_parser/parser.c
+++ b/contrib/babelfishpg_tsql/src/backend_parser/parser.c
@@ -29,8 +29,6 @@
 #include "src/pltsql.h"
 #include "tcop/tcopprot.h"

-int            pgtsql_base_yydebug;
-
 List      *babelfishpg_tsql_raw_parser(const char *str, RawParseMode mode);

 /*
diff --git a/contrib/babelfishpg_tsql/src/pl_comp.c b/contrib/babelfishpg_tsql/src/pl_comp.c
index ba0ff829..5f38b861 100644
--- a/contrib/babelfishpg_tsql/src/pl_comp.c
+++ b/contrib/babelfishpg_tsql/src/pl_comp.c
@@ -62,9 +62,6 @@ bool      pltsql_DumpExecTree = false;
 bool       pltsql_check_syntax = false;

 PLtsql_function *pltsql_curr_compile;
-int            pltsql_curr_compile_body_lineno;    /* lineno of
-                                                * function/procedure body in
-                                                * CREATE */

 /* A context appropriate for short-term allocs during compilation */
 MemoryContext pltsql_compile_tmp_cxt;

However, it still failed when installing the extension.

cd '/home/japin/babelfish/pg/lib/postgresql/bitcode' && /usr/lib/llvm-12/bin/llvm-lto -thinlto -thinlto-action=thinlink -o babelfishpg_tsql.index.bc babelfishpg_tsql/src/pl_gram.bc babelfishpg_tsql/src/pl_handler.bc babelfishpg_tsql/src/pl_comp.bc babelfishpg_tsql/src/pl_exec.bc babelfishpg_tsql/src/pl_funcs.bc babelfishpg_tsql/src/pl_scanner.bc babelfishpg_tsql/src/pl_comp-2.bc babelfishpg_tsql/src/pl_explain.bc babelfishpg_tsql/src/properties.bc babelfishpg_tsql/src/databasepropertyex.bc babelfishpg_tsql/src/plan_inval.bc babelfishpg_tsql/src/procedures.bc babelfishpg_tsql/src/cursor.bc babelfishpg_tsql/src/applock.bc babelfishpg_tsql/src/pltsql_coerce.bc babelfishpg_tsql/runtime/functions.bc babelfishpg_tsql/src/err_handler.bc babelfishpg_tsql/src/pltsql_function_probin_handler.bc babelfishpg_tsql/src/pltsql_utils.bc babelfishpg_tsql/src/tablecmds.bc babelfishpg_tsql/src/stmt_walker.bc babelfishpg_tsql/src/codegen.bc babelfishpg_tsql/src/dynavec.bc babelfishpg_tsql/src/dynastack.bc babelfishpg_tsql/src/analyzer.bc babelfishpg_tsql/src/prepare.bc babelfishpg_tsql/src/compile_context.bc babelfishpg_tsql/src/collation.bc babelfishpg_tsql/src/string.bc babelfishpg_tsql/src/format.bc babelfishpg_tsql/src/pltsql_identity.bc babelfishpg_tsql/src/collationproperty.bc babelfishpg_tsql/src/rolecmds.bc babelfishpg_tsql/src/backend_parser/keywords.bc babelfishpg_tsql/src/backend_parser/parser.bc babelfishpg_tsql/src/backend_parser/scan-backend.bc babelfishpg_tsql/src/backend_parser/gram-backend.bc babelfishpg_tsql/src/backend_parser/gram_hook.bc babelfishpg_tsql/src/dbcmds.bc babelfishpg_tsql/src/session.bc babelfishpg_tsql/src/guc.bc babelfishpg_tsql/src/catalog.bc babelfishpg_tsql/src/schemacmds.bc babelfishpg_tsql/src/hooks.bc babelfishpg_tsql/src/tsqlNodes.bc babelfishpg_tsql/src/tsqlHandler.bc babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.bc babelfishpg_tsql/src/tsqlIface.bc babelfishpg_tsql/src/special_keywords.bc babelfishpg_tsql/antlr/libantlr_tsql.a babelfishpg_tsql/src/multidb.bc babelfishpg_tsql/src/json_funcs.bc babelfishpg_tsql/src/pltsql_ruleutils.bc babelfishpg_tsql/src/tsql_for/tsql_for.bc babelfishpg_tsql/src/tsql_for/forjson.bc babelfishpg_tsql/src/tsql_for/forjson_old.bc babelfishpg_tsql/src/tsql_for/forxml.bc babelfishpg_tsql/src/tsql_for/forxml_old.bc babelfishpg_tsql/src/tsql_analyze.bc babelfishpg_tsql/src/linked_servers.bc babelfishpg_tsql/src/table_variable_mvcc.bc babelfishpg_tsql/src/extendedproperty.bc babelfishpg_tsql/src/fts.bc babelfishpg_tsql/src/fts_parser.bc babelfishpg_tsql/src/pltsql_bulkcopy.bc
LLVM ERROR: ThinLTO cannot create input file: The file was not recognized as a valid object file
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /usr/lib/llvm-12/bin/llvm-lto -thinlto -thinlto-action=thinlink -o babelfishpg_tsql.index.bc babelfishpg_tsql/src/pl_gram.bc babelfishpg_tsql/src/pl_handler.bc babelfishpg_tsql/src/pl_comp.bc babelfishpg_tsql/src/pl_exec.bc babelfishpg_tsql/src/pl_funcs.bc babelfishpg_tsql/src/pl_scanner.bc babelfishpg_tsql/src/pl_comp-2.bc babelfishpg_tsql/src/pl_explain.bc babelfishpg_tsql/src/properties.bc babelfishpg_tsql/src/databasepropertyex.bc babelfishpg_tsql/src/plan_inval.bc babelfishpg_tsql/src/procedures.bc babelfishpg_tsql/src/cursor.bc babelfishpg_tsql/src/applock.bc babelfishpg_tsql/src/pltsql_coerce.bc babelfishpg_tsql/runtime/functions.bc babelfishpg_tsql/src/err_handler.bc babelfishpg_tsql/src/pltsql_function_probin_handler.bc babelfishpg_tsql/src/pltsql_utils.bc babelfishpg_tsql/src/tablecmds.bc babelfishpg_tsql/src/stmt_walker.bc babelfishpg_tsql/src/codegen.bc babelfishpg_tsql/src/dynavec.bc babelfishpg_tsql/src/dynastack.bc babelfishpg_tsql/src/analyzer.bc babelfishpg_tsql/src/prepare.bc babelfishpg_tsql/src/compile_context.bc babelfishpg_tsql/src/collation.bc babelfishpg_tsql/src/string.bc babelfishpg_tsql/src/format.bc babelfishpg_tsql/src/pltsql_identity.bc babelfishpg_tsql/src/collationproperty.bc babelfishpg_tsql/src/rolecmds.bc babelfishpg_tsql/src/backend_parser/keywords.bc babelfishpg_tsql/src/backend_parser/parser.bc babelfishpg_tsql/src/backend_parser/scan-backend.bc babelfishpg_tsql/src/backend_parser/gram-backend.bc babelfishpg_tsql/src/backend_parser/gram_hook.bc babelfishpg_tsql/src/dbcmds.bc babelfishpg_tsql/src/session.bc babelfishpg_tsql/src/guc.bc babelfishpg_tsql/src/catalog.bc babelfishpg_tsql/src/schemacmds.bc babelfishpg_tsql/src/hooks.bc babelfishpg_tsql/src/tsqlNodes.bc babelfishpg_tsql/src/tsqlHandler.bc babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.bc babelfishpg_tsql/src/tsqlIface.bc babelfishpg_tsql/src/special_keywords.bc babelfishpg_tsql/antlr/libantlr_tsql.a babelfishpg_tsql/src/multidb.bc babelfishpg_tsql/src/json_funcs.bc babelfishpg_tsql/src/pltsql_ruleutils.bc babelfishpg_tsql/src/tsql_for/tsql_for.bc babelfishpg_tsql/src/tsql_for/forjson.bc babelfishpg_tsql/src/tsql_for/forjson_old.bc babelfishpg_tsql/src/tsql_for/forxml.bc babelfishpg_tsql/src/tsql_for/forxml_old.bc babelfishpg_tsql/src/tsql_analyze.bc babelfishpg_tsql/src/linked_servers.bc babelfishpg_tsql/src/table_variable_mvcc.bc babelfishpg_tsql/src/extendedproperty.bc babelfishpg_tsql/src/fts.bc babelfishpg_tsql/src/fts_parser.bc babelfishpg_tsql/src/pltsql_bulkcopy.bc
 #0 0x00007f18f55732a1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xd732a1)
 #1 0x00007f18f55713d0 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xd713d0)
 #2 0x00007f18f55739ad (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xd739ad)
 #3 0x00007f18f4042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f18f40969fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x00007f18f40969fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #6 0x00007f18f40969fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #7 0x00007f18f4042476 raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f18f40287f3 abort ./stdlib/./stdlib/abort.c:81:7
 #9 0x00007f18f54cda8d (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xccda8d)
#10 0x00007f18f54cdaa7 (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xccdaa7)
#11 0x00007f18f67d15f3 llvm::ThinLTOCodeGenerator::addModule(llvm::StringRef, llvm::StringRef) (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x1fd15f3)
#12 0x000000000041327b (/usr/lib/llvm-12/bin/llvm-lto+0x41327b)
#13 0x000000000040d7ca (/usr/lib/llvm-12/bin/llvm-lto+0x40d7ca)
#14 0x00007f18f4029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#15 0x00007f18f4029e40 call_init ./csu/../csu/libc-start.c:128:20
#16 0x00007f18f4029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#17 0x000000000040b1f5 (/usr/lib/llvm-12/bin/llvm-lto+0x40b1f5)
Aborted
make: *** [/home/japin/babelfish/pg/lib/postgresql/pgxs/src/makefiles/pgxs.mk:241: install] Error 134
jmbit commented 7 months ago

the first patch is also needed when compiling using gcc 11.4.0 on ubuntu 22.04.

japinli commented 7 months ago

the first patch is also needed when compiling using gcc 11.4.0 on ubuntu 22.04.

Thanks for your review. Create a new PR #2434.