Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming GNU is Not Unix

GCC Gets a New Frontend for Rust (fosdem.org) 106

Slashdot reader sleeping cat shares a recent FOSDEM talk by a compiler engineer on the team building Rust-GCC, "an alternative compiler implementation for the Rust programming language."

"If gccrs interprets a program differently from rustc, this is considered a bug," explains the project's FAQ on GitHub.

The FAQ also notes that LLVM's set of compiler technologies — which Rust uses — "is missing some backends that GCC supports, so a gccrs implementation can fill in the gaps for use in embedded development." But the FAQ also highlights another potential benefit: With the recent announcement of Rust being allowed into the Linux Kernel codebase, an interesting security implication has been highlighted by Open Source Security, inc. When code is compiled and uses Link Time Optimization (LTO), GCC emits GIMPLE [an intermediate representation] directly into a section of each object file, and LLVM does something similar with its own bytecode. If mixing rustc-compiled code and GCC-built code in the Linux kernel, the compilers will be unable to perform a full link-time optimization pass over all of the compiled code, leading to absent CFI (control flow integrity).

If Rust is available in the GNU toolchain, releases can be built on the Linux kernel (for example) with CFI using LLVM or GCC.

Started in 2014 (and revived in 2019), "The effort has been ongoing since 2020...and we've done a lot of effort and a lot of progress," compiler engineer Arthur Cohen says in the talk. "We have upstreamed the first version of gccrs within GCC. So next time when you install GCC 13 — you'll have gccrs in it. You can use it, you can start hacking on it, you can please report issues when it inevitably crashes and dies horribly."

"One big thing we're doing is some work towards running the rustc test suite. Because we want gccrs to be an actual Rust compiler and not a toy project or something that compiles a language that looks like Rust but isn't Rust, we're trying really hard to get that test suite working."

Read on for some notes from the talk...
  • It reuses the GNU toolchain — the gdb debugger, the as assembler, and the linker ld — while also reusing official Rust libraries like libcore, libstd, and libproc.
  • "Because of the way GCC is architectured, once you get to that common GCC backend and common GCC intermediate representation, you can basically reuse all of the plugins that have been written for GCC ever. And that means a lot of plugins — security plugins, stuff like the static analyzers, the LTO (link time optimization), CFI security plugins, and so on."
  • "We also hope that because we're writing it in C++, that means we can backport it to previous versions of GCC. And hopefully that will help some systems get Rust."
  • "Because GCC is much older than LLVM, it has support for more architectures and more targets than LLVM. So technically thanks to gccrs, you will now be able to run Rust on your favorite Soviet satellite and so on."
This discussion has been archived. No new comments can be posted.

GCC Gets a New Frontend for Rust

Comments Filter:
  • by SuperKendall ( 25149 ) on Sunday February 26, 2023 @12:53AM (#63323666)

    What other application can you ship that can casually include the phrase " you can please report issues when it inevitably crashes and dies horribly." And people are nodding along going "well yes of course perfectly reasonable".

    Mad respect to everyone who works on compilers.

    • by dfghjk ( 711126 )

      I would say that any application you're involved in should at least casually include that phrase. I'd expect more from a faux emacs user.

    • What other application can you ship that can casually include the phrase " you can please report issues when it inevitably crashes and dies horribly." And people are nodding along going "well yes of course perfectly reasonable".

      Games from Ubisoft. ;)

    • "Windows with versions ending in .0". They don't include the exact phrase but it is tribal knowledge.
  • We've already seen em on slashdot before. Basically their idea is that rust is going to marginalize C++ into a second class citizen as part of their C++ replacement theory. But this isn't true because C++ is already a second class citizen. C developers have for a long time maintained that C++ has no place in the kernel. But now that rust has been allowed in, that makes C++ developers very sad.

    • C developers have for a long time maintained that C++ has no place in the kernel. But now that rust has been allowed in, that makes C++ developers very sad.

      As a C++ developer, I'm glad the kernel devs have finally come to their senses and realised that C is not the be-all and end-all of languages. If there's one thing a C++ developer like me thinks it's that writing C is an exercise in tediously doing the same things over and over and over again by hand that you could automate away with the compiler at zero

      • If you take away all the things that cant be used in the kernel - ie the entire STL, exceptions, virtual functions - then C++ is little more than C with classes again.

        • Kernel runtime is different from application runtime so this is expected. There is nothing inherently wrong with C++ language when it comes to kernel programming. It is just that the toolchain is not designed for kernel runtime and the resulting object code is problematic when it comes to kernel development. They had to make changes to Rust toolchain to make it suitable for linux kernel as well.

          This is an old paper from Microsoft that outlines problems of using C++ for kernel development: kmcode.doc [microsoft.com]. It

      • As a C++ developer, I'm glad the kernel devs have finally come to their senses and realised that C is not the be-all and end-all of languages. If there's one thing a C++ developer like me thinks it's that writing C is an exercise in tediously doing the same things over and over and over again by hand that you could automate away with the compiler at zero cost.

        I don't even understand the language wars to be honest. Actually the whole reason I started using rust was because I was using the wrong tool for the job, repeatedly. At the time, all I knew was java and C#. Java was really pissing me off (and still does when I need to use it) and while C# was much better, it still had a problem in common with java: Too often, when you need to give somebody a tool you've written, they don't have the right runtime installed. Java is even worse because it routinely breaks com

        • Dependency management is a hard problem in general, and, IMO, one of the generally tedious and painful parts of managing production software through its expected lifetime.

          I find it a little easier in "batteries-included" environments like C#/.NET Core (among others) because most of the time I don't need a lot of external libraries and I have the option of choosing ones that don't have a lot of external dependencies themselves.

          • Yeah the batteries included part is nice, and C# does a better job than most. Especially when compared to java (dependency shading -- 'nuff said.) Though rust's reasoning for having a very small standard library is a very, very good one.

            And rust actually draws a ton of inspiration from C#, particularly with async/await. Likewise, adding dependencies to your project in rust is dead simple if not easier than C# (namely, no xml required.) But still, a lot of times I wish there was a batteries included extended

    • Re: (Score:3, Funny)

      > C developers have for a long time maintained that C++ has no place in the kernel.

      That's because C developers are arrogant pricks, especially the ones named Linus Torvalds :)

      • Nonsense. Results of his work aside, Torvalds always separates a person from their behavior. He may say that some code is absolute shit and that the person who thinks that code is OK is "out to lunch".

        And I say that as someone who codes in C++ all the time (except for golang when it comes to tedious system stuff), and I think his anti-C++ stance when it comes to the Linux kernel is spot on. Don't know what he thinks about rust, but the people who push for it seem to have an ideological bend that has nothing

      • When "simpleton fools" make unworkable suggestions lacking understanding of the kernel architecture and the gap is too much to close in the email thread, they may interpret rejection as work of "arrogant pricks".
    • We had to implement a client-server card playing game in C++ at uni. It invariably crashed after a few million games. No one was able to find out why... It's just that C++ networking libraries are shite IMO.
      • by Megane ( 129182 )
        A few million games? Did anyone check memory usage? Maybe it was too much heap fragmentation from going whole hog with the STL. I throw the STL out first when doing embedded firmware. Not only is there usually very little RAM, but there also usually isn't someone there to push the reset button. (yes I know what a watchdog is, and I've had times when it didn't work)
  • by gweihir ( 88907 ) on Sunday February 26, 2023 @01:50AM (#63323726)

    "If gccrs interprets a program differently from rustc, this is considered a bug," is very much _not_ the way to do it. Some people aggressively insist on making the same, old, well-known mistakes again and again it seems.

    • by Phillip2 ( 203612 ) on Sunday February 26, 2023 @04:04AM (#63323840)

      If people keep on doing it, perhaps that is because it is not such a big mistake as you think.

      The original reason that specifications were so important it that it gave a single source of truth, which mean that you were not tied into one vendor. That was a great idea, of course, but there are a number of flaws with it. First, for many languages, vendors simply add new "features" which are not standard. Next, many specifications have holes and other undefined behaviour which different vendors handle in different ways. Both of these means you get vendor lock in anyway.

      Finally, of course, if the implementation is freely available under equitable and non-revocable terms, vendor lock in is rather less of an issue. The implementation and its documentation become the source of truth and the language can evolve more rapidly. That is, perhaps, why many of the top used languages were not designed specification first: python and javascript are both examples.

      Rust, of course, has a specific set of aims and some of those would be served by having a specification which is why one is being written.

      I don't think this is a mistake; it's a decision and like all engineering decisions one that involves compromises.

      • by gweihir ( 88907 )

        If people keep on doing it, perhaps that is because it is not such a big mistake as you think.

        And at that point I stopped reading. You have nothing but an invalid AdHominem. And you are clearly incompetent as to language development. No, it is not "me" "thinking" that. It is a clear and well-know part of the state-of-the-art.

        • by HiThere ( 15173 )

          That's not really fair. I generally don't have a spec when I start, and often do lots of radical redesigns during development. When I get things right, THEN I write a spec. If you start with the spec you're likely to promise things you can't do, and leave out important things that you could have done.

          But the spec should show up before you consider the work out of alpha. Beta, et seq. should avoid massive changes in how things operate. And breaking changes should be avoided firmly after about half way t

          • by gweihir ( 88907 )

            The claim is that Rust is "production ready". At that time it needs to have a spec. What about that is "not really fair"?

        • It is not an ad hominen attack. The "you" could refer to anyone. I am simply asking you, what it is about the absence of a spec that worries you. What are you trying to achieve that the lack of a specification makes impossible, or difficult?

          I am not a language developer, that is not my job, my expertise. I am a language learner, and a developer. I want to understand what impact you think the lack of a spec has on me, and what not only makes it "state-of-the-art" today, but also state of the art tomorrow. I

          • by gweihir ( 88907 )

            Stop claiming nonsense. My answer was completely clear. Also, you may want to look into language design and evolution for a while, which is something I can obviously not summarize in a few lines.

            • I haven't claimed anything. I have asked something, which was an explanation.

              As far as I can see, your argument is this:

              Rust is bad because it does not have a spec
              The need for having a spec is a clear and well understood
              And, yes, despite this many other languages have not had a spec. This was and is a mistake in every case.

              Okay, that's fine. I am saying:

              Rust has reference doc and reference implementation
              Rust has a process for change management
              The rust implementation is freely available
              A specification is bei

              • by gweihir ( 88907 )

                Seriously? You expect me to state what probably would fill a 45 min lecture in a few sentences? And if cannot, then you are right? That is not how reality works.

                Some aspects you will find in my other answers here. Some others are obvious if you stop trying to argue with the misconception that obvious Rust must be great. For example, how many systems programing languages without a spec (which does not need to be a formal one) do you know? And there are more aspects to this. You also need to be aware that you

                • It is possible to summarize most things. Anyway, you have provided an explanation of at least one of the problems that you see in another post and that has been useful.

                  In terms of systems languages without a spec, I think, this will turn into a non-true-scotsman fallacy, because I can just say "rust". Even without this, the past does not prove the future. In the past, formal specs were considered vital in many areas that they are not now.

                  Finally, on the sunk cost fallacy, I don't think you can know whether

                  • by gweihir ( 88907 )

                    In the past, formal specs were considered vital in many areas that they are not now.

                    You are misguided. The problem is with today's social networking you have a lot of people being loud about things they do not understand. A spec is _still_ a requirement for any serious system programming language that claims to be production ready. A requirement by anybody actually competent in the area. The arguments for it have not gone away. There are no new arguments against it, just the same ones that were already invalid before. There are a lot of people that have no clue about established wisdom in

    • If you built it to a spec and it didnâ(TM)t compile existing rust code, then youâ(TM)d have a very nice piece of software that nobody would use
      • by gweihir ( 88907 )

        And were id I say the spec needs to come first? Oh, whait, I did not. The point is that when a language is claiming to be production ready, it needs to have a spec. If it does not have one, then it is still experimental and unsuitable for anything except experimental things. Make a choice. Is Rust unfinished and experimental or is it ready for production? You cannot have both.

    • So Rust does not even have a spec? WTF?

      Yes, that's actually why efforts to make a GCC frontend were dropped in 2014: the language was being changed so quickly that they couldn't keep up.

      Eventually a 1.0 language reference (which isn't a specification) was released and the new GCC Rust is based on this. It's not ideal but it's a fixed point rather than an ever evolving language which makes it psuedo-specification.

      "If gccrs interprets a program differently from rustc, this is considered a bug," is very much _not_ the way to do it.

      Part of the GCC Rust effort is to find where the reference is ambiguous (and thus interpreted differently) so that there can eventually

      • by gweihir ( 88907 )

        I applaud the efforts to make a specification even if they are going about it all wrong. This effort will either force them to do it correctly or be the death blow that destroys any possible future for it.

        I agree to that. For Rust to ever amount to anything, they have to finally get it out of the experimental stage and that means a specification that people can rely on. Just claiming it was ready for production does in no way make it so.

    • It's a Rust thread, I come here to laugh at Gweihir's harumphing.

      • by gweihir ( 88907 )

        Blessed are the clueless, for they shall be forever amused at things they do not understand....

    • Comment removed (Score:5, Informative)

      by account_deleted ( 4530225 ) on Sunday February 26, 2023 @01:38PM (#63324660)
      Comment removed based on user account deletion
      • by gweihir ( 88907 )

        That and when C was done, nobody really understood how to do it. That is different today. Well, many people still do not understand how to do this and Rust is an example of that.

        Yes, Rust is unstable and experimental at this time. What is not acceptable is the designers lying about that fact.

  • I have a Linux box, running Gentoo, that has been running for about 14 years now.

    The time to build Gcc on this box has gone from less than 3 hours to over 30 hours. It's made worse by the fact that, with only 2G of RAM, I have to use "-j1" or it runs out of memory. Even back in 2018, it was less than 8 hours, but has taken a big jump since then.

    This just looks like another thing that will increase the time to build Gcc.

    • Add RAM.
      • That’s why software today has the same load time as it did 30 years ago running on slow platter drives. Computers and memory are orders of magnitude faster and yet it never feels faster.

        • You definitely have a point but long compile times aren't as bad as long load times. gcc runs pretty quick from the command line.
          • Compile times can be an issue on Gentoo because it's source-based, and updating a package usually involves re-compiling it. Big packages like gcc, llvm, firefox, chrome, and kde can take hours if not days if the hardware isn't enough for the compiler to work efficiently.

            I have 3 Gentoo boxes at home. One is fine. Another is old, but I was able to add RAM and an SSD, and it is now fine in spite of an old-ish (i5-3570) CPU. But the one machine I intended as a "spare," and was underpowered even when I got

    • by Uecker ( 1842596 )

      You can select which languages to build using ./configure --enable-languages=c,c++,...

      So simply turn it off.

      In terms of build times (and IMHO also otherwise), it was certainly a bad decision to switch GCC to C++.

    • Gentoo? The Linux with the built-in system for compiling shit across multiple machines? That's the system you're having trouble with compiling on 2 GiB of RAM?

      Definitely sounds like user error.

      • Gentoo? The Linux with the built-in system for compiling shit across multiple machines?

        It just uses distcc, you can run that on any Linux you want. Most computers have enough cores that it isn't that important any more, though. The last time I used it (and gentoo) was when I owned a K6/2 laptop. Then it was really important to do your own build (a K6/2 is a terrible P2, but it's faster clock for clock than a P2 if you optimize for it) and I also had a much less limited desktop available to do my computation. I've also used it with an ARM system and a cross-compiler on a remote system, which i

        • I've found that you need an SSD and sufficient RAM in order to compile in reasonable amounts of time. CPU matters comparatively little in my experience. If you're swapping constantly to spinning rust (FeO, not the language) on whatever machine you're compiling on, you're going to be in for some long and painful updates.
    • Re:More bloat. (Score:5, Insightful)

      by serviscope_minor ( 664417 ) on Sunday February 26, 2023 @04:58AM (#63323878) Journal

      If you want a tiny compiler with no "bloat", i.e. features, use tcc.

      GCC's optimizer is huge and complicated and it also does an incredibly good job of making code fast, so you can write, the short, clear, obvious thing and have it run faster than some supper l33t tricky code. GCC's front end is pretty complicated now too, with extensive warnings (turning into a small static analyzer), "did you mean" suggestions, and the ability to track a warning found deep in the levels of the optimizer back to the exact character of the input.

      And GCC has also got a lot faster in the last 14 years, so your code builds quicker.

      All of those things make developing code better. It even makes you ancient machine more effective so that the code you build builds faster and runs faster.

      I don't really see why we should hold back meaningful, useful progress because you are running a substantially less capable computer than one that would cost you less than 100 GBP new. Even if you desperately don't want to upgrade (I built GCC 12 recently on my 13 year old machine but I have 16G), you can rent a 64 core machine for less than $1 per hour from google, build GCC there and copy it over (yep GCC install trees can be copied around just fine, thanks GCC devs!!).

    • I have a Linux box, running Gentoo, that has been running for about 14 years now.
      The time to build Gcc on this box has gone from less than 3 hours to over 30 hours. It's made worse by the fact that, with only 2G of RAM, I have to use "-j1" or it runs out of memory

      I just recycled a better computer than that. You can literally get a superior replacement for free by scrounging anywhere in the developed world.

      • rPI sounds like a more capable computer TBH. And it can probably use microsd cards that are both higher capacity and faster than whatever spinning disk runs on that.

    • by PPH ( 736903 )

      Just turn off all the front ends that you don't need. Are you going to be doing a lot of work with Fortran? Ada?

    • I would not run Gentoo in less than 16GB. It can handle a modestly old CPU, but sufficient RAM is absolutely essential because that's what compilers need.

      LLVM (which gets rebuild on my systems much more frequently than GCC) takes a little over an hour on my 3 year old machine which was fairly state of the art at the time. But on my 5 year old machine with no SSD, limited RAM and crap CPU, it can take well over a day.

  • I shot no one with this gun in my hand.

  • > So technically thanks to gccrs, you will now be able to run Rust on your favorite Soviet satellite and so on."

    Soviet satellites have plenty of rust already :)

  • by PPH ( 736903 )

    Now with corrosion inhibitors.

  • ..... it's simply a joy to work with. rustc's a first class piece of software. The error messages pretty much teach you the language as you go. Rust support is a great feature for gcc and it's a huge benefit to Rust to get input from GNU contributors. But without knowing what the goals of this gcc sub project are, I struggle to see a benefit from it for Rust coders. rustc (and cargo) are huge reasons why Rust has become so popular in recent years. Rust is adds far more value to gcc, than gccrs adds to

Keep up the good work! But please don't ask me to help.

Working...