Hi,

I created a port for libc++, LLVM's C++ standard library.  I'm not
a port's guy, so bear with me if this is not up to the standard.

The port contains libc++, libc++abi for the low level support and
libunwind as unwinder.  As libc++ and libc++abi kind of depend on each
other's headers I have put them together into a single port.

The cmake Makefiles expect to be compiled as part of a bigger LLVM
project checkout, which is overkill in my opinion.  Thus I have
created my own Makefiles for it.  In theory they could, with a few
modifications, also work in base.

The unwinder is configured to use the Itanium-ABI for exception
handling.  With LLVM/Clang it would also be possible to make ARM use
that ABI for exception handling.

libc++ actually expects the xlocale API to exist.  As we cannot provide
it, we just use Newlib's wrappers that basically ignore any thread-
local locales.  As far as I can see this also breaks a few of the tests,
but it's probably ok as a first step.

Additionally LLVM has to be modified to include the correct C++ header
directory if it is told to use libc++ as stdlib.  I have also appended
that diff, though without any REVISION change to LLVM.

Patrick


libc++ testsuite results:

****************************************************
Results for /home/patrick/openbsd-ports/pobj/libc++-3.7.1/libcxx-3.7.1.src/test:
using clang version 3.7.1 (tags/RELEASE_371/final)
Target: amd64-unknown-openbsd5.9
Thread model: posix
with -std=c++11 -stdlib=libc++ 
-I/home/patrick/openbsd-ports/pobj/libc++-3.7.1/libcxx-3.7.1.src/test/support 
-I/home/patrick/openbsd-ports/pobj/libc++-3.7.1/libcxx-3.7.1.src/include 
-L/home/patrick/openbsd-ports/pobj/libc++-3.7.1/libcxx-3.7.1.src/lib
----------------------------------------------------
sections without tests   : 13
sections with failures   : 55
sections without failures: 1106
                       +   ----
total number of sections : 1174
----------------------------------------------------
number of tests failed   : 185
number of tests passed   : 4740
                       +   ----
total number of tests    : 4925
****************************************************


libc++abi testsuite results:

****************************************************
Results for 
/home/patrick/openbsd-ports/pobj/libc++-3.7.1/libcxx-3.7.1.src/libcxxabi/test:
using clang version 3.7.1 (tags/RELEASE_371/final)
Target: amd64-unknown-openbsd5.9
Thread model: posix
with -std=c++0x -stdlib=libc++
----------------------------------------------------
sections without tests   : 3
sections with failures   : 1
sections without failures: 0
                       +   ----
total number of sections : 4
----------------------------------------------------
number of tests failed   : 2
number of tests passed   : 39
                       +   ----
total number of tests    : 41
****************************************************


diff --git devel/libc++/Makefile devel/libc++/Makefile
new file mode 100644
index 0000000..9654917
--- /dev/null
+++ devel/libc++/Makefile
@@ -0,0 +1,56 @@
+# $OpenBSD$
+
+ONLY_FOR_ARCHS = amd64
+DPB_PROPERTIES = parallel
+
+COMMENT =      new implementation of the C++ standard library
+
+LLVM_V =       3.7.1
+DISTNAME =     libcxx-${LLVM_V}.src
+PKGNAME =      libc++-${LLVM_V}
+REVISION =     0
+CATEGORIES =   devel
+DISTFILES =    libcxx-${LLVM_V}.src${EXTRACT_SUFX} \
+               libcxxabi-${LLVM_V}.src${EXTRACT_SUFX} \
+               libunwind-${LLVM_V}.src${EXTRACT_SUFX}
+MASTER_SITES = http://www.llvm.org/releases/${LLVM_V}/
+EXTRACT_SUFX = .tar.xz
+
+SHARED_LIBS =  c++             1.0 \
+               c++abi          1.0
+
+# packager notes in http://llvm.org/docs/Packaging.html
+HOMEPAGE =     http://www.llvm.org/
+
+MAINTAINER=    Patrick Wildt <patr...@blueri.se>
+
+# BSD
+PERMIT_PACKAGE_CDROM = Yes
+
+WANTLIB =      c
+
+BUILD_DEPENDS +=       devel/llvm
+
+SEPARATE_BUILD =       Yes
+
+WRKDIST = ${WRKDIR}/${DISTNAME}
+MAKE_ENV += LIBCXX=${WRKSRC}
+MAKE_ENV += LIBCXXABI=${WRKSRC}/libcxxabi
+MAKE_ENV += LIBUNWIND=${WRKSRC}/libunwind
+
+post-extract:
+       mv ${WRKDIR}/libcxxabi-${LLVM_V}.src ${WRKSRC}/libcxxabi
+       mv ${WRKDIR}/libunwind-${LLVM_V}.src ${WRKSRC}/libunwind
+       mkdir -p ${WRKBUILD}/libcxx
+       mkdir -p ${WRKBUILD}/libcxxabi
+
+pre-build:
+       @printf "major=${LIBc++_VERSION:R}\nminor=${LIBc++_VERSION:E}\n" \
+           >${WRKBUILD}/libcxx/shlib_version
+       @printf "major=${LIBc++abi_VERSION:R}\nminor=${LIBc++abi_VERSION:E}\n" \
+           >${WRKBUILD}/libcxxabi/shlib_version
+       @cp ${FILESDIR}/Makefile ${WRKBUILD}/Makefile
+       @cp ${FILESDIR}/libcxx-Makefile ${WRKBUILD}/libcxx/Makefile
+       @cp ${FILESDIR}/libcxxabi-Makefile ${WRKBUILD}/libcxxabi/Makefile
+
+.include <bsd.port.mk>
diff --git devel/libc++/distinfo devel/libc++/distinfo
new file mode 100644
index 0000000..ac0d557
--- /dev/null
+++ devel/libc++/distinfo
@@ -0,0 +1,6 @@
+SHA256 (libcxx-3.7.1.src.tar.xz) = NX+9QojOmXM7oGrivsb1A0E9JYruuquLankSAeb38UQ=
+SHA256 (libcxxabi-3.7.1.src.tar.xz) = 
pH+q7ZD1d9qMo7XwRL6UWNNUpT+rAwA6RAhakStzqyo=
+SHA256 (libunwind-3.7.1.src.tar.xz) = 
tp9EUlPC5dPIvmq+N5NypS0iPg5aVSC3mYOGbAP5Sfs=
+SIZE (libcxx-3.7.1.src.tar.xz) = 995724
+SIZE (libcxxabi-3.7.1.src.tar.xz) = 507428
+SIZE (libunwind-3.7.1.src.tar.xz) = 59584
diff --git devel/libc++/files/Makefile devel/libc++/files/Makefile
new file mode 100644
index 0000000..32aef54
--- /dev/null
+++ devel/libc++/files/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD$
+
+.include <bsd.own.mk>
+
+SUBDIR= libcxx libcxxabi
+
+.include <bsd.subdir.mk>
diff --git devel/libc++/files/libcxx-Makefile devel/libc++/files/libcxx-Makefile
new file mode 100644
index 0000000..2510d6d
--- /dev/null
+++ devel/libc++/files/libcxx-Makefile
@@ -0,0 +1,187 @@
+HDRDIR=                ${LIBCXX}/include
+SRCDIR=                ${LIBCXX}/src
+AHDRDIR=       ${LIBCXXABI}/include
+UHDRDIR=       ${LIBUNWIND}/include
+CXXINCLUDEDIR= /usr/local/include/c++/v1
+
+.PATH: ${SRCDIR}
+
+LIB=           c++
+LIBDIR=                /usr/local/lib
+
+SRCS+=         algorithm.cpp\
+               bind.cpp\
+               chrono.cpp\
+               condition_variable.cpp\
+               debug.cpp\
+               exception.cpp\
+               future.cpp\
+               hash.cpp\
+               ios.cpp\
+               iostream.cpp\
+               locale.cpp\
+               memory.cpp\
+               mutex.cpp\
+               new.cpp\
+               random.cpp\
+               regex.cpp\
+               shared_mutex.cpp\
+               stdexcept.cpp\
+               string.cpp\
+               strstream.cpp\
+               system_error.cpp\
+               thread.cpp\
+               typeinfo.cpp\
+               utility.cpp\
+               valarray.cpp
+
+WARNS=         0
+CC=            clang
+CXX=           clang++
+CFLAGS+=       -nostdlib -DLIBCXXABI -I${HDRDIR} -I${SRCDIR}/include \
+               -DLIBCXX_BUILDING_LIBCXXABI -I${AHDRDIR} -I${UHDRDIR}
+CPPFLAGS+=     ${CFLAGS}
+.if empty(CXXFLAGS:M-std=*)
+CXXFLAGS+=     -std=c++11
+.endif
+
+LDFLAGS+=      --verbose
+INCSGROUPS=    STD EXT
+
+STD_HEADERS=   __bit_reference\
+               __config\
+               __debug\
+               __functional_03\
+               __functional_base\
+               __functional_base_03\
+               __hash_table\
+               __locale\
+               __mutex_base\
+               __refstring\
+               __split_buffer\
+               __sso_allocator\
+               __std_stream\
+               __tree\
+               __tuple\
+               __undef___deallocate\
+               __undef_min_max\
+               algorithm\
+               array\
+               atomic\
+               bitset\
+               cassert\
+               ccomplex\
+               cctype\
+               cerrno\
+               cfenv\
+               cfloat\
+               chrono\
+               cinttypes\
+               ciso646\
+               climits\
+               clocale\
+               cmath\
+               codecvt\
+               complex\
+               complex.h\
+               condition_variable\
+               csetjmp\
+               csignal\
+               cstdarg\
+               cstdbool\
+               cstddef\
+               cstdint\
+               cstdio\
+               cstdlib\
+               cstring\
+               ctgmath\
+               ctime\
+               cwchar\
+               cwctype\
+               deque\
+               exception\
+               forward_list\
+               fstream\
+               functional\
+               future\
+               initializer_list\
+               iomanip\
+               ios\
+               iosfwd\
+               iostream\
+               istream\
+               iterator\
+               limits\
+               list\
+               locale\
+               map\
+               memory\
+               mutex\
+               new\
+               numeric\
+               ostream\
+               queue\
+               random\
+               ratio\
+               regex\
+               scoped_allocator\
+               set\
+               shared_mutex\
+               sstream\
+               stack\
+               stdexcept\
+               streambuf\
+               string\
+               strstream\
+               system_error\
+               tgmath.h\
+               thread\
+               tuple\
+               type_traits\
+               typeindex\
+               typeinfo\
+               unordered_map\
+               unordered_set\
+               utility\
+               valarray\
+               vector
+
+.for hdr in ${STD_HEADERS}
+STD+=          ${hdr} ${HDRDIR}/${hdr}
+.endfor
+STDDIR=                ${CXXINCLUDEDIR}
+
+EXT_HEADERS=   __hash\
+               hash_map\
+               hash_set
+
+.for hdr in ${EXT_HEADERS}
+EXT+=          ${hdr} ${HDRDIR}/ext/${hdr}
+.endfor
+EXTDIR=                ${CXXINCLUDEDIR}/ext
+
+#includes:
+beforeinstall:
+       @echo installing ${STD_HEADERS}
+       ${INSTALL} -d -m 555 ${DESTDIR}/${STDDIR};
+.      for hdr src in ${STD}
+               cmp -s ${src} ${DESTDIR}/${STDDIR}/${hdr} || \
+               ${INSTALL} ${INSTALL_COPY} -m 444 ${src} 
${DESTDIR}/${STDDIR}/${hdr};
+.      endfor
+       ${INSTALL} -d -m 555 ${DESTDIR}/${EXTDIR};
+.      for hdr src in ${EXT}
+               cmp -s ${src} ${DESTDIR}/${EXTDIR}/${hdr} || \
+               ${INSTALL} ${INSTALL_COPY} -m 444 ${src} 
${DESTDIR}/${EXTDIR}/${hdr};
+.      endfor
+       ${INSTALL} -d -m 555 ${DESTDIR}/${CXXINCLUDEDIR}/support/newlib;
+       cmp -s ${HDRDIR}/support/newlib/xlocale.h \
+           ${DESTDIR}/${CXXINCLUDEDIR}/support/newlib/xlocale.h || \
+           ${INSTALL} ${INSTALL_COPY} -m 444 
${HDRDIR}/support/newlib/xlocale.h \
+           ${DESTDIR}/${CXXINCLUDEDIR}/support/newlib/xlocale.h;
+       ${INSTALL} -d -m 555 ${DESTDIR}/${CXXINCLUDEDIR}/support/xlocale;
+       cmp -s ${HDRDIR}/support/xlocale/xlocale.h \
+           ${DESTDIR}/${CXXINCLUDEDIR}/support/xlocale/xlocale.h || \
+           ${INSTALL} ${INSTALL_COPY} -m 444 
${HDRDIR}/support/xlocale/xlocale.h \
+           ${DESTDIR}/${CXXINCLUDEDIR}/support/xlocale/xlocale.h;
+
+.include <bsd.lib.mk>
diff --git devel/libc++/files/libcxxabi-Makefile 
devel/libc++/files/libcxxabi-Makefile
new file mode 100644
index 0000000..bd9a9e9
--- /dev/null
+++ devel/libc++/files/libcxxabi-Makefile
@@ -0,0 +1,91 @@
+HDRDIR=                ${LIBCXXABI}/include
+SRCDIR=                ${LIBCXXABI}/src
+SHDRDIR=       ${LIBCXX}/include
+UHDRDIR=       ${LIBUNWIND}/include
+CXXINCLUDEDIR= /usr/local/include/c++/v1
+
+.PATH: ${SRCDIR} ${LIBUNWIND}/src
+
+LIB=           c++abi
+LIBDIR=                /usr/local/lib
+
+SRCS+=         abort_message.cpp\
+               cxa_aux_runtime.cpp\
+               cxa_default_handlers.cpp\
+               cxa_demangle.cpp\
+               cxa_exception.cpp\
+               cxa_exception_storage.cpp\
+               cxa_guard.cpp\
+               cxa_handlers.cpp\
+               cxa_new_delete.cpp\
+               cxa_personality.cpp\
+               cxa_thread_atexit.cpp\
+               cxa_unexpected.cpp\
+               cxa_vector.cpp\
+               cxa_virtual.cpp\
+               exception.cpp\
+               private_typeinfo.cpp\
+               stdexcept.cpp\
+               typeinfo.cpp\
+               Unwind-EHABI.cpp\
+               Unwind-sjlj.c\
+               UnwindLevel1-gcc-ext.c\
+               UnwindLevel1.c\
+               UnwindRegistersRestore.S\
+               UnwindRegistersSave.S\
+               libunwind.cpp
+
+WARNS=         0
+CC=            clang
+CXX=           clang++
+CFLAGS+=       -nostdlib -I${SHDRDIR} -funwind-tables -I${HDRDIR} -I${UHDRDIR}
+CPPFLAGS+=     ${CFLAGS}
+.if empty(CXXFLAGS:M-std=*)
+CXXFLAGS+=     -std=c++11
+.endif
+
+STD_HEADERS=   cxxabi.h \
+               __cxxabi_config.h
+
+.for hdr in ${STD_HEADERS}
+STD+=          ${hdr} ${HDRDIR}/${hdr}
+.endfor
+STDDIR=                ${CXXINCLUDEDIR}
+
+# Libunwind stuff
+STD_UHEADERS=  libunwind.h \
+               __libunwind_config.h \
+               unwind.h
+
+.for hdr in ${STD_UHEADERS}
+USTD+=         ${hdr} ${UHDRDIR}/${hdr}
+.endfor
+USTDDIR=       ${CXXINCLUDEDIR}
+
+MACHO_HEADERS=compact_unwind_encoding.h
+
+.for hdr in ${MACHO_HEADERS}
+MACHO+=                ${hdr} ${UHDRDIR}/mach-o/${hdr}
+.endfor
+MACHODIR=      ${CXXINCLUDEDIR}/mach-o
+
+#includes:
+beforeinstall:
+       @echo installing ${STD_HEADERS}
+       ${INSTALL} -d -m 555 ${DESTDIR}/${STDDIR};
+.      for hdr src in ${STD}
+               cmp -s ${src} ${DESTDIR}/${STDDIR}/${hdr} || \
+               ${INSTALL} ${INSTALL_COPY} -m 444 ${src} 
${DESTDIR}/${STDDIR}/${hdr};
+.      endfor
+       ${INSTALL} -d -m 555 ${DESTDIR}/${USTDDIR};
+.      for hdr src in ${USTD}
+               cmp -s ${src} ${DESTDIR}/${USTDDIR}/${hdr} || \
+               ${INSTALL} ${INSTALL_COPY} -m 444 ${src} 
${DESTDIR}/${USTDDIR}/${hdr};
+.      endfor
+       ${INSTALL} -d -m 555 ${DESTDIR}/${MACHODIR};
+.      for hdr src in ${MACHO}
+               cmp -s ${src} ${DESTDIR}/${MACHODIR}/${hdr} || \
+               ${INSTALL} ${INSTALL_COPY} -m 444 ${src} 
${DESTDIR}/${MACHODIR}/${hdr};
+.      endfor
+
+.include <bsd.lib.mk>
diff --git devel/libc++/patches/patch-include___config 
devel/libc++/patches/patch-include___config
new file mode 100644
index 0000000..b3a20d7
--- /dev/null
+++ devel/libc++/patches/patch-include___config
@@ -0,0 +1,30 @@
+$OpenBSD$
+--- include/__config.orig      Fri Jul 17 02:58:59 2015
++++ include/__config   Fri May 13 15:51:23 2016
+@@ -87,6 +87,17 @@
+ # define _LIBCPP_HAS_QUICK_EXIT
+ #endif  // __NetBSD__
+ 
++#ifdef __OpenBSD__
++# include <sys/endian.h>
++#  if _BYTE_ORDER == _LITTLE_ENDIAN
++#   define _LIBCPP_LITTLE_ENDIAN 1
++#   define _LIBCPP_BIG_ENDIAN    0
++# else  // _BYTE_ORDER == _LITTLE_ENDIAN
++#   define _LIBCPP_LITTLE_ENDIAN 0
++#   define _LIBCPP_BIG_ENDIAN    1
++# endif  // _BYTE_ORDER == _LITTLE_ENDIAN
++#endif  // __OpenBSD__
++
+ #ifdef _WIN32
+ #  define _LIBCPP_LITTLE_ENDIAN 1
+ #  define _LIBCPP_BIG_ENDIAN    0
+@@ -757,7 +768,7 @@ extern "C" void __sanitizer_annotate_contiguous_contai
+ #define _LIBCPP_HAS_NO_STDOUT
+ #endif
+ 
+-#if defined(__ANDROID__) || defined(__CloudABI__)
++#if defined(__ANDROID__) || defined(__CloudABI__) || defined(__OpenBSD__)
+ #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
+ #endif
+ 
diff --git devel/libc++/patches/patch-include___locale 
devel/libc++/patches/patch-include___locale
new file mode 100644
index 0000000..d4bbdf0
--- /dev/null
+++ devel/libc++/patches/patch-include___locale
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- include/__locale.orig      Wed Mar 11 18:00:28 2015
++++ include/__locale   Fri May 13 15:49:28 2016
+@@ -32,7 +32,7 @@
+ #elif defined(__sun__)
+ # include <xlocale.h>
+ # include <support/solaris/xlocale.h>
+-#elif defined(_NEWLIB_VERSION)
++#elif defined(_NEWLIB_VERSION) || defined(__OpenBSD__)
+ # include <support/newlib/xlocale.h>
+ #elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
diff --git devel/libc++/patches/patch-include_cstdio 
devel/libc++/patches/patch-include_cstdio
new file mode 100644
index 0000000..17a1d84
--- /dev/null
+++ devel/libc++/patches/patch-include_cstdio
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- include/cstdio.orig        Thu Mar 26 15:35:46 2015
++++ include/cstdio     Fri May 13 15:49:28 2016
+@@ -190,7 +190,7 @@ using ::tmpnam;
+ 
+ #ifndef _LIBCPP_HAS_NO_STDIN
+ using ::getchar;
+-#if _LIBCPP_STD_VER <= 11
++#if _LIBCPP_STD_VER <= 11  && !defined(__OpenBSD__)
+ using ::gets;
+ #endif
+ using ::scanf;
diff --git devel/libc++/patches/patch-include_locale 
devel/libc++/patches/patch-include_locale
new file mode 100644
index 0000000..836fe27
--- /dev/null
+++ devel/libc++/patches/patch-include_locale
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- include/locale.orig        Fri May 13 15:55:21 2016
++++ include/locale     Fri May 13 15:57:13 2016
+@@ -236,7 +236,7 @@ typedef _VSTD::unique_ptr<__locale_struct, decltype(&u
+ // locale.  Linux, not so much.  The following functions avoid the locale when
+ // that's possible and otherwise do the wrong thing.  FIXME.
+ #if defined(__linux__) || defined(__EMSCRIPTEN__) || defined(_AIX) || \
+-    defined(_NEWLIB_VERSION) || defined(__GLIBC__)
++    defined(_NEWLIB_VERSION) || defined(__GLIBC__) || defined(__OpenBSD__)
+ 
+ #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+ decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
diff --git devel/libc++/patches/patch-include_support_newlib_xlocale_h 
devel/libc++/patches/patch-include_support_newlib_xlocale_h
new file mode 100644
index 0000000..6a28191
--- /dev/null
+++ devel/libc++/patches/patch-include_support_newlib_xlocale_h
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- include/support/newlib/xlocale.h.orig      Fri Sep 19 22:09:12 2014
++++ include/support/newlib/xlocale.h   Fri May 13 15:49:28 2016
+@@ -10,7 +10,7 @@
+ #ifndef _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H
+ #define _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H
+ 
+-#if defined(_NEWLIB_VERSION)
++#if defined(_NEWLIB_VERSION) || defined(__OpenBSD__)
+ 
+ #include <cstdlib>
+ #include <clocale>
diff --git devel/libc++/patches/patch-libunwind_src_AddressSpace_hpp 
devel/libc++/patches/patch-libunwind_src_AddressSpace_hpp
new file mode 100644
index 0000000..c3507d2
--- /dev/null
+++ devel/libc++/patches/patch-libunwind_src_AddressSpace_hpp
@@ -0,0 +1,108 @@
+$OpenBSD$
+--- libunwind/src/AddressSpace.hpp.orig        Tue Jul 28 18:22:09 2015
++++ libunwind/src/AddressSpace.hpp     Fri May 13 17:21:13 2016
+@@ -343,6 +343,85 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t en
+   #endif
+ #endif
+ 
++#if __OpenBSD__
++  #include <link_elf.h>
++  #define PT_EH_FRAME_HDR (PT_LOOS + 0x474e550)
++
++  struct dl_unwind_sections
++  {
++    uintptr_t                    base;
++    const void                  *dwarf_section;
++    uintptr_t                    dwarf_section_length;
++    const void                  *compact_unwind_section;
++    uintptr_t                    compact_unwind_section_length;
++  };
++
++  struct eh_frame_hdr
++  {
++    uint8_t version;
++    uint8_t eh_frame_ptr_enc;
++    uint8_t fde_count_enc;
++    uint8_t table_enc;
++    uint8_t data[0];
++  };
++
++  struct _dl_iterate_struct
++  {
++    Elf_Addr                   addr;
++    Elf_Addr                   base;
++    Elf_Phdr                  *eh_frame_hdr;
++  };
++
++  static int _dl_iterate_cb(struct dl_phdr_info *dlpi, size_t size, void* 
data) {
++    struct _dl_iterate_struct *dlis = (struct _dl_iterate_struct *)data;
++    Elf_Phdr *phdr = (Elf_Phdr *)dlpi->dlpi_phdr;
++    int idx, found = 0;
++
++    for (idx = 0; idx < dlpi->dlpi_phnum; idx++, phdr++) {
++      if (phdr->p_type == PT_LOAD) {
++        Elf_Addr vaddr = dlpi->dlpi_addr + phdr->p_vaddr;
++        if (dlis->addr >= vaddr && dlis->addr < (vaddr + phdr->p_memsz))
++          found = 1;
++      } else if (phdr->p_type == PT_EH_FRAME_HDR)
++        dlis->eh_frame_hdr = phdr;
++    }
++
++    dlis->base = dlpi->dlpi_addr;
++    return found;
++  }
++
++  static inline bool _dl_find_unwind_sections(void *addr,
++      dl_unwind_sections *info) {
++
++    LocalAddressSpace::pint_t encoded, end;
++    struct _dl_iterate_struct dlis;
++    struct eh_frame_hdr *ehfh;
++    Elf_Phdr *phdr;
++    int idx;
++
++    dlis.addr = (Elf_Addr)addr;
++    if (!dl_iterate_phdr(_dl_iterate_cb, &dlis))
++      return false;
++
++    phdr = (Elf_Phdr *)dlis.eh_frame_hdr;
++    ehfh = (struct eh_frame_hdr *)(dlis.base + phdr->p_vaddr);
++
++    encoded = (LocalAddressSpace::pint_t)&ehfh->data;
++    end = (LocalAddressSpace::pint_t)ehfh + phdr->p_memsz;
++
++    // Fill in return struct.
++    info->base = dlis.base;
++    info->dwarf_section = (const void *)LocalAddressSpace::sThisAddressSpace
++        .getEncodedP(encoded, end, ehfh->eh_frame_ptr_enc);
++    /* XXX: We don't know how big it is, shouldn't be bigger than this. */
++    info->dwarf_section_length = 0x00ffffff;
++    info->compact_unwind_section = 0;
++    info->compact_unwind_section_length = 0;
++
++    return true;
++  }
++#endif
++
+ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
+                                                   UnwindInfoSections &info) {
+ #ifdef __APPLE__
+@@ -355,6 +434,18 @@ inline bool LocalAddressSpace::findUnwindSections(pint
+  #endif
+     info.compact_unwind_section        = 
(uintptr_t)dyldInfo.compact_unwind_section;
+     info.compact_unwind_section_length = 
dyldInfo.compact_unwind_section_length;
++    return true;
++  }
++#elif __OpenBSD__
++  dl_unwind_sections dlInfo;
++  if (_dl_find_unwind_sections((void *)targetAddr, &dlInfo)) {
++    info.dso_base                      = (uintptr_t)dlInfo.base;
++ #if _LIBUNWIND_SUPPORT_DWARF_UNWIND
++    info.dwarf_section                 = (uintptr_t)dlInfo.dwarf_section;
++    info.dwarf_section_length          = dlInfo.dwarf_section_length;
++ #endif
++    info.compact_unwind_section        = 
(uintptr_t)dlInfo.compact_unwind_section;
++    info.compact_unwind_section_length = dlInfo.compact_unwind_section_length;
+     return true;
+   }
+ #elif _LIBUNWIND_ARM_EHABI
diff --git devel/libc++/patches/patch-libunwind_src_config_h 
devel/libc++/patches/patch-libunwind_src_config_h
new file mode 100644
index 0000000..dbc3a2f
--- /dev/null
+++ devel/libc++/patches/patch-libunwind_src_config_h
@@ -0,0 +1,22 @@
+$OpenBSD$
+--- libunwind/src/config.h.orig        Fri Apr 24 21:39:17 2015
++++ libunwind/src/config.h     Fri May 13 17:22:51 2016
+@@ -60,6 +60,18 @@
+     #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
+   #endif
+ 
++#elif __OpenBSD__
++  #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || 
__arm64__ || __arm__)
++  #define _LIBUNWIND_BUILD_SJLJ_APIS      0
++  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
++  #define _LIBUNWIND_EXPORT               
__attribute__((visibility("default")))
++  #define _LIBUNWIND_HIDDEN               
__attribute__((visibility("hidden")))
++  #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, 
__VA_ARGS__)
++  #define _LIBUNWIND_ABORT(msg) __assert2(__FILE__, __LINE__, __func__, msg)
++  #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
++  #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   1
++  #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
++
+ #else
+   #include <stdlib.h>
+ 
diff --git devel/libc++/pkg/DESCR devel/libc++/pkg/DESCR
new file mode 100644
index 0000000..bfa8bdf
--- /dev/null
+++ devel/libc++/pkg/DESCR
@@ -0,0 +1,2 @@
+libc++ is a new implementation of the C++ standard library,
+targeting C++11.
diff --git devel/libc++/pkg/PLIST devel/libc++/pkg/PLIST
new file mode 100644
index 0000000..c3370ae
--- /dev/null
+++ devel/libc++/pkg/PLIST
@@ -0,0 +1,122 @@
+@comment $OpenBSD$
+include/c++/
+include/c++/v1/
+include/c++/v1/__bit_reference
+include/c++/v1/__config
+include/c++/v1/__cxxabi_config.h
+include/c++/v1/__debug
+include/c++/v1/__functional_03
+include/c++/v1/__functional_base
+include/c++/v1/__functional_base_03
+include/c++/v1/__hash_table
+include/c++/v1/__libunwind_config.h
+include/c++/v1/__locale
+include/c++/v1/__mutex_base
+include/c++/v1/__refstring
+include/c++/v1/__split_buffer
+include/c++/v1/__sso_allocator
+include/c++/v1/__std_stream
+include/c++/v1/__tree
+include/c++/v1/__tuple
+include/c++/v1/__undef___deallocate
+include/c++/v1/__undef_min_max
+include/c++/v1/algorithm
+include/c++/v1/array
+include/c++/v1/atomic
+include/c++/v1/bitset
+include/c++/v1/cassert
+include/c++/v1/ccomplex
+include/c++/v1/cctype
+include/c++/v1/cerrno
+include/c++/v1/cfenv
+include/c++/v1/cfloat
+include/c++/v1/chrono
+include/c++/v1/cinttypes
+include/c++/v1/ciso646
+include/c++/v1/climits
+include/c++/v1/clocale
+include/c++/v1/cmath
+include/c++/v1/codecvt
+include/c++/v1/complex
+include/c++/v1/complex.h
+include/c++/v1/condition_variable
+include/c++/v1/csetjmp
+include/c++/v1/csignal
+include/c++/v1/cstdarg
+include/c++/v1/cstdbool
+include/c++/v1/cstddef
+include/c++/v1/cstdint
+include/c++/v1/cstdio
+include/c++/v1/cstdlib
+include/c++/v1/cstring
+include/c++/v1/ctgmath
+include/c++/v1/ctime
+include/c++/v1/cwchar
+include/c++/v1/cwctype
+include/c++/v1/cxxabi.h
+include/c++/v1/deque
+include/c++/v1/exception
+include/c++/v1/ext/
+include/c++/v1/ext/__hash
+include/c++/v1/ext/hash_map
+include/c++/v1/ext/hash_set
+include/c++/v1/forward_list
+include/c++/v1/fstream
+include/c++/v1/functional
+include/c++/v1/future
+include/c++/v1/initializer_list
+include/c++/v1/iomanip
+include/c++/v1/ios
+include/c++/v1/iosfwd
+include/c++/v1/iostream
+include/c++/v1/istream
+include/c++/v1/iterator
+include/c++/v1/libunwind.h
+include/c++/v1/limits
+include/c++/v1/list
+include/c++/v1/locale
+include/c++/v1/mach-o/
+include/c++/v1/mach-o/compact_unwind_encoding.h
+include/c++/v1/map
+include/c++/v1/memory
+include/c++/v1/mutex
+include/c++/v1/new
+include/c++/v1/numeric
+include/c++/v1/ostream
+include/c++/v1/queue
+include/c++/v1/random
+include/c++/v1/ratio
+include/c++/v1/regex
+include/c++/v1/scoped_allocator
+include/c++/v1/set
+include/c++/v1/shared_mutex
+include/c++/v1/sstream
+include/c++/v1/stack
+include/c++/v1/stdexcept
+include/c++/v1/streambuf
+include/c++/v1/string
+include/c++/v1/strstream
+include/c++/v1/support/
+include/c++/v1/support/newlib/
+include/c++/v1/support/newlib/xlocale.h
+include/c++/v1/support/xlocale/
+include/c++/v1/support/xlocale/xlocale.h
+include/c++/v1/system_error
+include/c++/v1/tgmath.h
+include/c++/v1/thread
+include/c++/v1/tuple
+include/c++/v1/type_traits
+include/c++/v1/typeindex
+include/c++/v1/typeinfo
+include/c++/v1/unordered_map
+include/c++/v1/unordered_set
+include/c++/v1/unwind.h
+include/c++/v1/utility
+include/c++/v1/valarray
+include/c++/v1/vector
+lib/libc++.a
+@lib lib/libc++.so.${LIBc++_VERSION}
+lib/libc++_p.a
+lib/libc++abi.a
+@lib lib/libc++abi.so.${LIBc++abi_VERSION}
+lib/libc++abi_p.a
diff --git devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_cpp 
devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_cpp
index 79587cc..65b74ce 100644
--- devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_cpp
+++ devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_cpp
@@ -1,7 +1,7 @@
 $OpenBSD: patch-tools_clang_lib_Driver_ToolChains_cpp,v 1.5 2016/03/05 
