This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Add shared_cxxabi requirement
ClosedPublic

Authored by leonardchan on Sep 10 2021, 7:47 PM.

Details

Summary

This adds REQUIRES: shared_cxxabi to a bunch of tests that would fail if this weak reference in sanitizer common was undefined. This is necessary in cases where libc++abi.a is statically linked in. Because there is no strong reference to __cxa_demangle in compiler-rt, then if libc++abi is linked in via a static archive, then the linker will not extract the archive member that would define that weak symbol. This causes a handful of tests to fail because this leads to the symbolizer printing mangled symbols where tests expect them demangled.

Technically, this feature is WAI since sanitizer runtimes shouldn't fail if this symbol isn't resolved, and linking statically means you wouldn't need to link in all of libc++abi. As a workaround, we can simply make it a requirement that these tests use shared libc++abis.

Diff Detail

Event Timeline

leonardchan created this revision.Sep 10 2021, 7:47 PM
leonardchan requested review of this revision.Sep 10 2021, 7:47 PM
leonardchan added a comment.EditedSep 10 2021, 7:49 PM

Note that one other solution could be to make __cxa_demangle be a strong reference via a cmake argument. I think this would cover the C++ cases where the driver links in libc++abi, but clang doesn't seem to link in libc++abi for C code, which would lead to a bunch of undefined reference errors.

s/-u=__cxa_demangle/-u __cxa_demangle/

This causes a handful of tests to fail because this leads to the symbolizer printing mangled symbols where tests expect them demangled.

Could these tests just check mangled names?

This causes a handful of tests to fail because this leads to the symbolizer printing mangled symbols where tests expect them demangled.

Could these tests just check mangled names?

Technically yes, but I think that would cause the test to fail for users who dynamically link in libc++abi where __cxa_demangle would be defined and end up printing the demangled name.

leonardchan edited the summary of this revision. (Show Details)Sep 13 2021, 4:59 PM
vitalybuka resigned from this revision.Sep 14 2021, 10:46 AM

I don't have an opinion on that. Feel free to add me back if other reviewers will be unable to continue.

*ping* any more comments on this?

@leonardchan Could we instead use the REQUIRES: shared_cxxabi stanza you introduced in D109938 and disable these tests if using static libc++abi? That seems like a better solution to me.

@leonardchan Could we instead use the REQUIRES: shared_cxxabi stanza you introduced in D109938 and disable these tests if using static libc++abi? That seems like a better solution to me.

I can do that. I think the only downside would be we just won't run these specific tests.

leonardchan retitled this revision from [compiler-rt] Prevent __cxa_demangle from being undefined to [compiler-rt] Add shared_cxxabi requirement.
leonardchan edited the summary of this revision. (Show Details)
phosek added inline comments.Sep 22 2021, 4:43 PM
compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
5

Do we need both shared_cxxabi and cxxabi? I'd expect shared_cxxabi to imply cxxabi in which case this line can be dropped.

leonardchan added inline comments.Sep 22 2021, 4:55 PM
compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
5

So it's kinda unfortunate naming in this case since cxxabi in actuality refers to if libc++abi can be used in UBSan, rather than if it's available in general (see SANITIZER_CAN_USE_CXXABI in compiler-rt/lib/ubsan/CMakeLists.txt and https://github.com/llvm/llvm-project/blob/ac191bcc99e2fc4ab7993138f5e82a0b75b7e9db/compiler-rt/CMakeLists.txt#L182).

They're technical unrelated since cxxabi refers to if UBSan having libc++abi (either shared or static) whereas shared_cxxabi refers to if compiler-rt is using a shared libc++abi in general. I think in a followup, cxxabi should be renamed.

phosek accepted this revision.Sep 23 2021, 4:38 PM

LGTM

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp
5

Thanks for the explanation, renaming cxxabi makes sense.

Would it be possible to also file a bug in Bugzilla for the issue with linking libc++abi as a static archive in sanitizers and reference it here in the comment?

This revision is now accepted and ready to land.Sep 23 2021, 4:38 PM
This revision was landed with ongoing or failed builds.Sep 24 2021, 11:53 AM
This revision was automatically updated to reflect the committed changes.