-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
errno definitions not an integer constant #103
Comments
The switch statements need to be if statements. You've identified the one key area where we have no choice but to bend the POSIX rules, as discussed in the APE blog post: https://justine.lol/ape.html In the future we might be able to modify chibicc to be lenient about symbolic cases but it's something that's unlikely to make it into the C standard. For more background on why things need to be this way, having a symbol for things like |
I'm not sure I understand the reason for the incompatibility... Wouldn't something like this do the trick?
The |
@jacereda's question came up in a discussion regarding a proposed change to Rust: rust-lang/rfcs#3305 (comment) |
@jacereda In order to use POSIX magic numbers as constants, like the rest of the C community, we'd have to have every system interface (e.g. read, write, etc.) translate the magic numbers to the Linux values, for all possible numbers. That entails lots of bloat that would add to our static binaries. What I like about having constants be symbolic is it means we only have to pay for what we use. For example, if the only thing you care about is if The tradeoff is these gosh darn switch() statements. We must find a way to address this because it's such a big issue. Possibly by modifying the C language itself to permit smarter relocations. |
@Jules-Bertholet I've replied to the Rust thread and brought up some other good points, like how many magic numbers (e.g. termios) are sparse; therefore, system call wrappers would need to do things like binary searches every time you interact with the kernel. That's slow! rust-lang/rfcs#3305 (comment) |
(If you used a perfect hash table instead of a binary search, you wouldn't need any branches. Even with a binary search, the runtime cost would likely be dwarfed by the cost of even just entering and leaving the kernel [at least with speculative execution mitigations enabled], never mind doing the actual work of the syscall. And yet I can definitely sympathize with the concern when it comes to code size, or even bloat from an aesthetic perspective… Anyway, that's just my personal opinion. I'm just a commenter – in particular, not a member of any Rust team.) |
I was experimenting with compiling some non-cosmo code and came across this error:
I tried moving things around in
cosmopolitan.h
a bit, but no joy. It seems that the actual definition is inlibc/sysv/consts/ENOENT.S
, and I guess it changes (for some of them at least) at runtime. Is there any way to get around this, or would it be better to patch the code to useif
/else
instead ofswitch
?The text was updated successfully, but these errors were encountered: