BUG #18254: could not load library llvmjit.so,Undefined symbol "_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: yangxiaoming2019(at)gmail(dot)com
Subject: BUG #18254: could not load library llvmjit.so,Undefined symbol "_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt
Date: 2023-12-20 10:51:52
Message-ID: 18254-e303b33b2317c861@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18254
Logged by: Xiaoming Yang
Email address: yangxiaoming2019(at)gmail(dot)com
PostgreSQL version: 16.1
Operating system: FreeBSD14
Description:

when I run the sql
```sql
explain analyze select .. from ...;
```

I got the error info
```text
SQL Error [XX000]: ERROR: could not load library
"/usr/local/lib/postgresql/llvmjit.so":
/usr/local/lib/postgresql/llvmjit.so: Undefined symbol
"_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt8optionalINS_5AlignEE"
Where: parallel worker
ERROR: could not load library "/usr/local/lib/postgresql/llvmjit.so":
/usr/local/lib/postgresql/llvmjit.so: Undefined symbol
"_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt8optionalINS_5AlignEE"
Where: parallel worker
ERROR: could not load library "/usr/local/lib/postgresql/llvmjit.so":
/usr/local/lib/postgresql/llvmjit.so: Undefined symbol
"_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt8optionalINS_5AlignEE"
Where: parallel worker
``

I build postgresql on my FreeBSD system, the system & postgresql info:
```text
# build config
./configure --prefix=/usr/local --with-openssl --with-lz4
--with-wal-blocksize=64 --with-blocksize=32 --with-llvm

# uname -a
FreeBSD xxxx 14.0-RELEASE FreeBSD 14.0-RELEASE #0
releng/14.0-n265380-f9716eee8ab4: Fri Nov 10 05:57:23 UTC 2023
root(at)releng1(dot)nyi(dot)freebsd(dot)org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC
amd64

# pg_config
BINDIR = /usr/local/bin
DOCDIR = /usr/local/share/doc/postgresql
HTMLDIR = /usr/local/share/doc/postgresql
INCLUDEDIR = /usr/local/include
PKGINCLUDEDIR = /usr/local/include/postgresql
INCLUDEDIR-SERVER = /usr/local/include/postgresql/server
LIBDIR = /usr/local/lib
PKGLIBDIR = /usr/local/lib/postgresql
LOCALEDIR = /usr/local/share/locale
MANDIR = /usr/local/share/man
SHAREDIR = /usr/local/share/postgresql
SYSCONFDIR = /usr/local/etc/postgresql
PGXS = /usr/local/lib/postgresql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/usr/local' '--with-openssl' '--with-lz4'
'--with-wal-blocksize=64' '--with-blocksize=32' '--with-llvm'
'CFLAGS=-I/usr/local/include/python3.11/' 'LLVM_CONFIG=llvm-config16'
CC = gcc
CPPFLAGS = -I/usr/local/include -I/usr/local/include
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type
-Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv
-fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation
-I/usr/local/include/python3.11/
CFLAGS_SL = -fPIC -DPIC
LDFLAGS = -L/usr/local/llvm16/lib -L/usr/local/lib -Wl,--as-needed
-Wl,-R'/usr/local/lib'
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -llz4 -lssl -lcrypto -lz -lreadline -lpthread
-lexecinfo -lm
VERSION = PostgreSQL 16.1

# llvm-config16 --version
16.0.6

# postgresql.conf
jit_provider = 'llvmjit'
```

Demangle the symbol
`_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt8optionalINS_5AlignEE` is
`llvm::MemoryBuffer::getFile(llvm::Twine const&, bool, bool, bool,
std::optional<llvm::Align>)`

And, I have another PostgreSQL on Rokey 9 Linux, it's work well.
The Linux version info:
```text
# uname -a
Linux xxx 5.14.0-362.8.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 8
17:36:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

# build config
./configure --with-openssl --with-zstd -with-lz4 --with-systemd
--with-python --with-llvm

# postgresql.conf
jit_provider = 'llvmjit'
# pg_config
BINDIR = /usr/local/bin
DOCDIR = /usr/local/share/doc/postgresql
HTMLDIR = /usr/local/share/doc/postgresql
INCLUDEDIR = /usr/local/include
PKGINCLUDEDIR = /usr/local/include/postgresql
INCLUDEDIR-SERVER = /usr/local/include/postgresql/server
LIBDIR = /usr/local/lib
PKGLIBDIR = /usr/local/lib/postgresql
LOCALEDIR = /usr/local/share/locale
MANDIR = /usr/local/share/man
SHAREDIR = /usr/local/share/postgresql
SYSCONFDIR = /usr/local/etc/postgresql
PGXS = /usr/local/lib/postgresql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/usr/local' '--with-openssl' '-with-lz4'
'--with-systemd' '--with-python' '--with-llvm'
CC = gcc
CPPFLAGS = -D_GNU_SOURCE
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type
-Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv
-fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation
-O2
CFLAGS_SL = -fPIC
LDFLAGS = -L/usr/lib64 -Wl,--as-needed
-Wl,-rpath,'/usr/local/lib',--enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -llz4 -lssl -lcrypto -lz -ledit -lm
VERSION = PostgreSQL 16.1

# llvm-config --version
16.0.6

# postgresql.conf
jit_provider = 'llvmjit'
```

Linux Version run out:
```text
-- some info

Planning Time: 1.596 ms
JIT:
Functions: 75
Options: Inlining true, Optimization true, Expressions true, Deforming
true
Timing: Generation 2.626 ms, Inlining 221.238 ms, Optimization 161.173
ms, Emission 132.760 ms, Total 517.797 ms
Execution Time: 1416.203 ms
```

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Munro 2023-12-20 21:02:58 Re: BUG #18254: could not load library llvmjit.so,Undefined symbol "_ZN4llvm12MemoryBuffer7getFileERKNS_5TwineEbbbSt
Previous Message PG Bug reporting form 2023-12-20 08:51:34 BUG #18253: aarch64 oel 7 repomd.xml: [Errno 14] HTTPS Error 404