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

lto=full + address sanitizer results in free/delete errors #121704

Open
Oipo opened this issue Jan 5, 2025 · 0 comments
Open

lto=full + address sanitizer results in free/delete errors #121704

Oipo opened this issue Jan 5, 2025 · 0 comments
Labels
compiler-rt:asan Address sanitizer LTO Link time optimization (regular/full LTO or ThinLTO)

Comments

@Oipo
Copy link

Oipo commented Jan 5, 2025

clang version: 19

When compiling with lto=full and address sanitizer, I get weird errors:

$ ../bin/CoroutineTests
... program executes as normal ...
free(): invalid size
Aborted (core dumped)
$ ../bin/CoroutineTests_sdevent
... program executes as normal ...
munmap_chunk(): invalid pointer
Aborted (core dumped)
$ ../bin/AsyncFileIOTests
... program executes as normal ...
=================================================================
==3074019==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 376 byte(s) in 1 object(s) allocated from:
    #0 0x3f2edd in operator new(unsigned long) crtstuff.c
    #1 0x6473c9 in Catch::Detail::unique_ptr<std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>> Catch::Detail::make_unique<std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>>() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/internal/catch_unique_ptr.hpp:111:30
    #2 0x6473c9 in Catch::StringStreams::add() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_reusable_string_stream.cpp:26:38
    #3 0x6473c9 in Catch::ReusableStringStream::ReusableStringStream() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_reusable_string_stream.cpp:43:57
    #4 0x57dd08 in Catch::TablePrinter::TablePrinter(std::ostream&, std::vector<Catch::ColumnInfo, std::allocator<Catch::ColumnInfo>>) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/reporters/catch_reporter_console.cpp:305:5
    #5 0x57dd08 in Catch::Detail::unique_ptr<Catch::TablePrinter> Catch::Detail::make_unique<Catch::TablePrinter, std::ostream&, std::vector<Catch::ColumnInfo, std::allocator<Catch::ColumnInfo>>>(std::ostream&, std::vector<Catch::ColumnInfo, std::allocator<Catch::ColumnInfo>>&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/internal/catch_unique_ptr.hpp:111:34
    #6 0x57dd08 in Catch::ConsoleReporter::ConsoleReporter(Catch::ReporterConfig&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/reporters/catch_reporter_console.cpp:381:20
    #7 0x63e291 in Catch::Detail::unique_ptr<Catch::ConsoleReporter> Catch::Detail::make_unique<Catch::ConsoleReporter, Catch::ReporterConfig>(Catch::ReporterConfig&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/internal/catch_unique_ptr.hpp:111:34
    #8 0x63e291 in Catch::ReporterFactory<Catch::ConsoleReporter>::create(Catch::ReporterConfig&&) const /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/reporters/catch_reporter_registrars.hpp:48:20
    #9 0x5defab in Catch::ReporterRegistry::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Catch::ReporterConfig&&) const /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_reporter_registry.cpp:62:28
    #10 0x5defab in Catch::(anonymous namespace)::createReporter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Catch::ReporterConfig&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:46:75
    #11 0x5dc174 in Catch::(anonymous namespace)::prepareReporters(Catch::Config const*) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:56:24
    #12 0x5dc174 in Catch::Session::runInternal() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:320:29
    #13 0x5db471 in Catch::Session::run() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:269:24
    #14 0x56ad1b in int Catch::Session::run<char>(int, char const* const*) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/catch_session.hpp:41:30
    #15 0x56ad1b in main /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_main.cpp:36:29
    #16 0x7f0733b8ed8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16

SUMMARY: AddressSanitizer: 376 byte(s) leaked in 1 allocation(s).

All of these errors disappear if I remove either lto or address sanitizer.

Source file compilation:

/usr/bin/clang++-19 -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_SANITIZE_VECTOR -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST -D__SANITIZE_ADDRESS__ -I/home/oipo/Programming/Ichor/external/Catch2/src/catch2/.. -I/home/oipo/Programming/Ichor/build/external/Catch2/generated-includes -O3 -ggdb3 -DNDEBUG -flto=full -ffile-prefix-map=/home/oipo/Programming/Ichor/external/Catch2/= -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=vptr -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -std=c++2b -MD -MT external/Catch2/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_templated.cpp.o -MF external/Catch2/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_templated.cpp.o.d -o external/Catch2/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_templated.cpp.o -c /home/oipo/Programming/Ichor/external/Catch2/src/catch2/matchers/catch_matchers_templated.cpp

Linking:

/usr/bin/clang++-19 -O3 -ggdb3 -DNDEBUG -flto=full   -Wl,--exclude-libs,ALL -fsanitize=address,undefined -no-pie -Wl,-z,nodlopen -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -Wl,--no-copy-dt-needed-entries test/CMakeFiles/AsyncFileIOTests.dir/AsyncFileIOTests.cpp.o -o /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/AsyncFileIOTests  /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/libichor.a  /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/libCatch2Main.a  -lsystemd  -ldl  -lrt  /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/libCatch2.a

I don't really know how to make a minimally reproducible case here, as I can't trigger this without the combination of Catch2 and my source code. If I leave out Catch2, it doesn't trigger either. Please let me know what I could do to improve this report.

@EugeneZelenko EugeneZelenko added compiler-rt:asan Address sanitizer LTO Link time optimization (regular/full LTO or ThinLTO) and removed new issue labels Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:asan Address sanitizer LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

No branches or pull requests

3 participants