Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MTRNord opened this issue Nov 30, 2023 · 4 comments
Labels

Comments

@MTRNord
Copy link

MTRNord commented Nov 30, 2023

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
Copy link
Author

MTRNord commented Nov 30, 2023

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
Copy link
Member

vadz commented Nov 30, 2023

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.

@vadz vadz added the CMake label Nov 30, 2023
@Krzmbrzl
Copy link
Contributor

@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.

vadz added a commit to vadz/soci that referenced this issue Oct 16, 2024
Export all session_backend-derived classes as they can be used in the
application code, and some of them were actually used in our own tests.

Also export ref_counted_prepare_info and ref_counted_statement classes
to make their type info information accessible from outside the library:
this is needed at least when UBSAN and, more precisely, its vtbl
sanitizer, is used, as it uses typeinfo.

Closes SOCI#1103.
@vadz
Copy link
Member

vadz commented Oct 16, 2024

This was actually due to UBSAN vtbl sanitizer which really needs typeinfo to be accessible, so I've fixed it in the commit linked above now and the problem will be fixed once #1172 is merged.

@vadz vadz closed this as completed in d784785 Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants