Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 31 Aug 2018 14:13:25 +0100
From: Jon Chesterfield <>
Subject: Re: clang/musl/linux?

Combing them wasn't my idea but it definitely simplifies the rest of the
system. I think it's meant to work out of the box, but on llvm 6 release at
least it needs some handholding. There's a description of the method and
the bash script I'm running below.

Your crt* workaround looks sound. It's a bit sad to create files that lld
wants but doesn't need. I'm doing the same.

I'll look at miniz and netbsd-curses, thanks. Certainly worth a try.



libc++ has working support for bundling a libcxxabi.a into the
shared/static library. That worked for me building the libraries separately
or simultaneously.

libcxxabi has cmake options that suggests it can incorporate libunwind.
That didn't work for me, either building separately or together.

Strategy is therefore:
- put all the source directories next to each other
- compile libunwind.a
- combine libcxxabi.a
- merge into an archive (misleadingly) called libcxxabi.a
- point libc++ to that external archive and let cmake merge it with libc++

The cmake uses a python script to merge static archives which also does a
degree of looking around the filesystem for them. Merging archives robustly
is remarkably tedious if the objects could have the same name. gnu ar and
llvm-ar both know how to do this safely via mri scripts.

buildcxxlib() {


echo "make libunwind"
mkdir -p "$BUILD/libunwind" && cd "$BUILD/libunwind"
make -j `nproc` install
cd ../..

echo "make libcxxabi"
mkdir -p "$BUILD/libcxxabi" && cd "$BUILD/libcxxabi"
#     -DLIBCXXABI_ENABLE_STATIC_UNWINDER doesnt seem to be implemented
make -j `nproc` install
cd ../..

echo "Combine libunwind and libcxxabi into a single static library"
mkdir -p $INSTALL/tmp
echo "create $INSTALL/lib/libunwindc++abi.a
addlib $INSTALL/lib/libunwind.a
addlib $INSTALL/lib/libc++abi.a
end" | llvm-ar -M
rm $INSTALL/lib/libunwind.a $INSTALL/lib/libc++abi.a
mv $INSTALL/lib/libunwindc++abi.a $INSTALL/lib/libc++abi.a
rm -rf $INSTALL/tmp

echo "make libcxx"
# Setting rpath here could be useful for letting libc++ find libc
mkdir -p "$BUILD/libcxx" && cd "$BUILD/libcxx"
    -DLIBCXX_CXX_ABI="libcxxabi" \
    -DLIBCXX_CXX_ABI_INCLUDE_PATHS=$SRC/llvm/projects/libcxxabi/include \
    -DCMAKE_INSTALL_RPATH="$BUILD/install/lib" \
make -j `nproc` install
cd ../..

rm $INSTALL/lib/libc++abi.a

On Fri, Aug 31, 2018 at 12:50 PM Dmitry Golovin <> wrote:

> Combining libunwind, libcxxabi and libc++ into a single library is a great
> idea! How exactly did you achieve this? What cmake options did you use?
> This is how I worked around crtbegin/crtend problem:
> Maybe you would be interested in bundling your toolchain with
> netbsd-curses and miniz as lightweight alternatives to ncurses and libz
> (don't know if they will create more problems then solve, though).
> Regards,
> Dmitry
> 31.08.2018, 14:30, "Jon Chesterfield" <>:
> > I'm still working on this, off and on. I want to assemble a C++
> toolchain that depends on the Linux kernel but nothing else from the
> distribution. Otherwise I'd use alpine.
> >
> > Most of the difficulty has been in working around assumptions made by
> the cmake scripts in LLVM. They are subtle to configure.
> >
> > Combining libunwind, libcxxabi and libc++ into a single library makes
> linking significantly simpler. Also makes setting rpath simpler.
> >
> > crti,crtn,crtbegin,crtend can be empty files. Don't use crtbegin from
> bsd.
> >
> > Tools like clang, lld have dependencies on other libraries. zlib, curses
> etc. Disabling these in the cmake files broke apparently unrelated things.
> My next step is to debug that or start building the supporting libraries.
> >
> > Musl itself has caused me no problems in any of the above.
> >
> > Cheers
> >
> > Jon
> >
> > On Fri, 31 Aug 2018, 09:29 Luca Barbato, <> wrote:
> >> On 31/08/2018 09:19, Dmitry Golovin wrote:
> >>> There should not be any problems building LLVM and musl on glibc-based
> distro. The reason why I'm building on Alpine is that I want my llvm and
> clang to be linked against musl (this is what I need patches for). On a
> glibc-based distro no patches are needed and you can use musl-clang wrapper
> to produce binaries linked against musl.
> >>
> >> Another way is using this
> >>
> >> with
> >>
> >>
> >> It shouldn't have problems but I did not test it lately.
> >>
> >> lu

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.