[clang] [compiler-rt] [driver] Fix sanitizer libc++ runtime linking (PR #120370)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 00:51:04 PST 2024


mstorsjo wrote:

This was reverted, because https://github.com/llvm/llvm-project/blob/main/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp in libc++ started passing unexpectedly.

I'm not entirely sure about why that is though - previously, it used to fail like this:
```
/home/martin/clang-trunk/bin/clang++ /home/martin/code/llvm-project/libcxx/test/
libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp -pthread --targ
et=x86_64-unknown-linux-gnu -g -fno-omit-frame-pointer -fsanitize=address -nostd
inc++ -I /home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/test-suit
e-install/include/c++/v1 -I /home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/test-suite-install/include/c++/v1 -I /home/martin/code/llvm-project/li
bcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wsh
adow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes
 -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-mo
dule-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-liter
als -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-paramete
r -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wn
o-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-del
ete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_
LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE 
-Werror=thread-safety -Wuser-defined-warnings  -lc++experimental -nostdlib++ -L 
/home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/test-suite-install
/lib -Wl,-rpath,/home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/te
st-suite-install/lib -lc++ -latomic -o /home/martin/code/llvm-project/build-libc
xx-sanitizers/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe -faligned-allocation -fsized-deallocation
# executed command: /home/martin/clang-trunk/bin/clang++ /home/martin/code/llvm-
project/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh
.cpp -pthread --target=x86_64-unknown-linux-gnu -g -fno-omit-frame-pointer -fsan
itize=address -nostdinc++ -I /home/martin/code/llvm-project/build-libcxx-sanitiz
ers/libcxx/test-suite-install/include/c++/v1 -I /home/martin/code/llvm-project/b
uild-libcxx-sanitizers/libcxx/test-suite-install/include/c++/v1 -I /home/martin/
code/llvm-project/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsu
pported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argu
ment -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignm
ent -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wn
o-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variab
le -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-ty
pe-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wn
o-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAG
MA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_
HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -lc++experimen
tal -nostdlib++ -L /home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx
/test-suite-install/lib -Wl,-rpath,/home/martin/code/llvm-project/build-libcxx-s
anitizers/libcxx/test-suite-install/lib -lc++ -latomic -o /home/martin/code/llvm
-project/build-libcxx-sanitizers/libcxx/test/libcxx/language.support/support.dyn
amic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe -faligned-allocation -fsized-deallocation
# RUN: at line 25
/usr/bin/python3 /home/martin/code/llvm-project/libcxx/utils/run.py --execdir /h
ome/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/test/libcxx/language
.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir --  /home/martin/co
de/llvm-project/build-libcxx-sanitizers/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe
# executed command: /usr/bin/python3 /home/martin/code/llvm-project/libcxx/utils
/run.py --execdir /home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/
test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir
 -- /home/martin/code/llvm-project/build-libcxx-sanitizers/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe
# .---command stderr------------
# | =================================================================
# | ==2987905==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new vs free) on 0x6d15b6e20010
# |     #0 0x5b56d8dee976  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0xcf976)
# |     #1 0x5b56d8e34578  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x115578)
# |     #2 0x5b56d8e34c0c  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x115c0c)
# |     #3 0x5b56d8e34e3f  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x115e3f)
# |     #4 0x70f5b7c2a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
# |     #5 0x70f5b7c2a28a  (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
# |     #6 0x5b56d8d4c3d4  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x2d3d4)
# |
# | 0x6d15b6e20010 is located 0 bytes inside of 4-byte region [0x6d15b6e20010,0x6d15b6e20014)
# | allocated by thread T0 here:
# |     #0 0x5b56d8e3205d  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x11305d)
# |     #1 0x5b56d8e34b76  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x115b76)
# |     #2 0x5b56d8e34e3f  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x115e3f)
# |     #3 0x70f5b7c2a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
# |     #4 0x70f5b7c2a28a  (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
# |     #5 0x5b56d8d4c3d4  (/home/martin/code/llvm-project/build-libcxx-sanitize
rs/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0x2d3d4)
# |
# | SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/home/martin/code/llvm-pr
oject/build-libcxx-sanitizers/libcxx/test/libcxx/language.support/support.dynamic/Output/libcpp_deallocate.sh.cpp.dir/t.tmp.exe+0xcf976)
# | ==2987905==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
# | ==2987905==ABORTING
# `-----------------------------
# error: command failed with exit status: 1
```

But after this change, it succeeds.

If this is right and expected that it fixes the root cause, we could change the `XFAIL` into `UNSUPPORTED` in that test, while versions both with and without the fix are supported, and then finally remove the `UNSUPPORTED` later.


But as @vitalybuka mentioned in https://github.com/llvm/llvm-project/pull/108357#issuecomment-2553088739, many also expect to be able to link with `-nostdlib++ -lc++` and still have working sanitizers (e.g. ubsan, which also failed), which this does break.

https://github.com/llvm/llvm-project/pull/120370


More information about the llvm-commits mailing list