[cfe-users] crtbegin.o/crtend.o search path

邓尧 via cfe-users cfe-users at lists.llvm.org
Mon Sep 28 09:32:52 PDT 2015

Due to some non-technical issues, I have to work with some very old
Linux systems, mostly CentOS 6 installations, some are even older
which have CentOS 5 installations. I'm trying to create a
*self-hosting* toolchain with
clang/libc++/libc++abi/libunwind/compiler-rt/binutils, so I can
develop my applications with C++14 language standard and other nice
features provided by clang.

Note, I don't want to build libc myself, too much effort needed. I
just want a nice C++ development environment on top of the system

My steps are like this:
* Build gcc-5.2 with the system gcc and install it to /opt/extra (done)
* Verify the above gcc-5.2 installation (done)
* Build clang-3.7 with the installed gcc-5.2 and install it to
/opt/stage1 (done)
* Verify the clang-3.7 installation after removing the system gcc (fail)
* Rebuild clang-3.7 with clang-3.7 installed in /opt/stage1 (not yet tried)

The installed clang-3.7 cannot link a simple executable because it
failed to find crtbegin.o & crtend.o.

llvm, cfe, clang-tools-extra, compiler-rt, libcxx, libcxxabi,
libunwind and lld are built together with the cmake build system.
cmake command line options are:
CC=/my/gcc/wrapper CXX=/my/g++/wrapper \
    cmake -DCMAKE_INSTALL_PREFIX=/opt/stage1 \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_BINUTILS_INCDIR=/opt/extra/include \
    -DPYTHON_EXECUTABLE=/opt/extra/bin/python \

The two gcc/g++ wrappers are written myself, they are used to add some
extra -Wl,-rpath options to the linker, so that the ld.so can load the
right libstdc++.so.6/libgcc_s.so.1

Because I want a self-hosting toolchain, I don't want clang to search
the system path (/usr/lib) for crtbegin.o/crtend.o.

I have two questions:
1. How can I tell clang that these two files are under directory
/opt/extra ? I don't mind write a simple patch to clang, of course,
simpler solutions like build time options or command line options are
much better.
2. Since crtbegin.o/crtend.o are part of a compiler, why don't clang
provide one itself ? Google results showed that these two files seem
to be quite simple, are there any patent/copyright issues related ?

More information about the cfe-users mailing list