News for hackers. Stuff that matters.
Re:Bare metal printf – C standard library without OS by alxmdev on Saturday April 26, 2025 @06:08PM (#43807643)
What's the state of the art for cross-compiling in $CURRENTYEAR?
Re:Bare metal printf – C standard library without OS by LorenzoGood on Saturday April 26, 2025 @06:57PM (#43807997)
Honesty probably zig cc.
Re:Bare metal printf – C standard library without OS by forrestthewoods on Saturday April 26, 2025 @06:11PM (#43807668)
> What's the state of the art for cross-compiling in $CURRENTYEAR?

Poopy garbage dog poop.

glibc is a dumpster fire of bad design. If you want to cross-compile for an arbitrarily old version of glibc then... good luck. It can be done. But it's nightmare fuel.

Re:Bare metal printf – C standard library without OS by achierius on Saturday April 26, 2025 @06:33PM (#43807811)
What sort of roadblocks do you run into? Just to get an idea for the flavor of problems.
Re:Bare metal printf – C standard library without OS by forrestthewoods on Saturday April 26, 2025 @06:55PM (#43807981)
Well there's two flavors to this. Building glibc and building a program that links against glibc. They're not entirely the same. And you'd think the latter is easier. But you'd be wrong!

It should be trivial to compile glibc with an arbitrary build system for any target Linux platform from any OS. For example if I'm on Windows and I want to build a program that targets glibc 2.23 for Ubuntu on x86_64 target that should be easy peasy. It is not.

glibc should have ONE set of .c and .h files for the entire universe. There should be a small number of #define macros that users need to specify to build whatever weird ass flavor they need. These macros should be plainly defined in a single header file that anyone can look at.

But glibc is a pile of garbage and has generated files for every damn permutation in the universe. This is not necessary. It's a function of bad design. Code should NEVER EVER EVER have a ./configure step that generates files for the local platform. EVER.

Read this blog post to understand the mountains that Zig moved to enable cross-compilation. It's insane. https://andrewkelley.me/post/zig-cc-powerful-drop-in-replace...

Re:Bare metal printf – C standard library without OS by rcxdude on Sunday April 27, 2025 @07:11AM (#43811061)
>glibc should have ONE set of .c and .h files for the entire universe. There should be a small number of #define macros that users need to specify to build whatever weird ass flavor they need. These macros should be plainly defined in a single header file that anyone can look at.

Code generation aside, this is not really a great way to do it either. The build should include target-specific files, as opposed to creating a maze of ifdefs inside the code.

Re:Bare metal printf – C standard library without OS by forrestthewoods on Sunday April 27, 2025 @02:14PM (#43813964)
> The build should include target-specific files, as opposed to creating a maze of ifdefs inside the code.

Hard disagree. What makes you think it's a maze of ifdefs?

Compiling a library should be as simple as "compile every .c/.cpp file and link them into a static/shared lib". The nightmare maze is when you don't do that and you need to painfully figure out which files you should and shouldn't include in this particular build. It's horrible.

Far far far simpler is to stick with the rule "always compile all files". It's very simple to ifdef out an entire file with a single, easily understood ifdef at the top.

I do agree you don't want the middle of a file to be a fully of 10 different ifdef cases. There's an art to whether to switch within a file or produce different files. No hard and fast rule there.

Fundamentally you put either your branching logic in the code or in the build system. And given that source files should be compatible with an unbounded array of potential build systems it is therefore superior to solve the problem once in the code itself.

I am currently trying to get the Zig glibc source/headers to compile directly via clang and trying to figure out which files to include or not include is infuriatingly unclear and difficult. So no, I strongly and passionately disagree that build-system is where this logic should occur. It's fucking awful.

Re:Bare metal printf – C standard library without OS by zahlman on Saturday April 26, 2025 @06:50PM (#43807943)
Is the cross-compilation story any better with musl?
Re:Bare metal printf – C standard library without OS by forrestthewoods on Sunday April 27, 2025 @02:52PM (#43814221)
tbh I haven't gone too deep because glibc is such a standard :(

but I can answer with reasonable confidence "musl surely has other problems, but not this one". It's a nice, clean, simple, single set of headers and source files. Very nice.

Re:Bare metal printf – C standard library without OS by sylware on Saturday April 26, 2025 @06:15PM (#43807696)
gcc and glibc SDKs are hell beyond anything sane.

Like it is done on purpose.

Re:Bare metal printf – C standard library without OS by forrestthewoods on Saturday April 26, 2025 @06:33PM (#43807807)
You're getting downvoted but you're not wrong. Well, it's not on purpose per se. It's just really really bad design from the 80s when we didn't know better. And unfortunately its design hasn't been fixed. So we have to deal with almost 40 years of accumulated garbage.
Re:Bare metal printf – C standard library without OS by doublepg23 on Saturday April 26, 2025 @06:49PM (#43807939)
Aren't there some ideologically driven decisions to make proprietary extensions harder/impossible?
Re:Bare metal printf – C standard library without OS by sylware on Sunday April 27, 2025 @09:08AM (#43811661)
They would be illegal everywhere the GNU GPL can be enforced.
Re:Bare metal printf – C standard library without OS by sylware on Sunday April 27, 2025 @09:01AM (#43811617)
Indeed, that why HN comments are kind of dead (AIs, zealots with one billion accounts behind VPNs, etc). Sometimes I do still try to give an honest, but unpleasant, opinion/fact though. I should stick to raw neutral communication and information publishing.
Re:Bare metal printf – C standard library without OS by o11c on Saturday April 26, 2025 @08:29PM (#43808438)
Well, I know it's pretty easy in Debian. (It's not completely pain-free if you need unpackaged third-party libraries and/or if you are cross-compiling from one uncommon architecture to another.)
Re:Bare metal printf – C standard library without OS by genewitch on Sunday April 27, 2025 @04:07AM (#43810291)
I just run gentoo and follow their cross-compile guide, as well as set up distcc; but that's for system packages.

TBH I'd use qemu if I had to make something work for arbitrary code.

https://wiki.gentoo.org/wiki/Crossdev

But there are others.