[LLVMdev] Purpose of LLVM_ENABLE_LIBCXX and LLVM_ENABLE_LIBCXXABI

995 views
Skip to first unread message

Schlottke-Lakemper, Michael

unread,
Jul 28, 2015, 7:14:51 AM7/28/15
to llv...@cs.uiuc.edu
Hi,

I am wondering about the meaning of the cmake flags LLVM_ENABLE_LIBCXX and LLVM_ENABLE_LIBCXXABI. Are they used to indicate that if the C/C++ compiler for building LLVM is clang, and if this clang has support for libc++ with libc++Abi, that both lib++ and libc++abi should be used (instead of linking to the default, which at least on Linux is libstdc++)? If not, what is the canonical way of building LLVM with libc++? I am asking since I seem to have problems linking libLLVMSupport.a to a program while using clang with libc++, whereas the used clang/LLVM compiler was originally built with clang and libstdc++.

Related to the first question: do the above flags also make clang use libc++ by default, or is this configurable via a different set of flags?

Thanks a lot in advance

Michael

--
Michael Schlottke-Lakemper

SimLab Highly Scalable Fluids & Solids Engineering
Jülich Aachen Research Alliance (JARA-HPC)
RWTH Aachen University

Wüllnerstraße 5a
52062 Aachen
Germany

Phone: +49 (241) 80 95188
Fax: +49 (241) 80 92257
Mail: m.schlottk...@aia.rwth-aachen.de
Web: http://www.jara.org/jara-hpc


_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Martell Malone

unread,
Jul 28, 2015, 7:35:01 AM7/28/15
to Schlottke-Lakemper, Michael, llv...@cs.uiuc.edu
Hi Michael,

I am wondering about the meaning of the cmake flags LLVM_ENABLE_LIBCXX and LLVM_ENABLE_LIBCXXABI. Are they used to indicate that if the C/C++ compiler for building LLVM is clang, and if this clang has support for libc++ with libc++Abi, that both lib++ and libc++abi should be used (instead of linking to the default, which at least on Linux is libstdc++)?

Yes that is actually what they are used for.

Kind Regards
Martell

Martell Malone

unread,
Jul 28, 2015, 7:36:00 AM7/28/15
to Schlottke-Lakemper, Michael, llv...@cs.uiuc.edu
Also please note that there is a description of each option in the CMakeLists.txt :)

llvm/trunk/CMakeLists.txt
option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)

Kind Regards
Martell

Renato Golin

unread,
Jul 28, 2015, 8:13:21 AM7/28/15
to Schlottke-Lakemper, Michael, llv...@cs.uiuc.edu
On 28 July 2015 at 12:10, Schlottke-Lakemper, Michael
<m.schlottk...@aia.rwth-aachen.de> wrote:
> I am wondering about the meaning of the cmake flags LLVM_ENABLE_LIBCXX and LLVM_ENABLE_LIBCXXABI. Are they used to indicate that if the C/C++ compiler for building LLVM is clang, and if this clang has support for libc++ with libc++Abi, that both lib++ and libc++abi should be used (instead of linking to the default, which at least on Linux is libstdc++)? If not, what is the canonical way of building LLVM with libc++? I am asking since I seem to have problems linking libLLVMSupport.a to a program while using clang with libc++, whereas the used clang/LLVM compiler was originally built with clang and libstdc++.

Hi Michael,

Just cloning the libc++ / libc++abi / libunwind repositories in
llvm/projects (or symlinking them there) is enough for CMake to pick
it up, build and test on check-all. The libraries will be available on
build/lib.


> Related to the first question: do the above flags also make clang use libc++ by default, or is this configurable via a different set of flags?

No. I believe this is an old flag when that wasn't enable by default
(and now it's used to disable it if you have the dirs). But maybe
heavier users of libc++ can help you there.

You still have to use LDFLAGS="--stdlib=libc++ -lc++abi -lunwind" and,
if you're not installing it anywhere (but using the build directory),
add LD_LIBRARY_PATH=build/lib to your environment.

If you run into inconsistencies because libgcc_s / libgcc_eh are
included, or if libstdc++ is included as well, you may have to use
-nostdlibc++ to clean up the internal options, and then use --stdlib
and friends to create a new set.

It is confusing, but we don't want to make those libraries the default
on any environment that might still need/use libstdc++/libgcc by
default. This is more of a system-wide decision. For testing purposes,
though, it works well.

cheers,
--renato

Renato Golin

unread,
Jul 28, 2015, 8:14:58 AM7/28/15
to Martell Malone, llv...@cs.uiuc.edu
On 28 July 2015 at 12:32, Martell Malone <martel...@gmail.com> wrote:
> option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
> option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
> option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
> option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
> option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
> option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)

So, this is related to building LLVM/Clang, not the resulting Clang
binary's default behaviour, right?

I had the impression that Michael actually wanted the latter, like GCC
has autoconf options to change the default behaviour of the compiler
at build time.

I may be wrong, though.

cheers,
--renato

Martell Malone

unread,
Jul 28, 2015, 8:50:10 AM7/28/15
to Renato Golin, llv...@cs.uiuc.edu
Hi Renato

I had the impression that Michael actually wanted the latter, like GCC
has autoconf options to change the default behaviour of the compiler
at build time.

I may be wrong, though.

yes I thought that was what he wanted because he said


Are they used to indicate that if the C/C++ compiler for building LLVM is clang

That combined with the standard cmake flags cmake_cxx_compiler and cmake_c_compiler should result in the host being clang and using libc++ and libc++abi
I was a little thrown off by the wording of the question
I think you are more correct though I misread the second part of the question where he said what he actually wanted the resulting compiler to use libc++
Sorry for the noise

Michael

