Skip to content

Add C++ toolchain for portable Linux builds - #16173

Merged
rmlarsen merged 1 commit into
tensorflow:masterfrom
jart:clang
Jan 23, 2018
Merged

rmlarsen merged 1 commit into
tensorflow:masterfrom
jart:clang

Conversation

@jart

@jart jart commented Jan 17, 2018

Copy link
Copy Markdown
Contributor

See #15777

@case540

case540 commented Jan 17, 2018

Copy link
Copy Markdown
Contributor

gunan@ asked me to test if TensorFlow pip package built with this clang crosstool on Ubuntu 16 will run correctly on Ubuntu 14. Working on testing that now.

@jart

jart commented Jan 18, 2018

Copy link
Copy Markdown
Contributor Author

Oh by the way @case540, here are some notes I took on building Clang from source:

# Install CMake (to build Clang snapshot)
sudo apt-get purge 'cmake*'
wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz
tar xvzf cmake-3.10.1.tar.gz
pushd cmake-3.10.1
CFLAGS='-O2 -march=native' CXXFLAGS='-O2 -march=native' ./bootstrap --prefix=/usr --parallel=96
make CFLAGS='-O2 -march=native' CXXFLAGS='-O2 -march=native' -j96
sudo make install
popd

# Install Ninja
git clone git://github.com/ninja-build/ninja.git
pushd ninja
git checkout release
CC=clang-6.0 CXX=clang++-6.0 CFLAGS='-O2 -march=native' CXXFLAGS='-O2 -march=native' ./configure.py --bootstrap
sudo cp ninja /usr/bin
popd

# Install Clang 7.0
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd clang/tools  # llvm/tools/clang/tools
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
cd ../..  # llvm/tools
svn co http://llvm.org/svn/llvm-project/lld/trunk lld
svn co http://llvm.org/svn/llvm-project/polly/trunk polly
cd ../projects  # llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
cd ..  # llvm

# Note: Build Clang using GCC 4.8.2+ (rather than Clang)
llvm_build_opts=(
  -DBUILD_SHARED_LIBS=On
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_CXX_FLAGS=-march=native
  -DCMAKE_C_FLAGS=-march=native
  -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold
  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
  -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly
  -DLLVM_OPTIMIZED_TABLEGEN=On
  -DLLVM_PARALLEL_COMPILE_JOBS=100
  -DLLVM_PARALLEL_LINK_JOBS=50
)
mkdir _build
cd _build
cmake -G Ninja .. "${llvm_build_opts[@]}"
ninja
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-7.0 -P cmake_install.cmake

I was experimenting to see if Clang 7.0 unstable would be a better choice, but it seemed a little… unstable, and didn't have some of the bleeding edge features out of the box I was hoping it'd have.

So if you end up needing to build from source, hopefully those notes will save you time.

@case540

case540 commented Jan 19, 2018

Copy link
Copy Markdown
Contributor

I tried building using this crosstool on Ubuntu 16 and ran into some issues. I made the following modifications to the crosstool file...

  • Changed glibc and libstdc++ to the versions that were installed by default
  • Changed -fuse-ld=gold to -fuse-ld=lld since I kept getting an error that "gold" was not a valid choice.

The build makes it a good bit of the way through but then I ran into this error. Any idea what the issue could be? Have you seen this before?

ERROR: /home/mikecase/.cache/bazel/_bazel_mikecase/c22aed87a372cfab86407106f2bbe57d/external/protobuf_archive/BUILD:271:1: Executing genrule @protobuf_archive//:generate_js_well_known_types_embed failed (Segmentation fault): bash failed: error executing command

@rmlarsen

Copy link
Copy Markdown
Contributor

@jart please resolve conflicts so we can merge this.

@rmlarsen rmlarsen self-assigned this Jan 22, 2018
@jart

jart commented Jan 23, 2018 •

Copy link
Copy Markdown
Contributor Author

@rmlarsen This is now sync'd and ready to merge.

@case540 and I spoke offline about troubleshooting segfaults with Bazel.

Gentlemen, here's to looking forward to a smooth 1.5 that exceeds our users' expectations by being boring and maintaining compatibility commitments.

@rmlarsen
rmlarsen merged commit 297ae45 into tensorflow:master Jan 23, 2018
@jart
jart deleted the clang branch January 23, 2018 19:35
@case540

case540 commented Jan 24, 2018

Copy link
Copy Markdown
Contributor

I built using the clang6 toolchain on ubuntu 16.

I modified the crosstool with the following versions (to what was installed by default on the machine)...
glibc to from 2.19 -> 2.23
libstdc++ from 4.8 -> 5.4.0

Unfortunately, I still hit the same error...

ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20' not found

...when running this pip package on Ubuntu 14. Anything else I should try?

@jart

jart commented Jan 26, 2018

Copy link
Copy Markdown
Contributor Author

@case540 I can't remember, did we use -nostdlib and -nostdlib++ flags so we could use the force in manually defining these -L and -l things ourselves?

@case540

case540 commented Jan 26, 2018

Copy link
Copy Markdown
Contributor

I did not use those flags when building. Is that something I should try out?

@jart

jart commented Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

@case540 Yes absolutely give them a try.

@jart

jart commented Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

I wouldn't be surprised if you could manually extract old versions of libc, libstdc++, libgcc, etc. into hard-coded folders and Clang and then finagle Clang 6.0 on Ubuntu 16 to just ignore what's on the system and use only those highly specific paths you've specified.

@case540

case540 commented Jan 29, 2018

Copy link
Copy Markdown
Contributor

Talked to someone from one of the compiler teams. Sounds like it might be possible to compile against glibc libraries extracted from Ubuntu 14 on Ubuntu 16. But he did not recommend doing so. Will give it a try when I have some spare time and see how bad it is.

@jart

jart commented Jan 30, 2018 •

Copy link
Copy Markdown
Contributor Author

That's a sane default recommendation. It's just that, based on what I've been told, not making this heroic hack work means your team might have no choice but to own a monolithic megacore Debian 8 buildbox, which honestly, IMHO ain't so bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Pull request awaiting review cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants