-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
glibc: add changes to make riscv64-linux-gnu works #18803
glibc: add changes to make riscv64-linux-gnu works #18803
Conversation
I applied this PR's patch to the prebuilt |
75a8de3
to
54e33ef
Compare
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 |
note that this patch should additionally be sent upstream so its not lost in zig when we next upgrade glibc |
d2f5926
to
f3d9547
Compare
f3d9547
to
5b803ae
Compare
Woops, made a mistake |
@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. |
Might also fix ziglang/zig-bootstrap#115 |
@RossComputerGuy Regarding the
While an empty file might fix compilation, I'm not sure if it'll produce correct behavior. |
@bjia56 Alright, I'll copy that in. |
f3d9547
to
a21352b
Compare
Borrow 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
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 |
I've just been using QEMU userspace emulation ( |
With the most recent patches from this PR applied to
Note that the interpreter is |
Using patchelf to switch the interpreter to |
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... |
Actually, nvm on the previous post - this file doesn't seem to be pulled in as part of compilation. |
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
e4da8e1
Compare
Borrow 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
@bjia56 Would you be willing to add the fix for the interpreter to your PR? |
@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
1cac117
Compare
Borrow 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
ff70ec3
Compare
Borrow 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
23dd13c
Compare
23dd13c
to
9d74a70
Compare
Borrow 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
7e19962
Compare
Borrow 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
062b86a
Compare
062b86a
to
6bedfe1
Compare
Borrow 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
b4956c5
Compare
Borrow 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
c0afe03
Compare
c0afe03
to
a1cabc9
Compare
Borrow 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
Thank you @RossComputerGuy |
Just checking since I need this for my work over at #20389: What remains to be done here? 👀 |
@alexrp Just a review and merge |
@@ -0,0 +1 @@ | |||
#define NO_INITFINI 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upstream glibc sets this to zero in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -56,6 +56,12 @@ | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this in upstream glibc. Should a patch be submitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? Idk if we've ever sent a patch to glibc before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, something is weird here:
❯ clang --version
Ubuntu clang version 16.0.6 (15)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
❯ clang -target riscv test.s -c
❯ clang -target riscv64 test.s -c
test.s:5:1: error: unknown directive
.cfi_label .Ldummy
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clang doesn't support the directive which is why we have this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to drop this workaround in LLVM 19: llvm/llvm-project#97922
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, amazing getting that done. Would that mean this PR will have to wait for the next LLVM version bump in Zig?
a1cabc9
to
caca200
Compare
Hey @RossComputerGuy I built on your work here in #20909 which is now in master. There's still the |
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.