ed-o-saurus / PLHaskell

A Haskell extension for PostgreSQL that allows embedded Haskell code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined symbol: VARDATA_ANY when trying to create extension

sqlambda opened this issue · comments

Following the instructions to build a .deb package for debian stable and PostgreSQL 16, I received the error:

daniel=# create extension plhaskell ;
ERROR:  could not load library "/usr/lib/postgresql/16/lib/plhaskell.so": /usr/lib/postgresql/16/lib/plhaskell.so: undefined symbol: VARDATA_ANY

After running make on the source directory, the following output is found:

2024-02-25 19:54:44 daniel@ws01:~/src/PLHaskell $ make
hsc2hs src/PGutils.hsc -I/usr/include/postgresql/16/server
hsc2hs src/PGsupport.hsc -I/usr/include/postgresql/16/server
hsc2hs src/MemoryUtils.hsc -I/usr/include/postgresql/16/server
ghc -Wall -O1 -Werror -optc -Wall -Wno-trustworthy-safe -fforce-recomp -optc -fvisibility=hidden -isrc -c src/MemoryUtils.hs -o src/MemoryUtils.o -dynamic -I/usr/include/postgresql/16/server -fPIC -package-name pgutils-3.1
ghc -Wall -O1 -Werror -optc -Wall -fforce-recomp -optc -fvisibility=hidden -isrc -c src/PGsupport.hs   -o src/PGsupport.o   -dynamic -I/usr/include/postgresql/16/server -fPIC -package-name pgutils-3.1
/tmp/ghc81610_0/ghc_2.c: In function ‘ghczuwrapperZC12ZCpgutilszm3zi1ZCPGsupportZCVARDATAzuANY’:

/tmp/ghc81610_0/ghc_2.c:42:83: error:
     warning: implicit declaration of function ‘VARDATA_ANY’ [-Wimplicit-function-declaration]
       42 | void* ghczuwrapperZC12ZCpgutilszm3zi1ZCPGsupportZCVARDATAzuANY(HsWord a1) {return VARDATA_ANY(a1);}
          |                                                                                   ^~~~~~~~~~~
   |
42 | void* ghczuwrapperZC12ZCpgutilszm3zi1ZCPGsupportZCVARDATAzuANY(HsWord a1) {return VARDATA_ANY(a1);}
   |                                                                                   ^

/tmp/ghc81610_0/ghc_2.c:42:83: error:
     warning: returning ‘int’ from a function with return type ‘void *’ makes pointer from integer without a cast [-Wint-conversion]
       42 | void* ghczuwrapperZC12ZCpgutilszm3zi1ZCPGsupportZCVARDATAzuANY(HsWord a1) {return VARDATA_ANY(a1);}
          |                                                                                   ^~~~~~~~~~~~~~~
   |
42 | void* ghczuwrapperZC12ZCpgutilszm3zi1ZCPGsupportZCVARDATAzuANY(HsWord a1) {return VARDATA_ANY(a1);}
   |                                                                                   ^
/tmp/ghc81610_0/ghc_2.c: In function ‘ghczuwrapperZC13ZCpgutilszm3zi1ZCPGsupportZCSETzuVARSIZZE’:

/tmp/ghc81610_0/ghc_2.c:44:89: error:
     warning: implicit declaration of function ‘SET_VARSIZE’ [-Wimplicit-function-declaration]
       44 | void ghczuwrapperZC13ZCpgutilszm3zi1ZCPGsupportZCSETzuVARSIZZE(HsWord a1, HsWord64 a2) {SET_VARSIZE(a1, a2);}
          |                                                                                         ^~~~~~~~~~~
   |
44 | void ghczuwrapperZC13ZCpgutilszm3zi1ZCPGsupportZCSETzuVARSIZZE(HsWord a1, HsWord64 a2) {SET_VARSIZE(a1, a2);}
   |                                                                                         ^
/tmp/ghc81610_0/ghc_2.c: In function ‘ghczuwrapperZC14ZCpgutilszm3zi1ZCPGsupportZCVARSIZZEzuANYzuEXHDR’:

/tmp/ghc81610_0/ghc_2.c:46:94: error:
     warning: implicit declaration of function ‘VARSIZE_ANY_EXHDR’ [-Wimplicit-function-declaration]
       46 | HsWord64 ghczuwrapperZC14ZCpgutilszm3zi1ZCPGsupportZCVARSIZZEzuANYzuEXHDR(HsWord a1) {return VARSIZE_ANY_EXHDR(a1);}
          |                                                                                              ^~~~~~~~~~~~~~~~~
   |