15:31:41 pascal Exp $
 --- tools/clang/lib/Driver/ToolChains.cpp.orig Tue Jul 14 01:27:56 2015
-+++ tools/clang/lib/Driver/ToolChains.cpp      Sat Sep 12 14:00:16 2015
-@@ -2538,6 +2538,50 @@ Tool *OpenBSD::buildAssembler() const {
++++ tools/clang/lib/Driver/ToolChains.cpp      Fri May 13 14:45:38 2016
+@@ -2538,6 +2538,56 @@ Tool *OpenBSD::buildAssembler() const {
  
  Tool *OpenBSD::buildLinker() const { return new 
tools::openbsd::Linker(*this); }
  
@@ -24,15 +24,21 @@ $OpenBSD: patch-tools_clang_lib_Driver_ToolChains_cpp,v 1.5 
2016/03/05 15:31:41
 +      DriverArgs.hasArg(options::OPT_nostdincxx))
 +    return;
 +
-+  /* XXX handle libc++ includes */
-+
-+  addSystemInclude(DriverArgs, CC1Args,
-+                   getDriver().SysRoot + 
"${LOCALBASE}/include/c++/${GCC_VER}");
++  switch (GetCXXStdlibType(DriverArgs)) {
++  case ToolChain::CST_Libcxx:
++    addSystemInclude(DriverArgs, CC1Args,
++                     getDriver().SysRoot + "${LOCALBASE}/include/c++/v1");
++    break;
++  case ToolChain::CST_Libstdcxx:
++    addSystemInclude(DriverArgs, CC1Args,
++                     getDriver().SysRoot + 
"${LOCALBASE}/include/c++/${GCC_VER}");
 +
-+  addSystemInclude(DriverArgs, CC1Args,
-+                   getDriver().SysRoot + 
"${LOCALBASE}/include/c++/${GCC_VER}/${GCC_CONFIG}");
-+  addSystemInclude(DriverArgs, CC1Args,
-+                   getDriver().SysRoot + 
"${LOCALBASE}/include/c++/${GCC_VER}/backward");
++    addSystemInclude(DriverArgs, CC1Args,
++                     getDriver().SysRoot + 
"${LOCALBASE}/include/c++/${GCC_VER}/${GCC_CONFIG}");
++    addSystemInclude(DriverArgs, CC1Args,
++                     getDriver().SysRoot + 
"${LOCALBASE}/include/c++/${GCC_VER}/backward");
++    break;
++  }
 +}
 +
 +void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,


Reply via email to