-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Targeting an arch in gcc but not in LLVM. #49
Comments
I'm on vacation too.
|
I'm one of Debian's porters for the less common architectures such as m68k and sh4 (SuperH). I can bootstrap I guess we will have to add the various boilerplates for the additional architecture to |
I'm back from vacation.
Not necessarily,
What I mean is, something like @antoyo I guess my overarching question is: What can I do to start adding cross-compilation support to |
Sorry for the delay. As far as I know To start helping on the rustc side, you could start a discussion to see whether you can start adding the new architectures you would want in this directory and the new inline-asm register support for those new architectures so that this code can be completed with those new architectures. |
The target spec used to have a field to specify which backend to use. This was introduced to allow emscripten to use a rustc_codegen_llvm linked against emscripten's llvm instead of the newer default llvm used by rustc. I removed this field in rust-lang/rust#74394 as the emscripten support no longer needed a different llvm and thus the field wasn't used anymore. |
@bjorn3 Are you aware of any difficulties adding backend selection back, in similar to how it was (before it was removed)?
@antoyo Things have changed on my end in the past 4 weeks, so right now I don't have the time I thought I would to commit to starting a backend port (besides testing x86). But I can at least open issues, get feedback, and study your code in the interim :). I just need a few weeks to get things sorted. |
Some notes from my attempts at running Rust code in a Debian m68k qemu virtual machine:
I was able to run a simple program using core and a "hello world" using the std on m68k. |
@antoyo Excellent :D! In the coming days, I'll see if I can duplicate this setup in the coming days in rcg_docker, which has bitrotted a bit since your rebase. |
Are these required for no_std builds? I'd like to take a stab at compiling for Xtensa using the GCC backend. Is it possible to statically compile |
The object crate needs to support it the new target. While in the past it was only necessary for dylibs, rustc now also uses object for writing object files containing the crate metadata in rlibs.
Once you add support to the object crate (and update rustc with the new version) and compile libgccjit to target xtensa (every compiled version of gcc can only target a single triple unlike llvm) it may work. |
@MabezDev Also, if you want to use inline assembly, that will require an update in rustc to support this architecture. |
@antoyo Do you have a quick guide on how to bootstrap rustc using the backend for a given architecture? I would love to give it a try with m68k which currently uses the work-in-progress LLVM backend. |
Thanks for the hint! Fortunately I've already added Xtensa assembly support in our fork that uses a custom llvm backend: esp-rs/rust@9d4ab85 |
That might be simpler to wait until upstream rustc is updated with the latest changes in this repository, but if you want to do it manually locally, here's how to do it. Add the missing changes from rustc_codegen_gcc in your local rustc repo (might require to use the commit for nightly-2022-03-26). Update the changelog-seen = 2
[rust]
codegen-backends = ["gcc"]
deny-warnings = false
new-symbol-mangling = true then, run the following command:
I haven't tried cross-compiling rustc yet, so that might not work. |
It probably won't work. Rustc needs to be compiled for the build machine in addition to the chosen host to build the standard library. This would require some way to choose the right libgccjit for depending on the triple to compile for. |
Wouldn't it be possible to build a Rust cross-compiler with the standard Rust compiler on the host system?
On Debian unstable, we should have libgccjit versions for all targets. |
The standard library needs to be compiled by the exact same rustc version as the one that actually uses it. This means that we first have to build stage1 rustc for the host using the bootstrap compiler. This stage1 rustc can then build libstd. And finally another stage1 rustc can be built for the target which can then load the aformentioned libstd version. |
Do you have any suggestion on how we could do that, perhaps by specifying multiple libgccjit.so paths in the config file? |
That would be an option. |
One option might be to build the suitable libgccjit version during the build process of Would that be feasible? |
@glaubitz Continuing the discussion from #123 here:
One thing you might try is editing the file [patch.crates-io]
libc = { git = "https://github.com/rust-lang/libc", default-features = false, features = ['rustc-dep-of-std'] } That might work. |
I think I can just update the The only thing that I haven't understood yet: From where do I get a libgccjit that can cross-compile for a given architecture? Do I build libgccjit from source for that purpose? |
Yes, you always have to compile it because I have patches that have not been included in any released libgccjit. The readme contains the instructions of how to do so.. By the way, the instructions in the readme are outdated:
|
OK, thanks a lot! I will give it a try! |
You also won't need this step if rustc now have the m68k target triple:
Also, I realized the instructions are not that clear, so you can take a look at this commit to understand what is meant in the instructions. |
Just in case I wasn't clear, you want to use the latest libc in the program you compile, not within rustc, so you'll have to update the file The reason I couldn't run the tests of libcore on m68k was seemingly because the test runner would run the test executables with a syscall and one was called with an invalid value (since it wasn't using the constants for m68k). |
@glaubitz One more thing, in case you don't know already: use my fork of gcc as some of my patches were not merged yet upstream. |
FYI, I've merged the support for libgccjit in crosstool-ng (crosstool-ng/crosstool-ng#1873). This may help in getting the lib for some other target (initial goal was to have a cross rustc_cg_gcc in compiler-explorer compiler-explorer/compiler-explorer#3760) |
Is there any update on this? I'm interested in the SuperH architecture exactly as well, does the opener or anyone else have any information/progress? |
If you're interested in SuperH, you might want to join #linux-sh on Libera IRC as well as #debian-ports on OFTC IRC. |
@antoyo Here is a write-up that details how to use This should help us get started to add support for If I understood you correctly, you've already got a working compiler for |
@glaubitz: I have a working cross-compiler targetting I could try building a native Did you try to cross-compile other softwares (like |
m68k support has been added to What I still don't understand: How do we make |
Maybe by adding a vec into the target info: |
Sounds plausible to me. Do you have a rough idea how this would look like? |
A new field in |
Have you checked https://rustc-dev-guide.rust-lang.org/building/new-target.html ?
…On June 29, 2024 1:36:48 PM UTC, Guillaume Gomez ***@***.***> wrote:
A new field in `base` that is used for all targets (example [here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs)) I suppose?
--
Reply to this email directly or view it on GitHub:
#49 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
|
I have added And, more surprisingly, the instructions to build I would expect that we would need to add spec files to |
I'm using a little bit of a trick for that in my scripts that wrap the rustc_codegen_gcc tools. As for the It has been working fine doing this so far, but obviously this isn't the right way to handle things and we'll need to add SH, etc. to |
OK, that clarifies my confusion. Thanks a lot!
Adding
Would be great to document this as well as possible to ease the process of adding new |
I'm not super familiar with what exactly @darcagn had to go through to get all of this set up with rustc_codegen_gcc targeting SH4, but I have been on the KallistiOS side helping to support the back-end needs for the Rust stdlib and even tokio async library on the Sega Dreamcast, working on providing a pthread layer of abstraction above our own custom kernel among a few other things in C... And holy crap, guys, I can't believe how well this stuff works and just how quickly @darcagn was able to work his way up to having async and advanced Rust concurrency running just fine on the Sega Dreamcast with our TLS model (currently only supports local-exec), our atomics (we provide our own just toggling interrupts), and many other things... I really think this is going to be able to bring a lot of epic Rust stuff to the SH arch, and I would love to see us getting support for our target upstreamed.... Also its's so nice to see all of you SH rockstars here and how much interest there is in bringing this cool new stuff to the target. I'll have to join the IRC server! EDIT: @antoyo, should the "Rust on Dreamcast" article by @darcagn get added to the wiki as an SH link as well? He even bought a |
This gives me hope that we can get
Please keep in mind that there are still a lot of open issues with the SH backend in GCC, so please help me organize a crowdfunding campaign to pay an experienced GCC developer to revamp the SH backend in GCC. The SH backend really isn't in a good shape at the moment with lots of source packages triggering ICEs. |
@antoyo Are there plans to add GCC upstream as a git submodule to the rustc git tree similar to LLVM? I think it would be great to have |
Woohoo! Awesome, thanks! |
Looks like there's some confusion about the GPL license in the comments. Hope this won't push it back or trigger false alarm :). Nice to see it included in rustc :thumbup:
|
Don't hesitate to comment to clear confusion. ;) |
I'm not sure how you want to install rustc_codegen_gcc, but the above might be to get it via rustup: would that be alright? |
It's the plan. |
I'm not sure how that's related to To be honest, I have never used |
Nothing prevents you to build gcc from our fork. |
A forked GCC won't help me when I want to build a stand-alone compiler for alpha, hppa, m68k and sh4. My hope was that |
I'm getting more and more confused by what you want to do here. GCC upstream doesn't have all the patches we wrote that are needed for rust, so for now only our fork can be used with |
So lately, I've been just lurking, but I still read this issue:
When I asked this, something that I intended to imply asking is "will upstream Rust handle building/providing libgccjits, so that a user need not compile their own"? I take it from "Nothing prevents you to build gcc from our fork." that if someone wants to use the gcc backend, they are expected to provide their own gcc, and upstream Rust has no plans to host the libgccjit shared objects? I.e. if someone wants there to be a turnkey solution to installing the gcc backend from |
We plan to provide libgccjit.so and gcc for the target you asked, but nothing for cross-compilation (and linux-only for now).
Like I mentioned above, |
I'm getting more and more confused by what you want to do here. GCC upstream doesn't have all the patches we wrote that are needed for rust, so for now only our fork can be used with rustc_codegen_gcc. An important note about cross-compilation with GCC (I don't know how much you know about it so just in case...): GCC only allows to compile to one target. You need to compile GCC for this target on your current platform for it to be used to build cross-compilation. It's an annoying limitation and has nothing to do with Rust, so again, you need to build your own GCC. Only difference: you need to build the one from our fork (which is the submodule being added to the rust repository).
Well, my point is that I don’t understand why the necessary patches haven’t been upstreamed yet.
I don’t need a cross-compiler for all targets, I just want to be able to build stand-alone rustc for new targets.
I had hoped this to be much easier as I remember this was stated as one of the big advantages over gccrs which I have already used to build minimal rust binaries for new targets.
|
Well, quite a lot of them are waiting for reviews. Getting things merged it taking veeeeeeery long. |
The usual rustc also use a forked LLVM, if I'm not mistaken. Is there any reason why this wouldn't suit you that it is the same (for the time being: in the long run, the plan is to use upstream libgccjit, but the reviews take a long time to be done)? Could you please explain how you would want to build rustc_codegen_gcc since you seem to want something different than most people (that want to download it via |
It also works with upstream LLVM. The forked LLVM just has some more bugfixes, not any actually new non-optional features. |
Yea, it occurred to me that I asked my question prematurely and hoped you wouldn't notice :P.
All of this is perfectly fine with me. I have scripts (actually a Rust crate using My scripts assume a shared external LLVM checkout that I use for other projects, and has logic to handle swapping between upstream and Rust branches. Plan would be to do the same for the forked gcc repo. @glaubitz if your concern is not having 10 million gcc and llvm checkouts, I've used my script successfully for ~2 years now, building Rust once a week, and should probably open-source it. It's like 300 lines of Rust if that, and is mainly Rust to handle the git checkout logic.
|
I'm on vacation till Wednesday, but I figured I should ask this question now while it's fresh on my mind:
I'm interested in getting Rust support as soon as possible for a few architectures with the new
gcc
codegen; SuperH would be the highest priority for me. What current obstacles exist for me to try out cross compiling to bare-metalsh2
/j2
, and reporting back (and maybe even fixing, if I can get a grasp on RTL!) any issues I can find. What obstacles exist for attempting to testsh2
codegen usingrustc
? I can think of a few, but would love to know more:libgccjit.so
is more complicated than the LLVM backend because eachlibgccjit.so
can only target one arch. Has there been movement on how all the differentlibgccjit.so
s should coexist?libgccjit.so
is difficult to use in a cross-compile setting; how true is that?libcore
is tested for any arch wherelibstd
doesn't exist in Rust proper, let alone forgcc
codegen backends. Is there a way to run thelibcore
tests inqemu
or thegdb
simulators? Testinglibcore
would be a good litmus test for bare-metalsh2
/j2
1.rustc
would have to have a target registered forsh2
/j2
, and would somehow need to know that only thegcc
codegen backend is supported for now (LLVM backend might come later, but it's not a high priority). Does this "choose a backend" logic already exist in upstream Rust? Is there additional ABI work that needs to be done to addsh2
upstream?I assume 2. and 3. need to be handled first before I can start actual codegen for "archs which only have a gcc port". I'd be interested in getting the ball rolling there (at the very least testing, or contributing code depending on how much time I can allocate to this).
Footnotes
fdpic
, and I have no idea whetherrustc
meaningfully supports anything like it.The text was updated successfully, but these errors were encountered: