Обсуждение: Build with meson + clang + sanitizer resulted in undefined reference

Поиск
Список
Период
Сортировка

Build with meson + clang + sanitizer resulted in undefined reference

От
Maxim Orlov
Дата:
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.

Re: Build with meson + clang + sanitizer resulted in undefined reference

От
Dmitry Dolgov
Дата:
> On Thu, Apr 25, 2024 at 06:38:58PM +0300, Maxim Orlov wrote:
>
> 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'

Seems to be a meson quirk [1]. I could reproduce this, and adding
-Db_lundef=false on top of your configuration solved the issue.

[1]: https://github.com/mesonbuild/meson/issues/3853



Re: Build with meson + clang + sanitizer resulted in undefined reference

От
Maxim Orlov
Дата:

On Wed, 1 May 2024 at 00:11, Dmitry Dolgov <9erthalion6@gmail.com> wrote:
Seems to be a meson quirk [1]. I could reproduce this, and adding
-Db_lundef=false on top of your configuration solved the issue.

[1]: https://github.com/mesonbuild/meson/issues/3853
 
Thank you for a reply!  Yes, it seems to be that way.  Many thanks for the clarification.

--
Best regards,
Maxim Orlov.