[cfe-dev] unraveling libcxxabi/libcxx

David Fang fang at csl.cornell.edu
Wed Apr 3 01:11:29 PDT 2013


Some success here compiling and linking libc++abi.

I whipped up a Makefile (attached) and tweaked some flags, a bunch of 
variables defined to my environment.
My compile looks like:

ccache /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang++ -gdwarf2 
-O0  -std=c++0x -stdlib=libc++ -fstrict-aliasing -Wstrict-aliasing=2 
-Wsign-conversion -Wshadow -Wconversion -Wunused-variable 
-Wmissing-field-initializers -Wchar-subscripts -Wmismatched-tags 
-Wmissing-braces -Wshorten-64-to-32 -Wsign-compare -Wstrict-aliasing=2 
-Wstrict-overflow=4 -Wunused-parameter -Wnewline-eof -fPIC -fno-common 
-no-integrated-as -I../include 
-I/Users/fang/local/src/LLVM-svn/libcxx.git/include 
-I/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include -c ../src/typeinfo.cpp 
-o typeinfo.o

ccache /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang++ 
-dynamiclib -nodefaultlibs -current_version 1 -compatibility_version 1 
-install_name /usr/local/experimental/llvm/lib/libc++abi.1.dylib -lSystem 
-lgcc_s.10.4 abort_message.o cxa_aux_runtime.o cxa_default_handlers.o 
cxa_demangle.o cxa_exception.o cxa_exception_storage.o cxa_guard.o 
cxa_handlers.o cxa_new_delete.o cxa_personality.o cxa_unexpected.o 
cxa_vector.o cxa_virtual.o exception.o private_typeinfo.o stdexcept.o 
typeinfo.o -o libc++abi.1.dylib

I used -O0 because -O1 is buggy (bug 14579).
-gdwarf2 because that's what old /usr/bin/ld can understand.
-fno-common for targeting dylibs.
-no-integrated-as because integrated-as was giving me a few relocation 
entries in non-writable sections (__TEXT,__eh_frame).

After installation:
% otool -L /usr/local/experimental/llvm/lib/libc++abi.dylib
/usr/local/experimental/llvm/lib/libc++abi.dylib:
 	/usr/local/experimental/llvm/lib/libc++abi.1.dylib (compatibility 
version 1.0.0, current version 1.0.0)
 	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current 
version 88.1.12)
 	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current 
version 1.0.0)

Next, I'll need to run tests, after I understand what 'testit' is doing, 
and after some sleep.  :)

Fang

> On Apr 2, 2013, at 9:04 PM, David Fang <fang at csl.cornell.edu> wrote:
>
>> Hi,
>>
>>>> I'm currently looking into porting libcxx to an ancient system
>>>> (powerpc-darwin8), and I noticed that libcxx depends on libcxxabi. However, libcxxabi's sources include headers like <exception> which are expected to be in some C++ library.  Does it (mutually) depend on libcxx? Maybe this was obvious, but I take it libcxxabi needs a c++11 compiler to build, correct?  (This would be fine, as I have stage-1 clang built from gcc-4.0/libstdc++.)  Does one {libcxx,libcxxabi} need to be installed before the other, or should they be built cross-referencing each others include dirs? In terms of shared-library dependencies, libcxx should link to libcxxabi, right?
>>>>
>>>> Is there better documentation somewhere that I don't know about? All I see are html pages at http://libcxxabi.llvm.org and http://libcxx.llvm.org/.
>>>
>>> Contributions to better documentation (and your experiences in doing this) are welcome. :-)
>>
>> Sure, once I have a better understanding (and success). (And maybe along with it some Makefile/autotool files...)
>>
>>> Yes, libcxxabi is the lower-level library.  libcxx should link to libcxxabi.
>>>
>>> Yes, currently libcxxabi is using -std=c++0x and probably needs it, though I can't think offhand of a specific need.  If you need to, try changing that to -std=c++03.  If there's any breakage it will almost certainly be compile-time breakage.  So that is a safe experiment.
>>
>> One symbol that is referenced is std::get_unexpected(), which is both new and deprecated in c++11.
>
> Yeah, my motto is:  If you're going to standardize, do it with sense of humor. :-)
>
>> Another c++11 symbol needed is std::get_terminate().  I discovered this when I tried to use g++-4.0's libstdc++ headers and got compilation errors.
>>
>>> libcxxabi is designed to be ABI compatible with a gcc-4.2 era libstdc++. And therefore could almost certainly use a libstdc++-4.2 set of headers if need be to build against (another untested theory).
>>
>> I also encountered:
>> ../src/cxa_exception.hpp:66:9: error: unknown type name '_Unwind_Exception'
>>
>> and a search led me to various versions of "unwind.h".
>> The one in clang does some include_next magic.
>> I did however find one buried in /usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include/unwind.h
>> with the needed typedef.
>> I'm trying that now, but stop me if I'm going down a wrong path!
>
> This is a serious problem.  The unwind library is a part of the Itanium ABI, a public specification of the API:  http://mentorembedded.github.com/cxx-abi/
>
> But at this point in time, Apple does not open source this part of the API (to the best of my knowledge anyway).  There may or may not be other open source implementations of this part of the API, I honestly do not know (maybe others here do?).
>
>>
>>> As libcxxabi is the lower-level library, I would go with installing that first.  But understand you're traversing territory where few have gone before.
>>
>> I'll try this, pointing to libcxx's headers just for the prototypes that are needed from <exception>.  As you said, there should be no symbol dependence to libcxx.
>
> <nod>
>
> Howard
>

