Top
Best
New

Posted by ingve 4/15/2025

What the hell is a target triple?(mcyoung.xyz)
171 points | 133 commentspage 3
dvektor 4/16/2025|
Great read. Love those articles where you go in thinking that you have a pretty solid understanding of the topic and then proceed to learn much more than you thought you would.
theoperagoer 4/15/2025||
Great content. Also, this website is gorgeous!
o11c 4/15/2025||
This article should be ignored, since it disregards the canonical origin of target triples (and the fact that it's linked to `configure`):

https://git.savannah.gnu.org/cgit/config.git/tree/

The `testsuite/` directory contains some data files with a fairly extensive list of known targets. The vendor field should be considered fully extensible, and new combinations of know machine/kernel/libc shouldn't be considered invalid, but anything else should have a patch submitted.

jcranmer 4/15/2025||
This article is a very LLVM-centric view, and it does ignore the GNU idea of a target triple, which is essentially $(uname -a)-vendor-$(uname -s), with vendor determined (so far as I can tell) entirely from uname -s, the system name undergoing some amount of butchering, and version numbers sometimes being included and sometimes not, and Linux getting a LIBC tacked on.

But that doesn't mean the article should be ignored in its entirety. LLVM's target triple parsing is more relevant for several projects (especially given that the GNU target triple scheme doesn't include native Windows, which is one of the most common targets in practice!). Part of the problem is that for many people "what is a target triple" is actually a lead-in to the question "what are the valid targets?", and trying to read config.guess is not a good vehicle to discover the answer. config.guess isn't also a good way to find about target triples for systems that aren't designed to run general-purpose computing, like if you're trying to compile for a GPU architecture, or even a weird x86 context like UEFI.

o11c 4/15/2025|||
The GNU scheme does in fact have support for various windows targets. It's just that the GNU compilers don't support them all.
pjc50 4/15/2025|||
There's MinGW.
bruce343434 4/15/2025||
Why does this person have such negative views of GCC and positive bias towards LLVM?
nemothekid 4/15/2025||
If OP is above 30 - it's probably due to the frustration of trying to modularize GCC that led to the creation of LLVM in the first place. If OP is below 30, it's probably because he grew up in a world where most compiler research and design is done on LLVM and GCC is for grandpa.
steveklabnik 4/15/2025|||
I have intense respect for the history of gcc, but everything about using it screams that it's stuck in the past.

LLVM has a lot of problems, but it feels significantly more modern.

I do wish we had a "new LLVM" doing to LLVM what it did to gcc. Just because it's better doesn't mean it's perfect.

Basically, you can respect history while also being honest about the current state of things. But also, doing so requires you to care primarily about things like ease of use, rather than things like licenses. For some people, they care about licenses first, usability second.

tialaramex 4/15/2025|||
Their IR is a mess. So a "new LLVM" ought to start by nailing down the IR.

And as a bonus, seems to me a nailed down IR actually is that portable assembly language the C people keep telling us is what they wanted. Most of them don't actually want that and won't thank you - but if even 1% of the "I need a portable assembler" crowd actually did want a portable assembler they're a large volume of customers from day one.

o11c 4/16/2025||
Having tried writing plugins for both, I very much prefer GCC's codebase. You have to adapt to its quirks, but at least it won't pull the rug from under your feet gratuitously. There's a reason every major project ends up embedding a years-old copy of LLVM rather than just using the system version.

If you're ignoring the API and writing IR directly there are advantages to LLVM though.

flkenosad 4/15/2025|||
Honestly, I love that both exist with their respective world views.
steveklabnik 4/15/2025||
I for sure don't want to suggest that anyone who loves gcc shouldn't be working on what they love. More compilers are a good thing, generally. Just trying to say why I have a preference.
Skywalker13 4/15/2025|||
It is unfortunate. GCC has enabled the compilation of countless lines of source code for nearly 40 years and has served millions of users. Regardless of whether its design is considered good or bad today, GCC has played an essential role and has enabled the emergence of many projects and new compilers. GCC deserves deep respect.
matheusmoreira 4/15/2025|||
Good question. Author is incredibly hostile to one of the most important pieces of software ever developed because of the way they approached the problem nearly 40 years ago. Then he criticizes Go for trying to redesign the system instead of just using target triples...
FitCodIa 4/15/2025||
The author writes: "really stupid way in which GCC does cross compiling [...] Nobody with a brain does this [...]", and then admits in the footnote, "I’m not sure why GCC does this".

Immature to the point of alienating.

xyst 4/15/2025|||
Seems to have a decent amount of knowledge in this domain in education and professional work. Author is from MIT so maybe professors had a lot of influence here.

also, gcc is relatively old and comes with a lot of baggage. LLVM is sort of the defacto standard now with improvements in performance

rlpb 4/15/2025|||
> LLVM is sort of the defacto standard now...

Distributions, and therefore virtually all the software used by a distribution user, still generally use gcc. LLVM is only the de facto standard when doing something new, and for JIT.

bruce343434 4/15/2025|||
as someone who uses both Clang and GCC to cover eachothers weaknesses, as far as I can tell both LLVM and GCC are hopelessly beastly codebases in terms of raw size and their complexity. I think that's just what happens when people desire to build an "everything compiler".

From what I gathered, LLVM has a lot of C++ specific design choices in its IR language anyway. I think I'd count that as baggage.

I personally don't think one is better than the other. Sometimes clang produces faster code, sometimes gcc. I haven't really dealt with compiler bugs from either. They compile my projects at the same speed. Clang is better at certain analyses, gcc better at certain others.

ahartmetz 4/15/2025||
Clang used to compile much faster than GCC. I was excited. Now there is barely any difference, so I keep using GCC and occasionally some Clang-based tools such as iwyu, ClangBuildAnalyzer or sanitizer options (rare, Valgrind is easier and more powerful though sanitizers also have unique features).
flkenosad 4/15/2025|||
It's the new anti-woke mind virus going around attacking anything "communist" such as copyleft, Stallman, GCC, GNU, etc.
AceJohnny2 4/15/2025||
Offtopic, but I'm distracted by the opening example:

> After all, you don’t want to be building your iPhone app on literal iPhone hardware.

iPhones are impressively powerful, but you wouldn't know it from the software lockdown that Apple holds on it.

Example: https://www.tomsguide.com/phones/iphones/iphone-16-is-actual...

There's a reason people were clamoring for Apple to make ARM laptops/desktops for years before Apple finally committed.

AceJohnny2 4/15/2025||
I do not think I like this author...

> A critical piece of history here is to understand the really stupid way in which GCC does cross compiling. Traditionally, each GCC binary would be built for one target triple. [...] Nobody with a brain does this ^2

You're doing GCC a great disservice by ignoring its storied and essential history. It's over 40 years old, and was created at a time where there were no free/libre compilers. Computers were small and slow. Of course you wouldn't bundle multiple targets in one distribution.

LLVM benefitted from a completely different architecture and starting from a blank slate when computers were already faster and much larger, and was heavily sponsored by a vendor that was innately interested in cross-compiling: Apple. (Guess where LLVM's creator worked for years and lead the development tools team)

jaymzcampbell 4/15/2025|||
The older I get the more this kind of commentary (the OP, not you!) is a total turn off. Systems evolve and there's usually, not always, a reason for why "things are the way they are". It's typically arrogance to have this kind of tone. That said I was a bit like that when I was younger, and it took a few knockings down to realise the world is complex.
steveklabnik 4/15/2025||||
"This was the right way to do it forty years ago, so that's why the experience is worse" isn't a compelling reason for a user to suffer today.

Also, in this specific case, this ignores the history around LLVM offering itself up to the FSF. gcc could have benefitted from this fresh start too. But purely by accident, it did not.

FitCodIa 4/15/2025|||
> "This was the right way to do it forty years ago, so that's why the experience is worse" isn't a compelling reason for a user to suffer today.

On my system, "dnf repoquery --whatrequires cross-gcc-common" lists 26 gcc-*-linux-gnu packages (that is, kernel / firmware cross compilers for 26 architectures). The command "dnf repoquery --whatrequires cross-binutils-common" lists 31 binutils-*-linux-gnu packages.

The author writes, "LLVM and all cross compilers that follow it instead put all of the backends in one binary". Do those compilers support 25+ back-ends? And if they do, is it good design to install back-ends for (say) 23 such target architectures that you're never going to cross-compile for, in practice? Does that benefit the user?

My impression is that the author does not understand the modularity of gcc cross compilers / packages because he's unaware of (or doesn't care for) the scale that gcc aims at.

steveklabnik 4/15/2025||
> And if they do, is it good design to install back-ends for (say) 23 such target architectures that you're never going to cross-compile for, in practice? Does that benefit the user?

   rustc --print target-list | wc -l
  287
I'm kinda surprised at how large that is, actually. But yeah, I don't mind if I have the capability to cross-compile to x86_64-wrs-vxworks that I'm never going to use.

I am not an expert on all of these details in clang specifically, but with rustc, we take advantage of llvm's target specifications, so you that you can even configure a backend that the compiler doesn't yet know about by simply giving it a json file with a description. https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target...

While these built-in ones aren't defined as JSON, you can ask the compiler to print one for you:

     rustc +nightly -Z unstable-options --target=x86_64-unknown-linux-gnu --print target-spec-json
It's lengthy so instead of pasting here, I've put this in a gist: https://gist.github.com/steveklabnik/a25cdefda1aef25d7b40df3...

Anyway, it is true that gcc supports more targets than llvm, at least in theory. https://blog.yossarian.net/2021/02/28/Weird-architectures-we...

AceJohnny2 4/15/2025|||
I'd love to learn what accident you're referring to, Steve!

I vaguely recall the FSF (or maybe only Stallman) arguing against the modular nature of LLVM because a monolothic structure (like GCC's) makes it harder for anti-GPL actors (Apple!) to undermine it. Was this related?

steveklabnik 4/15/2025||
That is true history, in my understanding, but it's not related.

Chris Lattner offered to donate the copyright of LLVM to the FSF at one point: https://gcc.gnu.org/legacy-ml/gcc/2005-11/msg00888.html

He even wrote some patches: https://gcc.gnu.org/legacy-ml/gcc/2005-11/msg01112.html

However, due to Stallman's... idiosyncratic email setup, he missed this: https://lists.gnu.org/archive/html/emacs-devel/2015-02/msg00...

> I am stunned to see that we had this offer.

> Now, based on hindsight, I wish we had accepted it.

Note this email is in 2015, ten years after the initial one.

amszmidt 4/24/2025|||
The only truth to the story is the missed email.

There is nothing "unmodular" about GCC -- considering that it supports plenty of architectures, operating systems, and languages.

The big difference, which people seem to miss in the context of the GNU project and GNU system, is that modularity is for free software projects. GCC is planty modular, and very easy to extend in any way shape or form .. if you abide by the license!

If you want to be a parasite on a project licensed under the GNU GPL, you will have a rough ride .. that is after all the whole idea of copyleft.

Philpax 4/15/2025||||
Incredible. Thank you for sharing.
steveklabnik 4/15/2025||
You're welcome! It's a wild story. Sometimes, history happens by accident.
matheusmoreira 4/15/2025|||
Wow that is wild. Imagine how different things could have been...
FitCodIa 4/15/2025|||
> and was heavily sponsored by a vendor that was innately interested in cross-compiling

and innately disinterested in Free Software, too

boricj 4/15/2025|||
A more pertinent (if dated) example would be "you don't want to be building your GBA game on literal Game Boy Advance hardware".
richardwhiuk 4/15/2025||
Or a microcontroller
plorkyeran 4/16/2025|||
iPhones have terrible heat dispersion compared to even a fanless computer like a macbook air. You get a few minutes at full load before thermal throttling kicks in, so you could do the occasional build of your iPhone app on an iPhone but it'd be pretty terrible as a development platform.

At work we had some benchmarking suites that ran on physical devices and even with significant effort put into cooling them they spent more time sleeping waiting to cool off than actually running the benchmarks.

Joker_vD 4/16/2025||
> no one calls it x64 except for Microsoft. And even though it is fairly prevalent on Windows, I absolutely give my gamedev friends a hard time when they write x64.

So, it turns out, actually a lot of people call it x64 — including author's own friends! — it's just that the author dislikes it. Disliking something is fine, but why claim outright falsehood which you know first-hand is false?

Also, the actual proper name for this ISA is, of course, EM64T. /s

> The fourth entry of the triple (and I repeat myself, yes, it’s still a triple)

Any actual justification except the bald assertions from the personal preferences? Just call it a "tuple", or something...

kridsdale1 4/15/2025||
I really appreciate the angular tilt of the heading type on that blog.
Retr0id 4/15/2025|
Note to author, I'm not sure the word "anachronism" is being used correctly in the intro.
kupiakos 4/15/2025||
It's being used correctly: something that is conspicuously old-fashioned for its environment is an anachronism. A toolchain that only supports native builds fits.
Retr0id 4/15/2025||
The article does not place any given toolchain within an incorrect environment, though.

If someone said "old compilers were usually cross-compilers", that would be an ahistoric statement (somewhat).

If someone used clang in a movie set in the 90s, that would be anachronistic.

bqmjjx0kac 4/15/2025|||
It's technically correct, but feels a bit forced.
compyman 4/15/2025||
I think the meaning is that the idea that compilers can only compile for their host machine is an ananchronism, since that was historically the case but is no longer true.
bregma 4/15/2025|||
Heck, it hasn't been true since the 1950s. Consider it as "has never been true".

Oh, sure, there have been plenty of native-host-only compilers. It was never a property of all compilers, though. Most system brings-ups, from the mainframes of the 1960s through the minis of the 1970s to the micros and embeddeds of the 1980s and onwards have required cross compilers.

I think what he means is that a single-target toolchain is an anachronism. That's also not true, since even clang doesn't target everything under the sun in one binary. A toolchain needs far more than a compiler, for a start; it needs the headers and libraries and it needs a linker. To go from source to executable (or herd of dynamic shared objects) requires a whole lot more than installing the clang (or whatever front-end) binary and choosing a nifty target triple. Most builds of clang don't even support all the interesting target triples and you need to build it yourself, which require a lot more computer than I can afford.

Target triples are not even something limited to toolchains. I maintain software that gets cross-built to all kinds of targets all the time and that requires target triples for the same reasons compilers do. Target triples are just a basic tool of the trade if you deal with anything other than scripting the browser and they're a solved problem rediscovered every now and then by people who haven;t studied their history.

stefan_ 4/15/2025|||
Telling people that "Clang can compile for any architecture you like!" tends to confuse them more than it helps. I suppose it sets up unrealistic assumptions because of course outputting assembly for some architecture is a very long way from making working userland binaries for a system based on that architecture, which is what people actually want.

And ironically in all of this, building a full toolchain based on GCC is still easier than with LLVM.