From owner-freebsd-arch@freebsd.org Fri Jun 29 14:14:42 2018 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 916FCEF8DEA for ; Fri, 29 Jun 2018 14:14:42 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 22CC98CD3F for ; Fri, 29 Jun 2018 14:14:42 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: by mailman.ysv.freebsd.org (Postfix) id D757BEF8DE6; Fri, 29 Jun 2018 14:14:41 +0000 (UTC) Delivered-To: arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B4CE8EF8DE5 for ; Fri, 29 Jun 2018 14:14:41 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-yb0-x236.google.com (mail-yb0-x236.google.com [IPv6:2607:f8b0:4002:c09::236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F4AD8CD37 for ; Fri, 29 Jun 2018 14:14:41 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: by mail-yb0-x236.google.com with SMTP id r3-v6so3412232ybo.4 for ; Fri, 29 Jun 2018 07:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=ZjzBi1zAUIYAqye8y5dNJDMzgQLOM3yeU44v2KToj1Q=; b=TBzdqPSMx7pczVeluR3ZUo9OU5tQ4coe7loARABHwZfu0UInd8uwm43/OkzUqMeDiC Q2yFPab3wLnsncNcwXm8mRsQF7z/MWkun6adcquHpNWVPPiPp/LjOPBhxrMiw34DjgaH +XKmeEfx3+oSLbtuvkFo95c5d3d94guvWe2Ws= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=ZjzBi1zAUIYAqye8y5dNJDMzgQLOM3yeU44v2KToj1Q=; b=kt/HEYK1yNEwt9gUZr1uM/fJvhXc//03lt6GSKs8DS2DeCrCupvvxhkreCm4lDgGBL ABVEp4e2a74FmYkIBLQGEEDFRd7cGodbzHQ6moy1l02r0QY+/Jxek5kJjEgm1sZAGB/F s9eXYz+rBYGfrGgGKhqov5+q7qxBXdx2Eg+95//hVnR2IHaIpYyyCQhvjgrjL8qN/FSR tNdqQsrWBA7CA34vO+Nhx94NO/LEJkrltllCssRDcfcOvnLFGUcVvfnjGDShWpFxS6en TtXMmKQA8/WEmR6MmQlBi7Ocg5ph2eLFKqRpOhVyViYS0zjLp0pERjai1oDcs9yRLfhr A6Fg== X-Gm-Message-State: APt69E14dn3wXzvEBI8tP1wCSOVh3Quy2iLMPfeAAY9MkY1V6AaaI+lw YD03unQWSaR/C0fNFFy0UbtEDnoY4IEvp/5CLCa0tg== X-Google-Smtp-Source: ADUXVKKma1X4we7KNCVJUgRk/KUNULMun/evWNcRxq77qZl+zH6/p1MNOVGJvTHBrpd7SLhqLbROx2Djk3TNDcg6jtw= X-Received: by 2002:a25:9b09:: with SMTP id y9-v6mr7540449ybn.194.1530281680474; Fri, 29 Jun 2018 07:14:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:ef50:0:0:0:0:0 with HTTP; Fri, 29 Jun 2018 07:14:09 -0700 (PDT) In-Reply-To: References: From: Eitan Adler Date: Fri, 29 Jun 2018 07:14:09 -0700 Message-ID: Subject: Re: C++ in the kernel? To: "freebsd-arch@freebsd.org" , David Chisnall , Justin Hibbits , Maxim Sobolev , "Kenneth D. Merry" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jun 2018 14:14:42 -0000 On 29 June 2018 at 00:59, Eitan Adler wrote: > This was the contents of a conversation on a different list. Figured > it was more appropriate here: > >>> We are experimenting with a C++ library for systems programming and are= interested in trying it in the FreeBSD kernel. Has anyone managed to run = C++ code in the kernel before and perhaps have patches to make the kernel h= eaders somewhat less C++-hostile that they=E2=80=99d be willing to share? > >>> A friend gave a WIP talk at BSDCan a few years ago doing this very thin= g. You can find his work at https://github.com/adamlsd/libcpp.ko > >>> I believe few times I've seen this discussion over the years the main c= oncerns raised were uncertainty about handling of exceptions and also lack = of the real stable ABI for the C++. Each compiler seems to have its own con= ventions, which might vary even between compiler revisions. https://youtu.b= e/JPQWQfDhICA?t=3D51m55s What might be possible, however, is to have partic= ular C++ "runtime" as a module itself, which is then would be used by the o= ther modules that are compiled with that particular C++ compiler. > >>> Most kernels that use C++ require -fno-rtti -fno-exceptions, so don=E2= =80=99t rely on a runtime. The ABI concerns were a problem 20 years ago, b= ut *NIX systems have kept the same C++ ABI since everyone[1] adopted the It= anium ABI. [1] Well, almost everyone. AArch32 has a slightly different AB= I, but it has also been stable for a similar length of time. > >>> Thanks, the include directory of that repo looks to be exactly what I n= eed to get the subset of libc++ that I need working. Copan used C++ in the kernel to support RAIDCore, which was a software RAID stack. (Written by ex-Adaptec people, I believe they were acquired by Ciprico, which was then acquired by Dot Hill, which was acquired by Seagate. No idea whether the software is still active/maintained.) RAIDCore didn't use new/delete or exceptions, so it wasn't too difficult to get it running in the kernel on FreeBSD. (It was originally written for Windows and then ported to Linux, and we later ported it to FreeBSD at Copan.) The porting effort probably happened in the 2007-2008 timeframe. RAIDCore was proprietary and the support code was never open sourced, so there's nothing to share unfortunately. I don't think there was much to it, but my memory on that is fuzzy. I guess the point is basic C++ in the kernel can be done without a huge effort, and it was in a shipping product for years. --=20 Eitan Adler