Uh oh!
There was an error while loading. Please reload this page.
glibc: add changes to make riscv64-linux-gnu works - #18803
glibc: add changes to make riscv64-linux-gnu works#18803RossComputerGuy wants to merge 1 commit into
Conversation
bjia56
commented
Feb 4, 2024
I applied this PR's patch to the prebuilt |
75a8de3 to
54e33efCompareRossComputerGuy
commented
Feb 4, 2024
I've fixed that missing header issue and I compiled glibc just to check if that header had anything worth adding and all I got was this: /* This file is automatically generated. It defines a symbol `__stub_FUNCTION' for each function in the C library which is a stub, meaning it will fail every time called, usually setting errno to ENOSYS. */#ifdef_LIBC#error Applications may not define the macro _LIBC
#endif |
nektro
commented
Feb 4, 2024
note that this patch should additionally be sent upstream so its not lost in zig when we next upgrade glibc |
d2f5926 to
f3d9547Comparef3d9547 to
5b803aeCompareRossComputerGuy
commented
Feb 4, 2024
Woops, made a mistake |
RossComputerGuy
commented
Feb 4, 2024
@nektro Yeah, the fini/ini stuff is actually upstream already. I just simplified it a bit since idk how we do things with glibc. The stub file though can be copied from a built version of glibc. |
LinuxUserGD
commented
Feb 4, 2024
Might also fix ziglang/zig-bootstrap#115 |
bjia56
commented
Feb 4, 2024
@RossComputerGuy Regarding the While an empty file might fix compilation, I'm not sure if it'll produce correct behavior. |
RossComputerGuy
commented
Feb 4, 2024
@bjia56 Alright, I'll copy that in. |
f3d9547 to
a21352bCompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
rootbeer
commented
Feb 4, 2024
I've got a draft PR In #18815 that builds on this PR. It enables Zig code to target riscv64-linux , with or without glibc (previously this would fail with missing "ucontext_t" errors). I don't have any experience with riscv*, so I'm not able to test anything, so it may be wrong in obvious or subtle ways (I copied some details from https://go.dev/src/runtime/defs_linux_riscv64.go), but it does compile successfully. Just putting the PR out there in case someone with riscv access/experience/motivation needs pointers on how to get Zig's built-in library and/or the glibc linking for Zig code to work. There are also glibc linking tests in |
RossComputerGuy
commented
Feb 4, 2024
I've just been using QEMU userspace emulation ( |
bjia56
commented
Feb 4, 2024
With the most recent patches from this PR applied to Note that the interpreter is |
bjia56
commented
Feb 4, 2024
Using patchelf to switch the interpreter to |
RossComputerGuy
commented
Feb 4, 2024
Yeah, that's what I have to do on NixOS. I think Zig's interpreter selection or target guessing not quite there yet. If it at least compiles and can execute, I'd call that a win. I can probably look into fixing that once I have hardware. |
Btw - looks like we may be missing another file (this is Debian sid): Looks like this is where the lp64d interpreter is referenced. Still testing if this makes any difference... |
bjia56
commented
Feb 5, 2024
Actually, nvm on the previous post - this file doesn't seem to be pulled in as part of compilation. |
bjia56
commented
Feb 5, 2024
I think I found it - this line needs to switch on the abi to determine if it should use lp64, lp64f, or lp64d: Line 1674 in f5dbcd1 |
a21352b to
e4da8e1CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
RossComputerGuy
commented
Feb 5, 2024
@bjia56 Would you be willing to add the fix for the interpreter to your PR? |
bjia56
commented
Feb 5, 2024
@RossComputerGuy I haven't gotten around to building zig to test the interpreter fix yet, but hopefully will get to it later this week |
1768948 to
1cac117CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
1cac117 to
ff70ec3CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
ff70ec3 to
23dd13cCompare23dd13c to
9d74a70CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
9d74a70 to
7e19962CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
7e19962 to
062b86aCompare062b86a to
6bedfe1CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
6bedfe1 to
b4956c5CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
b4956c5 to
c0afe03Comparec0afe03 to
a1cabc9CompareBorrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
andrewrk
commented
May 9, 2024
Thank you @RossComputerGuy |
alexrp
commented
Jun 23, 2024
Just checking since I need this for my work over at #20389: What remains to be done here? 👀 |
RossComputerGuy
commented
Jun 23, 2024
@alexrp Just a review and merge |
| @@ -0,0 +1 @@ | |||
| #define NO_INITFINI 1 | |||
There was a problem hiding this comment.
Upstream glibc sets this to zero in this file.
There was a problem hiding this comment.
Alright, will change
There was a problem hiding this comment.
Sorry, I should have been clearer earlier. As a general principle, I think it's better to copy the file 1:1 from upstream glibc when we don't need any changes to it (which seems to be the case here), so there are less diffs to review when upgrading glibc.
| # define cfi_personality(enc, exp) .cfi_personality enc, exp | ||
| # define cfi_lsda(enc, exp) .cfi_lsda enc, exp | ||
| # ifndef __clang__ |
There was a problem hiding this comment.
I don't see this in upstream glibc. Should a patch be submitted?
There was a problem hiding this comment.
Maybe? Idk if we've ever sent a patch to glibc before.
There was a problem hiding this comment.
Ok, something is weird here:
❯ clang --versionUbuntu clang version 16.0.6 (15)Target: x86_64-pc-linux-gnuThread model: posixInstalledDir: /usr/bin
❯ clang -target riscv test.s -c
❯ clang -target riscv64 test.s -ctest.s:5:1: error: unknown directive.cfi_label .Ldummy^There was a problem hiding this comment.
Clang doesn't support the directive which is why we have this.
There was a problem hiding this comment.
Clang doesn't support the directive which is why we have this.
It's definitely an oversight. The MCStreamer code in LLVM has an API for emitting CFI labels, it's just that the MCParser hasn't been taught to parse them. Honestly a bit a surprised no one has run into this before as it affects ARC, C-SKY, and LoongArch too.
There was a problem hiding this comment.
We should be able to drop this workaround in LLVM 19: llvm/llvm-project#97922
There was a problem hiding this comment.
Sweet, amazing getting that done. Would that mean this PR will have to wait for the next LLVM version bump in Zig?
a1cabc9 to
caca200Comparealexrp
commented
Aug 7, 2024
Hey @RossComputerGuy I built on your work here in #20909 which is now in master. There's still the |
alexrp
commented
Oct 2, 2024
Closing since our |
Fixes#3340, builds with
zig build-exe bootstrap.c -lc -target riscv64-linux-gnu -mcpu=generic_rv64. I can't test this until I can get RISC-V hardware but this does fix compiling.