SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

fsanitize=undefined in parent project causes to link due to missing rtti infos in soci.so #1103

Open MTRNord opened 7 months ago

MTRNord commented 7 months ago

Hi :)

I am using soci in my project via meson (essentially via cmake). In my project, I wanted to use -fsanitize=address,undefined. So far so good. However, while using this with clang++16 I got the following linker errors with soci:

FAILED: persephone 
clang++  -o persephone persephone.p/src_database_database.cpp.o persephone.p/src_utils_config.cpp.o persephone.p/src_utils_json_utils.cpp.o persephone.p/src_utils_utils.cpp.o persephone.p/src_webserver_client_server_api_auth.cpp.o persephone.p/src_webserver_json.cpp.o persephone.p/src_webserver_webserver.cpp.o persephone.p/src_main.cpp.o -flto -fsanitize=address,undefined -Wl,--as-needed -Wl,--allow-shlib-undefined '-Wl,-rpath,$ORIGIN/subprojects/soci-4.0.3' -Wl,-rpath-link,/run/media/marcel/1ac60e61-e5e2-4157-9a7a-830801a3fb0b/projects/persephone/builddir/subprojects/soci-4.0.3 -Wl,--start-group subprojects/soci-4.0.3/libsoci_core.so subprojects/soci-4.0.3/libsoci_postgresql.so subprojects/yaml-cpp-0.8.0/libyaml_cpp.a -pthread /usr/lib64/libssl.so /usr/lib64/libcrypto.so /usr/lib64/libz.so /usr/lib64/libbrotlicommon.so /usr/lib64/libbrotlidec.so /usr/lib64/libbrotlienc.so -Wl,-Bstatic -ldl -Wl,-Bdynamic /usr/lib64/libboost_date_time.so.1.78.0 /usr/lib64/libdl.a -Wl,-Bstatic -Wl,-Bdynamic /usr/lib64/libpq.so -lpq /usr/lib64/libsodium.so -Wl,--end-group
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.20+0x18): undefined reference to `typeinfo for soci::postgresql_session_backend'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.23+0x18): undefined reference to `typeinfo for soci::postgresql_session_backend'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.157+0x18): undefined reference to `typeinfo for soci::details::ref_counted_statement'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.158+0x18): undefined reference to `typeinfo for soci::details::ref_counted_statement'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.193+0x18): undefined reference to `typeinfo for soci::details::ref_counted_statement'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.194+0x18): undefined reference to `typeinfo for soci::details::ref_counted_statement'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.222+0x18): undefined reference to `typeinfo for soci::details::ref_counted_statement'
/usr/bin/ld: /tmp/lto-llvm-c51c3f.o:(.data..Lanon.e2fefa1b5e301ebe1275295b6754704c.223+0x18): more undefined references to `typeinfo for soci::details::ref_counted_statement' follow
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

The sourcecode for this can be found at https://github.com/MTRNord/persephone/tree/291b037e5f57e2eabb0b214509de9c231061e8ea

Relevant in the meson.build is probably only that I disable the boost part and use lto. However, neither seem to make any difference in outcome.

I am targeting c++20 if this matters.

(also sorry if I miss some obvious thing here. I am still fairly new to C++)

The whole project compiled fine if I remove the undefined sanitizer. (Likely because then no RTTI is required)

MTRNord commented 7 months ago

Hm it gets even weirder after I disable the vptr sanitizer. After successful build it fails with further lookup errors:

./persephone: symbol lookup error: /run/media/marcel/1ac60e61-e5e2-4157-9a7a-830801a3fb0b/projects/persephone/builddir/subprojects/soci-4.0.3/libsoci_postgresql.so: undefined symbol: _ZTIN4soci7details21ref_counted_statementE

vadz commented 7 months ago

Sorry, no idea what's going on here but it would definitely be best to compile both SOCI and your project with the same options.

Krzmbrzl commented 4 months ago

@MTRNord could you maybe retry with #1118 ? I have no idea what the exact cause for the behavior you're seeing could be but given that the current cmake setup does have qutie a few quirks and oddities, I wouldn't be surprised if this issue is fixed as a side-effect of my PR.