CoreCLR needs NetBSD build infrastructure
We need to set up a new build environment with the latest NetBSD 6.1.5 stable. I am currently setting this up on Interoute in Frankfurt -- will follow up in this issue once it is done.
A few challenges I have got so far.
- The clang provided in official binary package does not have libc++.
- So you have to compile your own
- libunwind does not have support for NetBSD
- It has to be ported to NetBSD before anything can even start.
- (I have got it to compile by doing dirty hacks. But I am sure it would not actually work as it is.)
- Also some works need to be done in CoreCLR
- A large part is related to the machine context and low level conventions
- Which is the same knowledge that people would need in order to port libunwind
- A large part is related to the machine context and low level conventions
My primary point is that, the lack of libunwind posed some additional challenge on this platform (OpenBSD might also be effected as well). Also from my perspective, NetBSD 7 Beta might be a little bit easier to setup.
@milizhang We do not use the clang's libc++ on Linux. Although we build using clang, it by default targets the libstdc++ library that's native to the system. So I guess it would be similar for the NetBSD.
@milizhang Regarding the libunwind, I've bumped into the following: http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/lib/libunwind/ I have not looked into it, but the server path suggests it would be a libunwind for the NetBSD. But there is another option, although it would require postponing the build a bit. The LLVM project also contains a libunwind in its libc++.abi compiler support library. See here: http://blog.llvm.org/2013/10/new-libunwind-implementation-in-libcabi.html The current problem here is that this library is not separate or easily separable from the rest of the libc++.abi, but there has been a decision that this library will be extracted and made available separately. See here: http://article.gmane.org/gmane.comp.compilers.llvm.devel/81577
Ah, the http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/lib/libunwind/ seems to actually be the one from the LLVM that's not separable yet.
NetBSD does have some unwind functions if I'm correct. Are the functions in pal_unwind.h all we need?
For clang, the problem is that the clang supplied in binary package uses libc++ by default. If we want to use libstdc++ we need to specify -stdlib=libstdc++.
No, we also need the low level unwind functions, like the unw_set_reg, unw_get_reg, unw_getcontext etc.
Regarding the clang, then it makes sense to use the libc++ if the clang is using it by default.
The weird part is that they supplied a clang++ which is configured to use libc++ by default, but they did not supply libc++.
LabMouse-U03$ clang++ 1.cc -o 1
1.cc:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
LabMouse-U03$ clang++ 1.cc -o 1 -stdlib=libstdc++
LabMouse-U03$ ./1
Test
This is currently what they have. I could not see any of the low-level interfaces.
/* $NetBSD: unwind.h,v 1.2.4.1 2015/01/25 00:19:45 martin Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _UNWIND_H_
#define _UNWIND_H_
#include <sys/cdefs.h>
__BEGIN_DECLS
struct _Unwind_Context;
struct _Unwind_Exception;
typedef int _Unwind_Reason_Code;
typedef void *_Unwind_Ptr;
typedef long _Unwind_Word;
#define _URC_NO_REASON 0
#define _URC_FOREIGN_EXCEPTION_CAUGHT 1
#define _URC_FATAL_PHASE2_ERROR 2
#define _URC_FATAL_PHASE1_ERROR 3
#define _URC_NORMAL_STOP 4
#define _URC_END_OF_STACK 5
#define _URC_HANDLER_FOUND 6
#define _URC_INSTALL_CONTEXT 7
#define _URC_CONTINUE_UNWIND 8
typedef _Unwind_Reason_Code
(*_Unwind_Trace_Fn)(struct _Unwind_Context *, void *);
#ifdef notyet
typedef _Unwind_Reason_Code
(*_Unwind_Stop_Fn)(struct _Unwind_Context *, void *);
#endif
_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
void _Unwind_DeleteException(struct _Unwind_Exception *);
void *_Unwind_FindEnclosingFunction(void *);
#ifdef notyet
_Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception *,
_Unwind_Stop_fn, void *);
#endif
_Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
_Unwind_Ptr _Unwind_GetIP(struct _Unwind_Context *);
_Unwind_Ptr _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
_Unwind_Ptr _Unwind_GetLanguageSpecificData(
struct _Unwind_Context *);
_Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
_Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *);
void _Unwind_Resume(struct _Unwind_Exception *);
_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception *);
void _Unwind_SetGR(struct _Unwind_Context *, int,
_Unwind_Ptr);
void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Ptr);
__END_DECLS
#endif /* _UNWIND_H_ */
Yes, this is the standard high level unwind. We need the low level stuff, which is in the libunwind.
Then unfortunately even the LLVM's unwind does not have it. The only choice would be the libunwind8.
I meant llvm libunwind, not the llvm unwind. That one has the low level stuff, but we would have to wait until it is made a separate library. The llvm unwind is build on top of the llvm libunwind.
OK I see it. It is here now: https://llvm.org/svn/llvm-project/libunwind/
Looks like it is already separated from libcxxabi, maybe it will be released as a separate project in 3.7.
I'm porting CoreCLR and other repositories in pkgsrc-wip.
cd /usr/pkgsrc/wip/coreclr-git && make
It will handle the dependencies.
Currently there is no libunwind.
We don't need libc++ (at least to my knowledge), wip/clang-git is capable to use libstdc++ on NetBSD.
Right now pkgsrc-wip/coreclr-git builds 7% of CoreCLR.
Could we please mark all NetBSD tickets with a label like 'NetBSD'.
I have built 23% of sources with pkgsrc-wip/coreclr-git with temporary kludges.
From now I cannot build more without libunwind.
I can build 87% of CoreCLR (according to CMake) with pkgsrc-wip/coreclr-git (it contains right now 22 local patches).
87% and 20 local patches