From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70704 invoked by alias); 30 Aug 2019 20:24:46 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 70680 invoked by uid 89); 30 Aug 2019 20:24:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.4 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=vacation, H*F:D*br X-HELO: mail-io1-f65.google.com Received: from mail-io1-f65.google.com (HELO mail-io1-f65.google.com) (209.85.166.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2019 20:24:43 +0000 Received: by mail-io1-f65.google.com with SMTP id t3so16561763ioj.12 for ; Fri, 30 Aug 2019 13:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2YA6/iV7kqiNQETMYeRXPb6Hb7zCrp2F5t4OipJwqDI=; b=fUkApNkdcHyFX/yyzuOZnn4w5AGMs0n3x1aofUeYzIKLPR90s185c0wY5UC//hvvdc OcS861KJ0YIrGI3M4ocblILZn6SWfpZyk6MLFu+aCKh5lEHCDbvzONzxxePc61O4quQO //5Muxc9shn0odt1Q5XwslgGElfqIxih7F7fKOekD7qJCrwpdLUle5OMlDKOa+xU0myh 5DXBYCPxhIMr/r3GrM01aPSeIn8nnNp7mv4+iBsdI7YxGVwz/43GASAhcHi5JT1V46O+ Gv0+XoEPU1mZANN45o8OBFkpuS+3dL55uk1ckRzFjfEik0SVUaLg/371GiVWkswoY/VY eohQ== MIME-Version: 1.0 References: <1566917881.3379.24.camel@redhat.com> In-Reply-To: <1566917881.3379.24.camel@redhat.com> From: Mateus Carmo Martins de Freitas Barbosa Date: Fri, 30 Aug 2019 20:24:00 -0000 Message-ID: Subject: Re: Rust front-end To: David Malcolm Cc: gcc@gcc.gnu.org, Philip Herron Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00237.txt.bz2 > One approach would be something like how the GCC Go frontend works, > which uses a library shared with the other Go compiler implementation > to parse the code, and turn it into GCC's IR, which then goes through GCC's optimizer and backend. I'm not familiar with rustc's internal working. Its code seems to be pretty modular but I'm not sure whether those modules are available for external use (i.e. have a stable API). If they are, I assume that with this approach it would be necessary to transform rust's MIR into one of GCC's IRs (e.g. GIMPLE or GENERIC), and there doesn't seem to be any MIR specification yet (), so it's likely not stable enough. > Another approach would be to build a gcc-based backend to the existing > rust compiler, as an alternative to its LLVM-based backend, rather than > a rust frontend to gcc. libgccjit (despite its name) has the ability > to generate ahead-of-time code (e.g. .o files), and has rust bindings, > and thus could be embedded inside rustc - in theory, at least. This approach seems cleaner to me. libgccjit seems to abstract away IR details, and it's really convenient that Rust bindings already exist. I'll take this discussion to the rustc project. Thanks to all. On Tue, Aug 27, 2019 at 11:58 AM David Malcolm wrote: > > On Fri, 2019-08-23 at 11:10 -0300, Mateus Carmo Martins de Freitas > Barbosa wrote: > > I'm interested in working on the Rust front-end for GCC. > > > > So far I've cloned the repository > git> > > and tried to compile it as described in > tFrontEnd>. > > I've compiled it outside of the gcc directory tree with > > > > $ ../gccrs/configure --prefix=/opt/gccrs --enable-languages=rust > > --disable-multilib --disable-bootstrap > > $ make > > > > > > But this produces some linking errors for functions that were called > > but never defined: > > > > > > /usr/bin/ld: rust/rust-lang.o: in function > > `rust_langhook_handle_option(unsigned long, char const*, long, int, > > unsigned int, cl_option_handlers const*)': > > /home/baal/gccrs-build/gcc/../../gccrs/gcc/rust/rust-lang.c:185: > > undefined reference to `rust_add_search_path(char const*)' > > /usr/bin/ld: /home/baal/gccrs-build/gcc/../../gccrs/gcc/rust/rust- > > lang.c:213: > > undefined reference to `rust_add_search_path(char const*)' > > /usr/bin/ld: /home/baal/gccrs-build/gcc/../../gccrs/gcc/rust/rust- > > lang.c:217: > > undefined reference to `rust_add_search_path(char const*)' > > /usr/bin/ld: rust/rust-lang.o: in function > > `rust_langhook_post_options': > > /home/baal/gccrs-build/gcc/../../gccrs/gcc/rust/rust-lang.c:245: > > undefined reference to `rust_add_search_path(char const*)' > > /usr/bin/ld: rust/rust-lang.o: in function > > `rust_langhook_parse_file()': > > /home/baal/gccrs-build/gcc/../../gccrs/gcc/rust/rust-lang.c:282: > > undefined reference to `rust_parse_input_files(char const**, unsigned > > int, bool)' > > /usr/bin/ld: rust/rust-lang.o:/home/baal/gccrs-build/gcc/./gtype- > > rust.h:24: > > undefined reference to `rust_non_zero_struct' > > collect2: error: ld returned 1 exit status > > make[2]: *** [../../gccrs/gcc/rust/Make-lang.in:61: rust1] Error 1 > > make[2]: Leaving directory '/home/baal/gccrs-build/gcc' > > make[1]: *** [Makefile:4319: all-gcc] Error 2 > > > > > > It's doesn't really help that the latest commit message > > (3b1e76d808b9725e6ef439ae534011370e65fb85) says simply "x" and the > > previous one, only "more". Anyhow, I'm left with those questions: > > > > - Considering I'm new to gcc development, what should I read before > > getting into this? > > - Is there any developer in particular I should talk to? > > As far as I can tell, this is a side-project by one gcc developer > ("redbrain" aka Philip Herron), who appears to only work on it > intermittently. It may not be the best start for someone new to gcc > development. > > I've CCed him on this email (hi Philip!) as I suspect he hasn't seen > this thread (or might be on vacation). > > > - Is there anything else I need to know before getting started? > > FWIW, I'm not convinced that a rust frontend to gcc is the best > approach - Rust has some complicated semantic-checking rules that must > be implemented by a compiler (the "borrow checker"). Hopefully that > code is available via a library. > > One approach would be something like how the GCC Go frontend works, > which uses a library shared with the other Go compiler implementation > to parse the code, and turn it into GCC's IR, which then goes through > GCC's optimizer and backend. > > Another approach would be to build a gcc-based backend to the existing > rust compiler, as an alternative to its LLVM-based backend, rather than > a rust frontend to gcc. libgccjit (despite its name) has the ability > to generate ahead-of-time code (e.g. .o files), and has rust bindings, > and thus could be embedded inside rustc - in theory, at least. I'm the > maintainer of libgccjit. See this discussion: > > https://users.rust-lang.org/t/rust-front-end-to-gcc/11601 > > Although I'm a fan of Rust, I'm deep in the middle of another gcc- > related project, and I don't have cycles to spare to work on this > (beyond answering libgccjit questions). > > Hope this is helpful and constructive > Dave >