Problems linking compiler-rt and libc++ with -nodefaultlibs; Could -stdlib=none be a solution?

Hi All,

Currently we cannot use sanitizers and other instrumentation when
building and testing libc++ on OS X. For obvious reasons we have to
use '-nodefaultlibs' to ensure that clang doesn't link in another
standard library. On linux using '-fsanitize=...' and '-nodefaultlibs'
will link compiler-rt but on OS X it will not. I imagine other
platforms might also have this problem.

Manually linking compiler-rt is hard if not impossible and it would be
nice if we could have the linker driver do it for us. The changes
required to allow OS X to link compiler-rt with '-nodefaultlibs' seem
quite complicated and I don't think I would be able to make the
changes myself.

Should compiler-rt be linked when '-fsanitize=...' and
'-nodefaultlibs' are given? This behavior should be uniform across all
platforms. If not then how can we make manually linking compiler-rt

As an aside libc++ probably doesn't need to drop all default
libraries, just the standard library. Currently there is no way to do
this. One option that would fit our use case would be to add the
'-stdlib=none' option that only prevented linking (and including) the
standard library.

Are there any thoughts on adding '-stdlib=none'?

Related discussions can be found below:

[cfe-dev] Linking ProfileRT when using -nodefaultlibs

r218541 - Don't link in sanitizer runtimes if -nostdlib/-nodefaultlibs
is provided.


SGTM. This would be useful to me (and certainly others as well) even outside the tests because we don’t use the system installed C++ stdlib, but still need the other system libraries.