-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Rewrite generate_linux_syscalls.zig
#20895
Rewrite generate_linux_syscalls.zig
#20895
Conversation
tools/generate_linux_syscalls.zig
Outdated
|
||
if (!mem.eql(u8, prefix, "zigsyscall")) continue; | ||
const linux_dir = try std.fs.openDirAbsolute(linux_path, .{}); |
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.
const linux_dir = try std.fs.openDirAbsolute(linux_path, .{}); | |
var linux_dir = try std.fs.cwd().openDir(linux_path, .{}); | |
defer linux_dir.close(); |
This code was here prior to the rewrite but I noticed it while reviewing the diff - openDirAbsolute
doesn't actually do anything except assert that the path is absolute and then forward it to std.fs.cwd() openDir
, and there's no reason this program should only work with absolute paths.
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.
that makes sense, i should've paid attention to the missing dir close, thanks for pointing that out
tools/generate_linux_syscalls.zig
Outdated
comptime additional_args: ?[]const []const u8 = null, | ||
target: []const u8, | ||
|
||
pub inline fn get_args(self: *const @This(), zig_exe: []const u8, file_path: []const u8) []const []const u8 { |
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.
pub inline fn get_args(self: *const @This(), zig_exe: []const u8, file_path: []const u8) []const []const u8 { | |
pub inline fn getArgs(self: *const @This(), zig_exe: []const u8, file_path: []const u8) []const []const u8 { |
tools/generate_linux_syscalls.zig
Outdated
// TODO: maybe extract these from arch/arm/include/uapi/asm/unistd.h | ||
try writer.writeAll( | ||
const ArchInfo = union(enum) { | ||
tableBasedArch: struct { |
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.
tableBasedArch: struct { | |
table: struct { |
tools/generate_linux_syscalls.zig
Outdated
filters: Filters, | ||
additional_enum: ?[]const u8, | ||
}, | ||
preprocessedArch: struct { |
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.
preprocessedArch: struct { | |
preprocessor: struct { |
tools/generate_linux_syscalls.zig
Outdated
file_path: []const u8, | ||
header: ?[]const u8, | ||
extra_values: ?[]const u8, | ||
processFile: ProcessTableBasedArchFileFn, |
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.
processFile: ProcessTableBasedArchFileFn, | |
process_file: ProcessTableBasedArchFileFn, |
Likewise in the other case below.
Other than style nitpicks, this looks reasonable to me. Just as a sanity check, does it produce a byte-for-byte identical |
Does the hexagon arch work ? the only difference is the order of enums is different |
Yes, #20798 was merged, so a freshly built compiler should work.
It would be nice to maintain the current order just to reduce diff churn on the next syscalls update. But if that requires more work than just reordering the |
I ll recompile it on linux and test it and ensure all the values are in the same order |
@alexrp, After the changes there is no difference between |
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.
Great work!
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 appreciate you and @alexrp taking the time to extend/simplify the code, but I think these are the wrong abstractions for the table-based arch's. Given each table has the same structure of:
<number> <abi> <name> [everything else]
I think you can have a function that splits all the lines into these three strings, and then passes them into functions like so:
const Result = union(enum) {
entry: []const u8,
skip: void,
done: void,
};
*const fn (number: usize, abi: []const u8, name: []const u8, buf: []u8) Result;
That way you can pair everything down to a helper function and a couple of arch-specific Result
functions. Besides, a little copy-pasta never hurt anyone ;).
|
||
fn processPowerPcBasedArch( |
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.
This was a cute trick when I wrote it, but looking back I think it'd be better to split the logic for ppc32/6 and read the same file twice. It's not like this is performance critical.
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.
Any reasons on why it s a bad idea ? when i've worked on it other architectures can benefit from your trick like sparc/sparc64
which gets it's values from the same file arch/sparc/kernel/syscalls/syscall.tbl
and there is some weird abi
edge cases, but yeah it is not performance critical if you want me to separate them I can do that
tools/generate_linux_syscalls.zig
Outdated
const prefix = fields.next() orelse return error.Incomplete; | ||
// As of 5.17.1, the largest table is 23467 bytes. | ||
// 32k should be enough for now. | ||
const buf = try allocator.alloc(u8, 1 << 15); |
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 did this so that a single allocation could be done up front - and if there were problems one could bump the limit up. Now this gets called for every table arch and never gets free
'd.
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.
This is fixed, buf is just passed now, and readFile
returns a slice of buf [0..end]
tools/generate_linux_syscalls.zig
Outdated
|
||
const AbiCheckFn = *const fn (abi: []const u8) FlowControl; | ||
|
||
fn getAbiCheckFunction(comptime b: []const u8, comptime flow: FlowControl) AbiCheckFn { |
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.
Does this really need to be generated at compile-time?
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.
No not necessarily, it can be just a slice of (abi, flow) instead of a function pointer
I'm not sure I understood what you meant by your impl, what did you mean by three strings, and wouldn't this impl require more mem allocations for entry ? instead of writing it directly, you ll |
I'm happy to merge this when all the parties involved reach consensus. |
Once it's merged would there be interest in updating it to use aro instead of calling |
I have no strong feelings on the above suggestions. My primary concern was getting the copy/pasted code under control as it was getting annoying when I had to make edits to it. 🙂 |
I have no objections on the output - just style. I'm tied up today so I don't mind if this goes in as is. I second @ehaas's comments about just using Aro or clang - I'd like it so that we could run a pre-processor and get a list of key-value definitions. |
To quote |
OK I went to merge this but then I realized it effectively has no commit message, not even a commit title ("rewrite $foo" does not contain any more information than the git commit metadata). Can you at least explain what this does? Note, you didn't say closes any particular issue, you just mentioned that it is related. So there's actually no description in the PR writeup or commit messages as to your goals, and whether they were achieved, and how you tested, etc. |
@andrewrk I've updated the PR description, sorry for the hassle i didn't think it need a description will make sure to be more specific next time on each change ! |
refactors the syscall generation tool aiming to reduce code duplication for both the table based arches and the ones generated using a preprocessor.
@alexrp is the issue still existing in the PR the issue is in |
I pushed a fixed |
@alexrp it was there before as well, basically after each enum generated |
@alexrp can you try with this generate_linux_syscalls.zig and see if the issue is still persisting ? I've tried it should be good to go, I ll have to fix my zig build dependencies as I can't rebuild zig on my machine currently :/ PR: #21005 |
refactors the syscall generation tool aiming to reduce code duplication for both the table based arches and the ones generated using a preprocessor.
refactors the syscall generation tool aiming to reduce code duplication for both the table based arches and the ones generated using a preprocessor.
Related: #20801, #20869
Closes: #20801
Description:
This PR refactors the syscall generation tool aiming to reduce code duplication for both the table based arches and the ones generated using a preprocessor.
The
ArchInfo
union contains 2 tags.table
and.preprocessor
To add an Arch that depends on a
tbl
file, use the following structure:To add an Arch that is generated using a preprocessor, use the following structure
The generated enum will be in this format:
How it's tested:
Ran the tool and generated the enums and diffed them with
lib/std/os/linux/syscalls.zig
from master to make sure everything works the same