-- 
David Fang
http://www.csl.cornell.edu/~fang/
-------------- next part --------------
# "lib/Makefile.darwin" -- for libcxxabi

.SUFFIXES: .cpp .o
VPATH = ../src
SRCDIR = ../src
CCACHE = ccache
CLANG_BUILDDIR = /Volumes/Isolde/builds/LLVM/gcc40-cmake-build
CLANG_PATH = ${CLANG_BUILDDIR}/bin
TRIPLE = powerpc-apple-darwin8
CXX = ${CCACHE} ${CLANG_PATH}/clang++
CC = ${CCACHE} ${CLANG_PATH}/clang
CXXLD = ${CXX}
RC_ProjectSourceVersion ?= 1
PREFIX = /usr/local/experimental/llvm
LIBDIR = ${PREFIX}/lib
SOEXT = dylib

# CXXLIB_ROOT = /usr/include/c++/4.0.0
# CXXLIB_INCLUDES = -I${CXXLIB_ROOT} -I${CXXLIB_ROOT}/${TRIPLE}
UNWIND_INCLUDES = -I/usr/lib/gcc/${TRIPLE}/4.0.1/include

CXXLIB_ROOT = /Users/fang/local/src/LLVM-svn/libcxx.git/include
# libcxx's include/__config defines _NOEXCEPT
CXXLIB_INCLUDES = -I${CXXLIB_ROOT}
# UNWIND_INCLUDES = -I/usr/local/experimental/llvm/lib/clang/3.3/include

CXXCPPFLAGS = -I../include ${CXXLIB_INCLUDES} ${UNWIND_INCLUDES}
CXXFLAGS = -std=c++0x -stdlib=libc++ -fstrict-aliasing -Wstrict-aliasing=2 \
	-Wsign-conversion -Wshadow -Wconversion -Wunused-variable \
	-Wmissing-field-initializers -Wchar-subscripts -Wmismatched-tags \
	-Wmissing-braces -Wshorten-64-to-32 -Wsign-compare \
	-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter \
	-Wnewline-eof
CXXFLAGS += -fPIC -fno-common
CXXFLAGS += -no-integrated-as
# CXXFLAGS += -isysroot ${SDKROOT}
# CXXFLAGS += -save-temps -triple ${TRIPLE}

# ARCHS = -arch i386 -arch x86_64
# ARCHS = -arch ppc

OFLAGS = -gdwarf2 -O0
# OFLAGS = -g -O3

LDFLAGS = \
        -dynamiclib -nodefaultlibs  \
        -current_version ${RC_ProjectSourceVersion} \
        -compatibility_version 1 \
        -install_name ${LIBDIR}/$@ \
        -lSystem \
	-lgcc_s.10.4

#	if [ -f "${SDKROOT}/usr/local/lib/libCrashReporterClient.a" ]
#	then
#		LDFLAGS+=" -lCrashReporterClient"
#	fi

TARGET = libc++abi.${RC_ProjectSourceVersion}.${SOEXT}
all: ${TARGET}

.cpp.o:
	${CXX} ${OFLAGS} ${ARCHS} ${CXXFLAGS} ${CXXCPPFLAGS} -c $< -o $@

OBJS = \
	abort_message.o \
	cxa_aux_runtime.o \
	cxa_default_handlers.o \
	cxa_demangle.o \
	cxa_exception.o \
	cxa_exception_storage.o \
	cxa_guard.o \
	cxa_handlers.o \
	cxa_new_delete.o \
	cxa_personality.o \
	cxa_unexpected.o \
	cxa_vector.o \
	cxa_virtual.o \
	exception.o \
	private_typeinfo.o \
	stdexcept.o \
	typeinfo.o

${TARGET}: ${OBJS}
	${CXXLD} ${ARCHS} ${LDFLAGS} ${OBJS} -o $@

install:
	cp ${TARGET} ${LIBDIR}
	pushd ${LIBDIR} ; ln -f -s ${TARGET} libc++abi.dylib ; popd
# alternatively, run install_name_tool after installation

clean:
	rm -f *.o
	rm -f *.dylib



More information about the cfe-dev mailing list