46 | HsWord64 ghczuwrapperZC14ZCpgutilszm3zi1ZCPGsupportZCVARSIZZEzuANYzuEXHDR(HsWord a1) {return VARSIZE_ANY_EXHDR(a1);}
   |                                                                                              ^
ghc -Wall -O1 -Werror -optc -Wall -fforce-recomp -optc -fvisibility=hidden -isrc -c src/PGutils.hs     -o src/PGutils.o     -dynamic -I/usr/include/postgresql/16/server -fPIC -package-name pgutils-3.1
cp src/PGutils.hi src/PGutils.dyn_hi
cp src/PGsupport.hi src/PGsupport.dyn_hi
hsc2hs src/PLHaskell.hsc -I/usr/include/postgresql/16/server
ghc -Wall -O1 -Werror -optc -Wall -fforce-recomp -optc -fvisibility=hidden -isrc -c src/PLHaskell.hs   -o src/PLHaskell.o   -dynamic -I/usr/include/postgresql/16/server -fPIC -package-name pgutils-3.1
ghc -Wall -O1 -Werror -optc -Wall -fforce-recomp -c src/plhaskell.c -o src/plhaskell.o -I/usr/include/postgresql/16/server -I. -D_GNU_SOURCE -fPIC
ghc -Wall -O1 -Werror -optc -Wall -fforce-recomp src/plhaskell.o src/PLHaskell.o src/PGutils.o src/PGsupport.o src/MemoryUtils.o -o src/plhaskell.so -dynamic -shared -L/usr/lib/ghc/rts -L/usr/lib/haskell-packages/ghc/lib/x86_64-linux-ghc-9.0.2 -L/usr/lib/ghc/text-1.2.5.0 -lHSrts-ghc9.0.2 -lHShint-0.9.0.6-HgKYJTrorOJIGDC8f1M0HL-ghc9.0.2 -lHStext-1.2.5.0-ghc9.0.2 -optl-Wl,-rpath,/usr/lib/ghc/rts:/usr/lib/haskell-packages/ghc/lib/x86_64-linux-ghc-9.0.2:/usr/lib/ghc/text-1.2.5.0
./src/mk_pgutils_conf.sh /usr/lib/postgresql/16/lib > src/pgutils-3.1.conf
touch selinux/plhaskell.pp

I'm not sure what is going on. I'll try to take a look this weekend.

It looks like PostgreSQL 16 moved some code into a different header file. I posted a patch to address this. Try building branch varatt. Let me know if it build and the test files run correctly. If so, I'll merge it into main.

Nice, thank you very much. I was able to compile and it installed. I stumbled into a different issue because my server is configured with lc_messages pt_BR.utf8 and it raises an error when creating functions

ERRO: /lib/x86_64-linux-gnu/libc.so: cabeçalho de ELF inválido

which might be in English something like:

ERROR: /lib/x86_64-linux-gnu/libc.so: invalid ELF header

After changing lc_messages to C, the function is created with success. If I change lc_messages back to pt_BR.utf8 the functions fails to execute with the same error:

daniel=# set lc_messages to default;
SET
daniel=# show lc_messages ;
 lc_messages 
-------------
 pt_BR.utf8
(1 linha)

daniel=# SELECT * FROM primes(100);
ERRO:  /lib/x86_64-linux-gnu/libc.so: cabeçalho de ELF inválido
daniel=# set lc_messages to 'C';
SET
daniel=# SELECT * FROM primes(10);
 n  | p  
----+----
  1 |  2
  2 |  3
  3 |  5
  4 |  7
  5 | 11
  6 | 13
  7 | 17
  8 | 19
  9 | 23
 10 | 29
(10 linhas)

Ah, it works with en_US.utf8:

daniel=# set lc_messages to 'en_US.utf8';
SET
daniel=# SELECT * FROM primes(10);
 n  | p  
----+----
  1 |  2
  2 |  3
  3 |  5
  4 |  7
  5 | 11
  6 | 13
  7 | 17
  8 | 19
  9 | 23
 10 | 29
(10 linhas)

Do you prefer to open a new issue to deal with this?

Thank you again, Haskell and PostgreSQL are a perfect match.

I've merged the branch. I'm going to close this issue. Please create a new one for the other bug.