From: | Maxim Orlov <orlovmg(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Build with meson + clang + sanitizer resulted in undefined reference |
Date: | 2024-04-25 15:38:58 |
Message-ID: | CACG=ezY3WuUTVycW=0-2CTkj3BaoKrBZY2CqbxKKwc3QDTG-CA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi!
Recently, I'm stumbled in such an easy task as build Postgres with clang
and
sanitizer.
Usually, I use autotools to build Postgres something like this:
================================================================================
SRC="../postgres"
TRG="/tmp"
LINUX_CONFIGURE_FEATURES="
--without-llvm
--with-tcl --with-tclconfig=/usr/lib/tcl8.6/ --with-perl
--with-python --with-gssapi --with-pam --with-ldap --with-selinux
--with-systemd --with-uuid=ossp --with-libxml --with-libxslt --with-zstd
--with-ssl=openssl
"
CC="ccache clang" CXX="ccache clang++" \
CFLAGS="-Og -ggdb -fno-sanitize-recover=all -fsanitize=alignment,undefined"
\
CXXFLAGS="-Og -ggdb -fno-sanitize-recover=all
-fsanitize=alignment,undefined" \
LDFALGS="-fsanitize=alignment,undefined" \
\
$SRC/configure \
-C \
--prefix=$TRG/"pgsql" \
--enable-debug --enable-tap-tests --enable-depend --enable-cassert \
--enable-injection-points --enable-nls \
$LINUX_CONFIGURE_FEATURES
...
$ ./config.status --config
'-C' '--prefix=/tmp/pgsql' '--enable-debug' '--enable-tap-tests'
'--enable-depend'
'--enable-cassert' '--enable-injection-points' '--enable-nls'
'--without-llvm'
'--with-tcl' '--with-tclconfig=/usr/lib/tcl8.6/' '--with-perl'
'--with-python'
'--with-gssapi' '--with-pam' '--with-ldap' '--with-selinux'
'--with-systemd'
'--with-uuid=ossp' '--with-libxml' '--with-libxslt' '--with-zstd'
'--with-ssl=openssl'
'CC=ccache clang'
'CFLAGS=-Og -ggdb -fno-sanitize-recover=all -fsanitize=alignment,undefined'
'CXX=ccache clang++'
'CXXFLAGS=-Og -ggdb -fno-sanitize-recover=all
-fsanitize=alignment,undefined'
================================================================================
Then it compiles with no problems.
Now I exact the same, but with meson build.
================================================================================
LINUX_CONFIGURE_FEATURES="
--with-gssapi --with-icu --with-ldap --with-libxml --with-libxslt
--with-lz4 --with-zstd --with-pam --with-perl --with-python
--with-tcl --with-tclconfig=/usr/lib/tcl8.6
--with-selinux --with-sll=openssl --with-systemd --with-uuid=ossp
"
LINUX_MESON_FEATURES="-Dllvm=disabled -Duuid=e2fs"
PG_TEST_EXTRA="kerberos ldap ssl libpq_encryption load_balance"
SANITIZER_FLAGS="-fsanitize=alignment,undefined" \
CC="ccache clang" \
CXX="ccache clang++" \
CFLAGS="-Og -ggdb -fno-sanitize-recover=all $SANITIZER_FLAGS" \
CXXFLAGS="$CFLAGS" \
LDFALGS="$SANITIZER_FLAGS" \
meson setup \
--buildtype=debug -Dcassert=true -Dinjection_points=true \
-Dprefix=/tmp/pgsql \
${LINUX_MESON_FEATURES} \
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
build-meson postgres
...
System
host system : linux x86_64
build system : linux x86_64
Compiler
linker : ld.bfd
C compiler : clang 14.0.0-1ubuntu1
Compiler Flags
CPP FLAGS : -D_GNU_SOURCE
C FLAGS, functional : -fno-strict-aliasing -fwrapv
C FLAGS, warnings : -Wmissing-prototypes -Wpointer-arith
-Werror=vla
-Werror=unguarded-availability-new -Wendif-labels
-Wmissing-format-attribute
-Wcast-function-type -Wformat-security -Wdeclaration-after-statement
-Wno-unused-command-line-argument -Wno-compound-token-split-by-macro
C FLAGS, modules : -fvisibility=hidden
C FLAGS, user specified: -Og -ggdb -fno-sanitize-recover=all
-fsanitize=alignment,undefined
LD FLAGS : -Og -ggdb -fno-sanitize-recover=all
-fsanitize=alignment,undefined
...
================================================================================
And then upon build I've got overwhelmed by thousands of undefined
reference errors.
fe-auth-scram.c:(.text+0x17a): undefined reference to
`__ubsan_handle_builtin_unreachable'
/usr/bin/ld: fe-auth-scram.c:(.text+0x189): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x195): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x1a1): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x1ad): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x1b9): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld:
src/interfaces/libpq/libpq.so.5.17.p/fe-auth-scram.c.o:fe-auth-scram.c:(.text+0x1c8):
more undefined references to `__ubsan_handle_type_mismatch_v1_abort' follow
/usr/bin/ld: src/interfaces/libpq/libpq.so.5.17.p/fe-auth-scram.c.o: in
function `scram_init':
fe-auth-scram.c:(.text+0x1d4): undefined reference to
`__ubsan_handle_nonnull_arg_abort'
/usr/bin/ld: src/interfaces/libpq/libpq.so.5.17.p/fe-auth-scram.c.o: in
function `scram_exchange':
fe-auth-scram.c:(.text+0x11c2): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x11d1): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x11e0): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x11ef): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld: fe-auth-scram.c:(.text+0x11fe): undefined reference to
`__ubsan_handle_type_mismatch_v1_abort'
/usr/bin/ld:
src/interfaces/libpq/libpq.so.5.17.p/fe-auth-scram.c.o:fe-auth-scram.c:(.text+0x120d):
more undefined references to `__ubsan_handle_type_mismatch_v1_abort' follow
/usr/bin/ld: src/interfaces/libpq/libpq.so.5.17.p/fe-auth-scram.c.o: in
function `scram_exchange':
...
many many many more
...
My OS info:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
Previously, I've got the same troubles on my old trusty 32-bit laptop on
Debian. But, there was no time to dig deeper in the problem
at the time. And now same for 64-bit Ubuntu. The most common reason for
such errors are not passing appropriate sanitizer
flags to LDFLAGS, but this is not the case. What could be the reason for
this? Am I doin' something wrong?
Exact the same sequence, but for GCC, works splendidly.
--
Best regards,
Maxim Orlov.
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2024-04-25 15:48:05 | Re: some additional (small) problems with pg_combinebackup and tablespaces |
Previous Message | Nathan Bossart | 2024-04-25 15:30:58 | Re: New GUC autovacuum_max_threshold ? |