0

Using a Dockerfile, I'm attempting to build Clang version v8 along with its dependencies on Ubuntu 18.04. The reason I'm going through all this trouble is because I can't find a 32-bit version of the LLVM libraries. Even the LLVM packages themselves have only 64-bit variants of everything. Because of this, I'm not able to build my 32-bit applications using the LLVM toolchain at version 8. Using version 8 of LLVM is mandatory for reasons I won't go into here.

So far, here is what I have:

FROM ubuntu:18.04 AS build ARG NUM_PARALLEL=8 RUN true \ && dpkg --add-architecture i386 \ && apt-get -qq update \ && apt-get -qq install \ software-properties-common \ build-essential \ gcc-multilib \ g++-multilib \ git \ wget \ autoconf \ pkg-config \ m4 \ python-dev:i386 \ libcurl4-gnutls-dev:i386 \ libncurses-dev:i386 \ uuid-dev:i386 \ libx11-dev:i386 \ libxext-dev:i386 \ libtinfo-dev:i386 \ libedit-dev:i386 \ swig \ libedit-dev python-dev ENV CMAKE_BUILD_PARALLEL_LEVEL=$NUM_PARALLEL # Ninja RUN true \ && git clone --depth 1 --branch v1.8.2 https://github.com/ninja-build/ninja.git \ && cd ninja \ && ./configure.py --bootstrap \ && cp ninja /usr/local/bin # CMake RUN true \ && git clone --depth 1 --branch v3.13.4 https://gitlab.kitware.com/cmake/cmake.git \ && cd cmake \ && ./bootstrap --parallel=$NUM_PARALLEL \ && make -j$NUM_PARALLEL install # Clang (See: https://clang.llvm.org/get_started.html) RUN true \ && git clone --depth 1 --branch llvmorg-8.0.0 https://github.com/llvm/llvm-project.git \ && cd llvm-project \ && cmake -G Ninja -B build -S llvm \ -D CMAKE_BUILD_TYPE=Release \ -D LLVM_BUILD_32_BITS:BOOL=ON \ -D LLVM_ENABLE_PROJECTS=all \ -D LLVM_BUILD_TESTS:BOOL=OFF \ -D LLVM_BUILD_EXAMPLES:BOOL=OFF \ -D LLVM_INCLUDE_EXAMPLES:BOOL=OFF \ -D LLVM_INCLUDE_TESTS:BOOL=OFF \ -D LLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ && cmake --build build -j $NUM_PARALLEL --target install 

I get through compiling a little over 5200 translation units, which takes over an hour, only for it to fail:

[5232/6435] Linking CXX shared library lib/readline.so FAILED: lib/readline.so : && /usr/bin/c++ -fPIC -fPIC -fvisibility-inlines-hidden -m32 -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -Wno-macro-redefined -O3 -DNDEBUG -Wl,-z,defs -Wl,-z,nodelete -m32 -shared -Wl,-soname,readline.so -o lib/readline.so tools/lldb/scripts/Python/modules/readline/CMakeFiles/readline.dir/readline.cpp.o /usr/lib/x86_64-linux-gnu/libpython2.7.so /usr/lib/x86_64-linux-gnu/libedit.so && : /usr/lib/x86_64-linux-gnu/libpython2.7.so: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status 

I followed the getting started page to understand how to build LLVM so far, but I must be missing something. They don't exactly go into 32-bit compilation in their examples. Can someone help me get this building? Or at least (and probably better), point me to a version of Clang v8 that has 32-bit LLVM libraries bundled with it?

8
  • Are you trying to build libc++ or the whole LLVM/Clang toolchain? Also, why do you assume that x64 Clang compiler can't target x86 arch? What did you do with previous version of LLVM/Clang? Commented Apr 10, 2019 at 13:44
  • I never said the x64 compiler can't target x86. What I'm saying is that the 32-bit LLVM libraries are not available, so using -m32 causes linker failures due to libc++ missing (since it's not available for the i386 architecture). Commented Apr 10, 2019 at 13:50
  • clang by default uses system libstdc++, but anyway, if you only want libc++, why are you building the whole LLVM (with ninja and cmake to boot)? Have you read libcxx.llvm.org/docs/BuildingLibcxx.html ? Commented Apr 10, 2019 at 13:56
  • If you're using Ubuntu already, can't you dpkg --add-architecture i386 and then apt-get install libc++1:i386 ? (see Debian multiarchitecture) Commented Apr 10, 2019 at 14:07
  • @Botje the libc++1 package is for Clang v7, not v8, and also requires v18.10 of ubuntu (I'm on 18.04 and that cannot change). Commented Apr 10, 2019 at 14:30

1 Answer 1

3

Seems like you are linking against the wrong Python: usr/lib/x86_64-linux-gnu/libpython2.7.so.

You may want to for it and add it to the CMake commands:

-DPYTHON_EXECUTABLE=PATH_TO_PYTHON-DEV:i686 

You may also need to set PYTHON_LIBRARY and PYTHON_INCLUDE_DIR to make sure that the i386 versions are used.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.