New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 6.0 #3583

Closed
wants to merge 6 commits into
base: master
from

Conversation

@xentec
Contributor

xentec commented Mar 11, 2018

Building LLVM components as standalone packages becomes more painful as more of them rely directly on LLVM's source code. I suggest putting packages without reverse dependencies, like compiler-rt and llvm-libunwind back to testing until a satisfying way is found to build all of them (including lldb and libc++) in one package.

Needless to say all packages in this PR passed their tests.

@jirutka

This comment has been minimized.

Member

jirutka commented Mar 11, 2018

Building LLVM components as standalone packages becomes more painful as more of them rely directly on LLVM's source code.

And it even breaks some components (IIRC lldb). LLVM’s build system is really crappy. We (me and @kaniini) have already decided to resign on it and merge all (or some) LLVM components into a single abuild, so we can build it as a single unit. It seems that this is the only approach the LLVM build system is tested on. 😿
However, I’m not keen into doing this job, I’ve already wasted quite a lot of time on this LLVM insanity…

If you’re willing to do it, I’d be very happy!

I suggest putting packages without reverse dependencies, like compiler-rt and llvm-libunwind back to testing…

llvm-libunwind is needed for rust, so it cannot be moved to testing!

@xentec

This comment has been minimized.

Contributor

xentec commented Mar 12, 2018

If you’re willing to do it, I’d be very happy!

I am and will try to, but my expertise, time and CPU cores are limited so this could take a while. Because of that I'd like you to merge this PR first for a guarantee that a working LLVM 6.0 package will land in next Alpine release.

@am11

This comment has been minimized.

Contributor

am11 commented Mar 13, 2018

@jirutka, sorry for the long delay on #2342. Last time I tried building LLDB, I was running into errors from one of the dependency (can't remember which one, but it was not of LLVM family and abuild -R in lldb directory with tip of alpinelinux/aport's master branch wasn't even building for me). If @xentec wants to try out building LLDB 6 instead, we can close my PR. Otherwise, I will try to dig into it with LLDB release_60 sources over the coming weekend. 😊

@algitbot algitbot force-pushed the alpinelinux:master branch from 96f9230 to 3e87b8f Mar 28, 2018

@andypost

This comment has been minimized.

Contributor

andypost commented Mar 31, 2018

llvm-libunwind is needed for rust, so it cannot be moved to testing!

Yes rust 1.25 require it

@drmoose

This comment has been minimized.

drmoose commented May 11, 2018

The APKBUILD doesn't list diffutils among its makedepends, but fails without it:

[100%] Running the LLVM regression tests
FAIL: LLVM :: MC/AsmParser/preserve-comments-crlf.s (16245 of 23267)
******************** TEST 'LLVM :: MC/AsmParser/preserve-comments-crlf.s' FAILED ********************
Script:
--
/aports/main/llvm6/src/llvm-6.0.0.src/build/bin/llvm-mc -preserve-comments -n -triple i386-linux-gnu < /aports/main/llvm6/src/llvm-6.0.0.src/test/MC/AsmParser/preserve-comments-crlf.s > /aports/main/llvm6/src/llvm-6.0.0.src/build/test/MC/AsmParser/Output/preserve-comments-crlf.s.tmp
diff --strip-trailing-cr /aports/main/llvm6/src/llvm-6.0.0.src/test/MC/AsmParser/preserve-comments-crlf.s /aports/main/llvm6/src/llvm-6.0.0.src/build/test/MC/AsmParser/Output/preserve-comments-crlf.s.tmp
--
Exit Code: 1

Command Output (stderr):
--
diff: unrecognized option: strip-trailing-cr
BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary.

Usage: diff [-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2

Compare files line by line and output the differences between them.
This implementation supports unified diffs only.

	-a	Treat all files as text
	-b	Ignore changes in the amount of whitespace
	-B	Ignore changes whose lines are all blank
	-d	Try hard to find a smaller set of changes
	-i	Ignore case differences
	-L	Use LABEL instead of the filename in the unified header
	-N	Treat absent files as empty
	-q	Output only whether files differ
	-r	Recurse
        --no-dereference Don't follow symlinks
	-S	Start with FILE when comparing directories
	-T	Make tabs line up by prefixing a tab when necessary
	-s	Report when two files are the same
	-t	Expand tabs to spaces in output
	-U	Output LINES lines of context
	-w	Ignore all whitespace

--

********************
Testing Time: 756.94s
********************
Failing Tests (1):
    LLVM :: MC/AsmParser/preserve-comments-crlf.s

  Expected Passes    : 21353
  Expected Failures  : 135
  Unsupported Tests  : 1778
  Unexpected Failures: 1
make[3]: *** [test/CMakeFiles/check-llvm.dir/build.make:58: test/CMakeFiles/check-llvm] Error 1
make[2]: *** [CMakeFiles/Makefile2:69290: test/CMakeFiles/check-llvm.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:69297: test/CMakeFiles/check-llvm.dir/rule] Error 2
make: *** [Makefile:13381: check-llvm] Error 2
>>> ERROR: llvm6: all failed

With apk add diffutils to get GNU diff instead of the busybox one, abuild -r with this package works as expected. Being very new to Alpine, I don't know whether this is actually a problem with this PR or with my build procedure, but I'm noting it here anyway for others like me, who need this package, find this PR, but don't know what they're doing.

@xentec xentec force-pushed the xentec:pr-llvm-6 branch from 103d4bf to cc8d8cc May 11, 2018

@xentec

This comment has been minimized.

Contributor

xentec commented May 12, 2018

Fixed. Thanks for the report @drmoose!
I've updated the PR to latest master and also enabled dynamic linking for Clang and LLD (cc @am11) significantly reducing their package sizes.

@am11

This comment has been minimized.

Contributor

am11 commented May 12, 2018

Thanks, this is progressing nicely @xentec!
As per #2342 (comment), v6 toolchain of LLVM will probably go in once Alpine Linux v3.8 is out.

A question regarding patch number prefix convention: should those be renumbered (001-, 002-) without gaps?

@matteomonti

This comment has been minimized.

matteomonti commented May 15, 2018

Hello! I have just used this pull request to successfully install llvm6 and clang6 on my Alpine Linux Docker container. I tried to go ahead, build and install libc++6 as well, but I couldn't find it. I naively tried to install libc, but it obviously didn't help. Does anyone have suggestions on how I could get libc++6 installed on Alpine Linux?

@jeannich

This comment has been minimized.

jeannich commented Jun 1, 2018

Hi @matteomonti,
Would you mind explaining a bit how you did this please? (Having alpine container with this PR)
Thanks!

xentec added some commits Mar 11, 2018

@xentec xentec force-pushed the xentec:pr-llvm-6 branch from 869ec34 to 82fee9a Jul 12, 2018

@xentec

This comment has been minimized.

Contributor

xentec commented Jul 22, 2018

@jirutka Friendly reminder that this PR is ready and waiting.

@m3talstorm

This comment has been minimized.

m3talstorm commented Jul 30, 2018

Would be great to have this applied and in a release.

@Kronuz

This comment has been minimized.

Kronuz commented Sep 1, 2018

These two fellows need upgrading too: main/compiler-rt and testing/libc++ ... and also, by the way, I think clang should use compiler-rt and libc++ by default, and not to depend on GCC; that’s what I, as a developer, would expect, when installing and using clang.

@Kronuz

This comment has been minimized.

Kronuz commented Sep 1, 2018

I've added a few commits towards that end, on top of the pr-llvm-6 branch: xentec/aports@pr-llvm-6...Kronuz:pr-llvm-6

Final docker image could be compiled with something like:

# gcloud container --project=dubalu-io-cloud clusters create clang-builder --enable-ip-alias --enable-autoupgrade --cluster-version=latest --num-nodes=1 --machine-type=n1-highcpu-64
# kubectl run -it clang-builder --image=alpine:3.8 -- sh
# Temporary workaround for there not being an llvm6 apk yet
# Open PR for llvm6 package: https://github.com/alpinelinux/aports/pull/3583
# See https://stackoverflow.com/questions/50258121/building-llvm-6-under-linux-alpine
FROM alpine:3.8

RUN apk update \
  && apk add --no-cache --virtual .build-deps \
    alpine-sdk \
    git \
    diffutils \
    patchelf \
  && adduser -D apk \
  && adduser apk abuild \
  && sudo -iu apk abuild-keygen -a \
  && cp /home/apk/.abuild/*.rsa.pub /etc/apk/keys \
  && sudo -iu apk git clone --depth=1 -b pr-llvm-6 https://github.com/Kronuz/aports \
  \
  # For faster builds in multi-processor boxes:
  # && sudo -iu apk sh -xec 'cd aports/main/llvm6; sed -i "s@\bmake\b@make -j96@g" APKBUILD' \
  # && sudo -iu apk sh -xec 'cd aports/main/clang; sed -i "s@\bmake\b@make -j96@g" APKBUILD' \
  # && sudo -iu apk sh -xec 'cd aports/main/compiler-rt; sed -i "s@\bmake\b@make -j96@g" APKBUILD' \
  # && sudo -iu apk sh -xec 'cd aports/community/lld; sed -i "s@\bmake\b@make -j96@g" APKBUILD' \
  # && sudo -iu apk sh -xec 'cd aports/community/llvm-libunwind; sed -i "s@\bmake\b@make -j96@g" APKBUILD' \
  # && sudo -iu apk sh -xec 'cd aports/testing/libc++; sed -i "s@\bmake\b@make -j96@g" APKBUILD' \
  \
  # First pass.
  # Build the needed components using gcc (libc++ is build last, using the built clang):
  && sudo -iu apk sh -xec 'cd aports/main/llvm6; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/llvm6-*.apk \
  && sudo -iu apk sh -xec 'cd aports/main/clang; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/clang-*.apk \
  && sudo -iu apk sh -xec 'cd aports/community/lld; abuild -r' \
  && apk add /home/apk/packages/community/$(uname -m)/lld-*.apk \
  && sudo -iu apk sh -xec 'cd aports/community/llvm-libunwind; abuild -r' \
  && apk add /home/apk/packages/community/$(uname -m)/llvm-libunwind-*.apk \
  && sudo -iu apk sh -xec 'cd aports/testing/libc++; abuild -r' \
  && apk add /home/apk/packages/testing/$(uname -m)/libc++-*.apk \
  && sudo -iu apk sh -xec 'cd aports/main/compiler-rt; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/compiler-rt-*.apk \
  \
  # Second pass.
  # Build and install a llvm6 and clang which compiles using lld, libc++ and compiler-rt:
  # (but first patch rpath for current clang and lld so they keep working during the process)
  && rm /usr/lib/libunwind.so* \
  && sudo -iu apk cp -R /usr/lib lib1 \
  && patchelf --set-rpath '/home/apk/lib1:/home/apk/lib1/llvm6/lib:$ORIGIN/../lib:/usr/lib/llvm6/lib' /usr/bin/clang \
  && patchelf --set-rpath '/home/apk/lib1:/home/apk/lib1/llvm6/lib:$ORIGIN/../lib:/usr/lib/llvm6/lib' /usr/bin/lld \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; cd aports/main/llvm6; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/llvm6-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; export CLANG_DEFAULT_LINKER="lld"; export CLANG_DEFAULT_CXX_STDLIB="libc++"; export CLANG_DEFAULT_RTLIB="compiler-rt"; cd aports/main/clang; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/clang-*.apk \
  \
  # Third pass.
  # Rebuild and install everything using new clang with libc++ and compiler-rt (kill all gcc dependencies):
  # (but first patch rpath for current clang so it keeps working during the process)
  && sudo -iu apk cp -R /usr/lib lib2 \
  && patchelf --set-rpath '/home/apk/lib2:/home/apk/lib2/llvm6/lib:$ORIGIN/../lib:/usr/lib/llvm6/lib' /usr/bin/clang \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; cd aports/main/llvm6; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/llvm6-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; export CLANG_DEFAULT_LINKER="lld"; export CLANG_DEFAULT_CXX_STDLIB="libc++"; export CLANG_DEFAULT_RTLIB="compiler-rt"; cd aports/main/clang; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/clang-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; cd aports/main/compiler-rt; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/main/$(uname -m)/compiler-rt-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; cd aports/community/lld; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/community/$(uname -m)/lld-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; cd aports/community/llvm-libunwind; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/community/$(uname -m)/llvm-libunwind-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; export LIBCXX_USE_COMPILER_RT="ON"; cd aports/testing/libc++; abuild cleanpkg; abuild -r' \
  && apk add /home/apk/packages/testing/$(uname -m)/libc++-*.apk \
  && sudo -iu apk sh -xec 'export CC="clang"; export CXX="clang++"; cd aports/testing/lldb; abuild -r' \
  && apk add /home/apk/packages/testing/$(uname -m)/lldb-*.apk \
  \
  # Save .apk packages
  && mkdir /packages \
  && cp /home/apk/.abuild/apk-*.rsa.pub /packages \
  && find /home/apk/packages -name '*.apk' -exec mv {} /packages \; \
  \
  # Cleanup:
  && deluser --remove-home apk \
  && rm -rf /var/cache/apk/APKINDEX* \
  && apk del .build-deps

FROM alpine:3.8

COPY --from=0 /packages /packages

RUN cp /packages/apk-*.rsa.pub /etc/apk/keys \
  && apk add /packages/libc++-6.0.1-r0.apk \
    /packages/llvm-libunwind-6.0.1-r0.apk \
  && apk add --no-cache --virtual build-clang \
    binutils \
    musl-dev \
    /packages/llvm6-libs-6.0.1-r0.apk \
    /packages/compiler-rt-6.0.1-r0.apk \
    /packages/llvm-libunwind-dev-6.0.1-r0.apk \
    /packages/clang-6.0.1-r0.apk \
    /packages/clang-libs-6.0.1-r0.apk \
    /packages/clang-dev-6.0.1-r0.apk \
    /packages/lld-6.0.1-r0.apk \
    /packages/lld-libs-6.0.1-r0.apk \
    /packages/libc++-dev-6.0.1-r0.apk \
    /packages/lldb-6.0.1-r0.apk \
    /packages/lldb-dev-6.0.1-r0.apk \
    /packages/py2-lldb-6.0.1-r0.apk \
  && rm -rf /packages

# The following are intentionally left out of the final image:
# packages/clang-doc-6.0.1-r0.apk
# packages/llvm6-6.0.1-r0.apk
# packages/clang-static-6.0.1-r0.apk
# packages/clang-analyzer-6.0.1-r0.apk
# packages/lld-dev-6.0.1-r0.apk
# packages/llvm6-test-utils-6.0.1-r0.apk
# packages/llvm6-dev-6.0.1-r0.apk
# packages/llvm6-static-6.0.1-r0.apk

Edit: I updated the above Dockerfile, this one I tested it and it's producing working tools with absolutely no gcc dependencies from a clean alpine:3.8. With the above image, I can now do:

FROM kronuz/clang

RUN printf '#include <iostream>\nint main(){std::cout<<"Hello, World!"<<std::endl;return 0;}' > test.cc \
  && clang++ -std=c++11 test.cc -o test \
  && apk del build-clang
@xentec

This comment has been minimized.

Contributor

xentec commented Sep 11, 2018

@Kronuz Big thanks!
But does your libc++ package use the same ABI as libstd++? Because otherwise it breaks all C++ libraries compiled with g++.
Also I noticed some curl calls in your patches. Please put the URLs into sources= definition.

@Kronuz

This comment has been minimized.

Kronuz commented Sep 11, 2018

I’m using libc++, which allegedly has ABI compatibility with gcc's libstdc++, or so the documentation states... but in all honestly, i haven’t tried; I’m just compiling all my C++ dependencies as well, as it’s the recommendation.

The thing with those curl is I’m using NetBSD’s crtbegin.S and crtend.S for the current architecture; this is to allow ld (binutils) to seemlessly link binaries without needing GCC. But those crt*.S are in assembly and those come in different files for different architectures. The alternative would be to download all of them, for all architectures (as we need to add the sha512 of each), and just use the one for the active architecture; or otherwise bundle the files as patches to compiler-rt.

@aw1621107

This comment has been minimized.

aw1621107 commented Oct 1, 2018

@Kronuz From what I understand, libc++ is only partially ABI compatible with libstdc++. For example, std::string isn't ABI compatible between libc++ and libstdc++, but memory allocated in libc++ can be deallocated in libstdc++.

For what it's worth, Debian's clang-6.0 package appears to use libstdc++ by default, presumably so things built with clang will be more or less guaranteed to work with other things installed using apt. I don't know whether this is considered to be behavior that Alpine should copy; at the very least it's a tradeoff between the convenience of using prebuilt C++ packages and the correctness of having all C++ code built using the same compiler. I think more binary distros go with the former, but I'm not that familiar with the Linux ecosystem.

Also, have you tried using the current version of your Docker script recently? I've been trying to use it and builds are failing on the second build of clang (on the make clang-tblgen target) due to the linker being unable to find a definition for the symbol _Unwind_Resume:

Linking CXX executable ../../bin/clang-tblgen                                                                                                                
cd /home/apk/aports/main/clang/src/cfe-6.0.1.src/build/utils/TableGen && /usr/bin/cmake -E cmake_link_script CMakeFiles/clang-tblgen.dir/link.txt --verbose=1
/usr/bin/clang++  -Os -fomit-frame-pointer -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -
Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
-Wstring-conversion -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -pedantic -Wno-long-long -Wno-nested-anon-types -Os -fomit-frame-poi
nter -Os -DNDEBUG  -Wl,--as-needed -stdlib=libc++ -Wl,--as-needed  -Wl,-rpath-link,/home/apk/aports/main/clang/src/cfe-6.0.1.src/build/./lib  -Wl,-O3 -Wl,--g
c-sections CMakeFiles/obj.clang-tblgen.dir/ClangASTNodesEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/ClangAttrEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/
ClangCommentCommandInfoEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/Cla
ngCommentHTMLTagsEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/ClangDataCollectorsEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/ClangDiagnosticsEmitter.cpp.o
 CMakeFiles/obj.clang-tblgen.dir/ClangOptionDocEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/ClangSACheckersEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/Neo
nEmitter.cpp.o CMakeFiles/obj.clang-tblgen.dir/TableGen.cpp.o  -o ../../bin/clang-tblgen  -L/usr/lib/llvm6/lib -Wl,-rpath,"\$ORIGIN/../lib:/usr/lib/llvm6/lib
" /usr/lib/llvm6/lib/libLLVMSupport.a /usr/lib/llvm6/lib/libLLVMTableGen.a /usr/lib/llvm6/lib/libLLVMSupport.a -lz -lrt -ldl -lm /usr/lib/llvm6/lib/libLLVMDe
mangle.a
/usr/bin/ld.lld: error: undefined symbol: _Unwind_Resume
>>> referenced by ClangASTNodesEmitter.cpp
>>>               CMakeFiles/obj.clang-tblgen.dir/ClangASTNodesEmitter.cpp.o:(clang::EmitClangASTNodes(llvm::RecordKeeper&, llvm::raw_ostream&, std::__1::bas
ic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocato
r<char> > const&))

/usr/bin/ld.lld: error: undefined symbol: _Unwind_Resume
>>> referenced by ClangASTNodesEmitter.cpp
>>>               CMakeFiles/obj.clang-tblgen.dir/ClangASTNodesEmitter.cpp.o:(clang::EmitClangDeclContext(llvm::RecordKeeper&, llvm::raw_ostream&))

<snip: more "undefined symbol: _Unwind_Resume" errors>
@tylerhale

This comment has been minimized.

tylerhale commented Oct 5, 2018

Is there work on the LLVM side to make it easier for alpine builds? and is there an ETA on when this might be accessible through apk?

@xentec

This comment has been minimized.

Contributor

xentec commented Oct 6, 2018

I'm in the middle of testing LLVM 7.0 right now. New PR is coming when everything works well enough.
You can see the progress here: https://github.com/xentec/aports/commits/pr-llvm-7

@xentec xentec closed this Oct 6, 2018

@Kronuz

This comment has been minimized.

Kronuz commented Oct 6, 2018

@xentec, I think we should have all the other bits I added (such as crtbegin/crtend and whatnot) to make clang to not depend on GCC at all. Clang could still be (maybe) compiled with libstdc++ as the default stdlib for building stuff (by not setting CLANG_DEFAULT_CXX_STDLIB) but nonetheless still building all clang it’s dependencies and tools with libc++, so it doesn’t depend on GCC (it really shouldn’t).

The goal should also be to build all the sanitizers with compiler-rt and the corresponding instrumented libc++ libraries.

@xentec

This comment has been minimized.

Contributor

xentec commented Oct 6, 2018

@Kronuz, I will add your patches, once 7.0 runs, but whether or not clang should compile against compile-rt is for the Alpine Maintainers to decide. cc @ncopa

@Kronuz

This comment has been minimized.

Kronuz commented Oct 6, 2018

Clang should have no GCC dependencies, it could use libstdc++ as it’s default standard library when compiling stuff, but clang itself should not have GCC dependencies IMHO.

@am11

This comment has been minimized.

Contributor

am11 commented Oct 7, 2018

@xentec, regarding lldb, this locale patch is not required if we go from 5.0.1 to 7.0: xentec@fc12123#diff-af86b066296def851ee48fd7c9a8e5d3; missing #include <locale.h> is in 6.0.1 branch.

@raja

This comment has been minimized.

raja commented Nov 27, 2018

Any updates on this?

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