Compiling LLVM C++ library for x86 architecture

Looking at Building libc++ — libc++ 16.0.0git documentation to build the C++ library.
If I use those steps for gcc compiler on a Linux machine:

$ cmake -G Ninja -S llvm -B build …
$ ninja -C build runtimes

I get the 64 bits libraries.
How do I generate the same for 32 bits architecture.

Thanks,
Serge

Hi!

You need to tell the LLVM build system which targets you want like this:

-DLLVM_BUILTIN_TARGETS="x86_64-unknown-linux-gnu;i686-unknown-linux-gnu" 
-DLLVM_RUNTIME_TARGETS="i686-unknown-linux-gnu;x86_64-unknown-linux-gnu"

This will build for both. You can then set specific options per target by adding variables like:

-DBUILTINS_i686-unknown-linux-gnu_CMAKE_SYSTEM_NAME=Linux
-DBUILTINS_i686-unknown-linux-gnu_CMAKE_SYSROOT=/path_to_sysroot

You can find a good example that build several runtimes and builtins here: llvm-project/Fuchsia.cmake at main · llvm/llvm-project (github.com)

Hey Tobia,

adding -DLLVM_BUILTIN_TARGETS=“x86_64-unknown-linux-gnu;i686-unknown-linux-gnu”
to the cmake command and I get the following warning:

CMake Warning:
Manually-specified variables were not used by the project:

LLVM_RUNTIME_TARGETS

Any idea?

typo above:

CMake Warning:
Manually-specified variables were not used by the project:

LLVM_BUILTIN_TARGETS

You need to enable compiler-rt I think. Try:

-DLLVM_ENABLE_RUNTIMES=compiler-rt;libcxx

you might not need builtins for what you are doing, in that case you can just remove that line with BUILTIN_TARGETS

-DLLVM_ENABLE_RUNTIMES=compiler-rt;libcxx

does not help

for the second part, do you mean to use
-DBUILTIN_TARGETS

instead of

-DLLVM_BUILTIN_TARGETS=“x86_64-unknown-linux-gnu;i686-unknown-linux-gnu”

Hi.

I tested this and it worked fine for me on my machine. Can you post your full invocation and log when running CMake? Make sure you don’t have a CMakeCache.txt there as well since it will make CMake not regard all the new input.

Hi Tobia,

the CMake command that generates the ninja build environment is:

“cmake -G Ninja -S runtimes -B build -DLLVM_BUILTIN_TARGETS=“x86_64-unknown-linux-gnu;i686-unknown-linux-gnu” -DLLVM_ENABLE_RUNTIMES=“compiler-rt;libcxx;libcxxabi;libunwind” --log-level=VERBOSE -DLLVM_PARALLEL_LINK_JOBS=8 -DCMAKE_CXX_COMPILER=/usr/intel/pkgs/gcc/11.1.0/bin/g++ -DCMAKE_C_COMPILER=/usr/intel/pkgs/gcc/11.1.0/bin/gcc”

The log is long and since I can not upload a log file (new user) - I am copying and paste it here - sorry for that:

– The C compiler identification is GNU 4.8.5
– The CXX compiler identification is GNU 4.8.5
– The ASM compiler identification is GNU
– Found assembler: /usr/bin/cc
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: /usr/bin/cc - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Could NOT find LLVM (missing: LLVM_DIR)
– Could NOT find Clang (missing: Clang_DIR)
– Performing Test LLVM_RUNTIMES_LINKING_WORKS
– Performing Test LLVM_RUNTIMES_LINKING_WORKS - Success
– Performing Test LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG
– Performing Test LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG - Failed
– Performing Test LLVM_RUNTIMES_SUPPORT_NOSTDINCXX_FLAG
– Performing Test LLVM_RUNTIMES_SUPPORT_NOSTDINCXX_FLAG - Success
– Linker detection: GNU ld
– Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
– Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
– Performing Test C_SUPPORTS_WERROR_DATE_TIME
– Performing Test C_SUPPORTS_WERROR_DATE_TIME - Failed
– Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
– Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Failed
– Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
– Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
– Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
– Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
– Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG
– Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
– Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
– Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Failed
– Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
– Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Failed
– Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
– Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Failed
– Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
– Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Failed
– Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG
– Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Failed
– Performing Test CXX_SUPPORTS_REDUNDANT_MOVE_FLAG
– Performing Test CXX_SUPPORTS_REDUNDANT_MOVE_FLAG - Failed
– Performing Test CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG
– Performing Test CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG - Failed
– Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG
– Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Failed
– Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR
– Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR - Failed
– Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG
– Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG - Failed
– Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP
– Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Failed
– Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG
– Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Failed
– Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG
– Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Failed
– Performing Test C_SUPPORTS_MISLEADING_INDENTATION_FLAG
– Performing Test C_SUPPORTS_MISLEADING_INDENTATION_FLAG - Failed
– Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG
– Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG - Failed
– Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS
– Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS - Failed
– Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS
– Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS - Failed
– Performing Test C_SUPPORTS_FDATA_SECTIONS
– Performing Test C_SUPPORTS_FDATA_SECTIONS - Failed
– Performing Test CXX_SUPPORTS_FDATA_SECTIONS
– Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success
– Looking for os_signpost_interval_begin
– Looking for os_signpost_interval_begin - not found
– Found Python3: /usr/intel/bin/python3 (found version “3.7.4”) found components: Interpreter
– check-runtimes does nothing.
– Configuring done
– Generating done
CMake Warning:
Manually-specified variables were not used by the project:

LLVM_BUILTIN_TARGETS

– Build files have been written to: /nfs/…/work/llvm-project/build

Ah you are supposed to run -S llvm for my commands to work, I have never tired to build directly from the runtime directory before. Note that your detected compiler is to old to build clang. I am not sure why your -DCMAKE_CXX/C_COMPILER is not picked up? possibly because you have a old cache around.

The addition:
"-B build -DLLVM_BUILTIN_TARGETS=“x86_64-unknown-linux-gnu;i686-unknown-linux-gnu”

causes the compiler version confusion. Removing and version 11.1.0 is detected normally.

Maybe the unknown in x86_64-unknown-linux-gnu causes the confusion.

Where can the list of those targets be found - there may be one with gcc 11?

Hi guys,

I am insisting with this one since it looks quite a basic matter and I may not understand some basics with LLVM. I would be grateful if someone can shade light.
The only way I could build libcxx for 32bits (on my 64bits linux system using gcc) is by using the following:

cmake -G Ninja -S runtimes -B build -DCMAKE_ASM_FLAGS=-m32 -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_CXX_LINK_FLAGS=-m32 -DLLVM_ENABLE_RUNTIMES=“libcxx;libcxxabi;libunwind” --log-level=VERBOSE -DLLVM_PARALLEL_LINK_JOBS=8 -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc

It seems to build 32 bits libraries - although the release notes say using -m32 is “flaky” and they recommend to use cross compile by adding “-DLLVM_RUNTIME_TARGETS=i386-unknown-linux” but it does not work and cmake says LLVM_RUNTIME_TARGETS is ignored.

So, is my workaround above ok?
Is building 64 bits a simple task while 32 bits somewhat more complicated?
And what is the recommended way to build 32 bits libcxx in a 64bits linux environment?

Thanks,
Serge

I don’t think there is anything wrong with this approach per-se. I find it a bit ugly defining CFLAGS like that manually. But if it works - it works.

I think the recommended way is to get RUNTIMES build to work. I think it will be easier for you if you try to build a full clang and runtime build since clang has a bit of better handling of cross-compilation than gcc in this case.

But it all depends on if you are trying to do a small non-production thing or if you want to ship something important on this. There is no point putting more time into doing this “right” if it works for you and it’s not that important.

Thanks Tobia for your help.

What you say about -m32 makes sense.
To summarize:
I could not make the cross compilation work with either clang or gcc with ‘-S llvm’ or ‘-S runtimes’.
The LLVM_RUNTIME_TARGETS parameter is disregarded the same as I stated above.

In addition setting LLVM_ENABLE_RUNTIMES=all does not affect the issue above