In short Michael it should not matter if clang was build with libc++ or libstdc++ the resulting compiler can use both after the fact
As Renato described above in more detail LDFLAGS="--stdlib=libc++ -lc++abi -lunwind" would be used to tell that resulting compiler to link its programs with libc++, libc++abi and libunwind
Rather than using libstdc++ and libgcc_eh

If you want to know how to change the default to do this without touching the LDFLAGS for your target this you must look in the clang repo under lib/driver
If you have any trouble doing this I'd be glad to help you change the default behavior if let me know what your target is.

Kind Regards
Martell

Martell Malone

unread,
Jul 28, 2015, 9:46:37 AM7/28/15
to Renato Golin, llv...@cs.uiuc.edu
I think you are more correct though
Meant to say more likely correct. :)

I don't have an ego problem this was a typo

Michael
In short Michael
Also said his name twice,
I need to start reading things twice before I click the send button

Martell Malone

unread,
Jul 28, 2015, 9:47:20 AM7/28/15
to Renato Golin, LLVM Developers Mailing List
That's how I read it. :)
:)

Adding a little to the topic what criteria would we need to make a target use compiler-rt and libc++ as the default in the clang driver.
I have successfully built a standalone clang toolchain with mingw-w64 without using gcc or binutils.
Currently I locally patch this to be the default.


On Tue, Jul 28, 2015 at 2:33 PM, Renato Golin <renato...@linaro.org> wrote:
On 28 July 2015 at 14:14, Martell Malone <martel...@gmail.com> wrote:
> Meant to say more likely correct. :)

That's how I read it. :)

cheers,
--renato

Renato Golin

unread,
Jul 28, 2015, 10:02:07 AM7/28/15
to Martell Malone, LLVM Developers Mailing List
On 28 July 2015 at 14:44, Martell Malone <martel...@gmail.com> wrote:
> Adding a little to the topic what criteria would we need to make a target
> use compiler-rt and libc++ as the default in the clang driver.
> I have successfully built a standalone clang toolchain with mingw-w64
> without using gcc or binutils.

There was another discussion with David Chisnall, where he gave a good
overall on some of the complications for doing so:

http://comments.gmane.org/gmane.comp.compilers.clang.devel/44037

From my point of view, we can only do something that radical when we
can test on most environments and make sure that any combination will
work. I don't know how to do that, though, but I expect that there
should be enough tests in Clang to that effect.

For now, I just want to make sure it works on ARM/AArch64, even if I
have to hack my way through it. If I can have at least a buildbot
testing them, we'll be sure not to regress in functionality. System
integration is a secondary issue.

Schlottke-Lakemper, Michael

unread,
Jul 28, 2015, 11:41:36 AM7/28/15
to Martell Malone, llv...@cs.uiuc.edu
Hi Martell,

I am wondering about the meaning of the cmake flags LLVM_ENABLE_LIBCXX and LLVM_ENABLE_LIBCXXABI. Are they used to indicate that if the C/C++ compiler for building LLVM is clang, and if this clang has support for libc++ with libc++Abi, that both lib++ and libc++abi should be used (instead of linking to the default, which at least on Linux is libstdc++)?

Yes that is actually what they are used for.

Thank you for the confirmation. I saw the help text in CMakeLists.txt but was not sure whether it refers to the build process itself or the behavior of the resulting compiler.

Michael

Schlottke-Lakemper, Michael

unread,
Jul 28, 2015, 11:54:41 AM7/28/15
to Renato Golin, llv...@cs.uiuc.edu
Hi Renato,

>> Related to the first question: do the above flags also make clang use libc++ by default, or is this configurable via a different set of flags?
>
> No. I believe this is an old flag when that wasn't enable by default
> (and now it's used to disable it if you have the dirs). But maybe
> heavier users of libc++ can help you there.
>
> You still have to use LDFLAGS="--stdlib=libc++ -lc++abi -lunwind" and,
> if you're not installing it anywhere (but using the build directory),
> add LD_LIBRARY_PATH=build/lib to your environment.
>
> If you run into inconsistencies because libgcc_s / libgcc_eh are
> included, or if libstdc++ is included as well, you may have to use
> -nostdlibc++ to clean up the internal options, and then use --stdlib
> and friends to create a new set.
Thanks for the clarification and the hint with -nostdlibc++.

Michael

Schlottke-Lakemper, Michael

unread,
Jul 28, 2015, 12:00:17 PM7/28/15
to Renato Golin, LLVM Developers Mailing List
Wouldn’t it it be possible to add a flag like the one used in the OpenMP subproject? There they default to linking to the non-functional libgomp (as far as I understand it), and if people want to use the actual libomp runtime, they have to specify -fopenmp=libomp when compiling/linking a program. At the same time, it is possible to use the libomp runtime library by default by specifying

-DCLANG_DEFAULT_OPENMP_RUNTIME=libomp

at configuration time when building LLVM. That way things would not break for existing users with unsupported systems while making things for users like us *much* easier :)

Regards,

Michael

Renato Golin

unread,
Jul 28, 2015, 12:41:04 PM7/28/15
to Schlottke-Lakemper, Michael, LLVM Developers Mailing List
On 28 July 2015 at 16:57, Schlottke-Lakemper, Michael
<m.schlottk...@aia.rwth-aachen.de> wrote:
> -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
>
> at configuration time when building LLVM. That way things would not break for existing users with unsupported systems while making things for users like us *much* easier :)

This is possible, but not yet done for compiler-rt / libc++. It needs
support in the driver to actually change the default. Shouldn't be too
hard, but we need something that can grow into architectural options
as well (like GCC), to make the life of distributions easier, so we
can't just hack up something that will work "just" for rt/libc++.
Reply all
Reply to author
Forward
0 new messages