This is an archive of the discontinued LLVM Phabricator instance.

[Scudo] Avoid accidental references of C++ library
AbandonedPublic

Authored by phosek on Mar 14 2018, 3:51 PM.

Details

Reviewers
cryptoad
Summary

Scudo uses C++ but doesn't use C++ library. Set -nostdinc++ and
-nostdlib++ flags to enforce this and avoid accidental references.

Diff Detail

Event Timeline

phosek created this revision.Mar 14 2018, 3:51 PM
Herald added subscribers: Restricted Project, llvm-commits, mgorny. · View Herald TranscriptMar 14 2018, 3:51 PM

So as is this gets me clang-6.0: error: argument unused during compilation: '-nostdlib++' [-Werror,-Wunused-command-line-argument].
I duplicated SCUDO_CFLAGS to SCUDO_CXXFLAGS and added -nostdlib++ there, replacing the flags for the CXX static library & the .so and this works, but I am not sure it achieves what you want.

cryptoad added a comment.EditedMar 14 2018, 4:10 PM

Nevermind, I messed up the variable name it doesn't work either, -Wl, is what we want.

So it looks like it's going to be a bit more complicated.
There is C++ dependencies in UBSan (dynamic_cast and whatnot) and we pull in RTUBsan.
The base link flags are SANITIZER_COMMON_LINK_LIBS, SANITIZER_CXX_ABI_LIBRARY, which will pull in a C++ library.
As far as I understand, you guys don't care about a -fsanitize=scudo,undefine yet, so the way to go is a UBsan free Scudo (scudo-minimal or something).
Unless I'm misunderstanding the point.

phosek updated this revision to Diff 138646.Mar 15 2018, 4:13 PM

The missing -Wl, is a mistake on my side. This came up while cleaning up the libc++ installation process which made the Scudo build to fail because Scudo couldn't find libc++ headers which was expected since Scudo doesn't have an explicit dependency on it. So either it needs to have that dependency (at least on Fuchsia where libc++ is being built as part of LLVM and doesn't come from sysroot) or it should disable it altogether which is what this patch does. Having scudo-minimal sounds like something we probably want although it wasn't the original motivation behind this patch.

On Linux with -Wl,-nostdlib++, this doesn't compile as is with some complains about -lgcc_s not being found (from memory, not in front of my desktop now).
I figured the minimal build would be solution, I can dig into this tomorrow.

With the patch as is, it fails with gcc/clang on Linux with: /usr/bin/ld: cannot find -lgcc_s
Should those new options be Fuchsia only?

cryptoad added a comment.EditedMar 25 2018, 1:13 PM

Should be taken care of with D44791 [edited].

phosek abandoned this revision.Mar 25 2018, 11:31 PM

This is being addressed by D44791.