Questions about LLVM geneology, Wasm, Emscripten


#1

Hi all,

I’m trying to make sense of Rust’s fork of LLVM.

My understanding is that overall Rust builds against a released version of LLVM, likely with a small number of Rust-specific changes. Because LLVM changes tend to break the Rust bindings, LLVM upgrades are a nontrivial undertaking, and thus happen somewhat infrequently. Is this correct so far?

Rust also has asm.js and Wasm targets, which use fastcomp, which is from a fork of LLVM. At first I thought this meant Rust would change LLVM branches when building the emscripten target, but it seems like actually Rust uses one branch that has either merged in or cherry-picked fastcomp. Is this right?

Next, the Wasm LLVM backend seems to have advanced somewhat since January when it seems Rust’s LLVM was last significantly updated. Would the Rust team be open to updating the LLVM Wasm backend? If so, would it be better to do it with cherry picking, merging, subtree merges, or trying to do another LLVM upgrade?


#2

It looks like this is our fork. There was a time when we only carried a few patches, but it looks quite monstrous at the moment.

Rust does not base it’s fork off of a released version of LLVM. It is an arbitrary commit from upstream LLVM. LLVM upgrades do break Rust’s bindings but that is usually not the hardest part of the upgrades. Rather, getting all of Rust’s supported platforms to pass CI again is. Our MinGW port is especially troublesome, as upstream support has degraded over the years.

It looks like we are currently carrying a merge of the fastcomp fork, though when I originally merged fastcomp support, we did not literally merge with fastcomp, we just created a minimal patch that created a fastcomp target with fastcomp-compatible IR.

If we try to pull in an updated wasm backend I’d prefer to upgrade LLVM from upstream and not cherry-pick more stuff.

cc @TimNN did the last upgrade.


#3

If we do an upgrade, then chances are emscripten will need to as well.


#4

Hmm, does that mean that Rust is now basically unable to upgrade LLVM unless Emscripten also does so?


#5

Yes, that is the case.


#6

This all sounds kind of crazy. Is upstream LLVM really so unstable that it regularly breaks platforms? Or is it that rust is using LLVM in ways that LLVM wasn’t designed for?


#7

LLVM puts out a new major version roughly every six months, so it’s not super super stable.


#8

Yep. LLVM supports a lot of platforms and architectures, with greater and lesser degrees of support and testing. Apple platforms work great!


#9

It could be that basing our fork off of arbitrary commits causes us more platform regressions than using an LLVM release. Presumably they catch some regressions ahead of release.


#10

Out of curiosity, what all is in the Rust LLVM fork that’s not in regular LLVM? Are these changes still necessary, or would it be feasible to consider moving back to a vanilla LLVM release?


#11

Just going through the list of patches it looks like these are not from upstream:

https://github.com/rust-lang/llvm/pull/73 https://github.com/rust-lang/llvm/pull/70 https://github.com/rust-lang/llvm/pull/45 https://github.com/rust-lang/llvm/pull/49 https://github.com/rust-lang/llvm/pull/34 https://github.com/rust-lang/llvm/pull/62 https://github.com/rust-lang/llvm/pull/61


#12

It seems pretty hard to tell whether these are necessary after an upgrade a-priori.


#13

That’s a smaller set of changes than I was expecting. Just going by the titles, it seems like most of the changes could probably be upstreamed.


#14

I went ahead and opened https://github.com/rust-lang/rust/issues/42389, since it seems like de-forking LLVM would be beneficial in the long run. Of course, there may still be reasons why the state of affairs is necessary, so the bug seems like a good place to discuss the feasibility and desirability of de-forking LLVM.


#15

FWIW, Rust does work with vanilla LLVM. We use the system LLVM in Fedora, and probably most other distros do too. But we’re only trying to support our own native linux-gnu targets in that case.

I do apply some of the rust-llvm backported fixes to our system LLVM though.


#16

This is the big one: https://github.com/rust-lang/llvm/commit/c9bf6e3f98557937df93b24c48b2564c6963e788

As far as I know, LLVM devs don’t want to merge any of that, ever.