Live data from Hacker News

What the hell is a target triple?

mcyoung.xyz

91–100 of 139 posts

Re: What the hell is a target triple?

#91
post #44

The author's blog is a FANTASTIC source of information. I recommend checking out some of their other posts: - https://mcyoung.xyz/2021/06/01/linker-script/ - https://mcyoung.xyz/2023/08/09/yarns/ - https://mcyoung.xyz/2023/08/01/llvm-ir/

Given TFA's bias against GCC, I'm not so sure. e.g. looking at the linker script article… it's also missing the __start_XYZ and __stop_XYZ symbols automatically created by the linker.

It also focuses exclusively on sections. I wish it had at least mentioned segments, also known as program headers. Linux kernel's ELF loader does not care about sections, it only cares about segments.

Sections and segments are more or less the same concept: metadata that tells the loader how to map each part of the file into the correct memory regions with the correct memory protection attributes. Biggest difference is segments don't have names. Also they aren't neatly organized into logical blocks like sections are, they're just big file extents. The segments table is essentially a table of arguments for the mmap system call.

Learning this stuff from scratch was pretty tough. Linker script has commands to manipulate the program header table but I couldn't figure those out. In the end I asked developers to add command line options instead and the maintainer of mold actually obliged.

Looks like very few people know about stuff like this. One can use it to do some heavy wizardry though. I leveraged this machinery into a cool mechanism for embedding arbitrary data into ELF files. The kernel just memory maps the data in before the program has even begun execution. Typical solutions involve the program finding its own executable on the file system, reading it into memory and then finding some embedded data section. I made the kernel do almost all of that automatically.

https://www.matheusmoreira.com/articles/self-contained-lone-...

Re: What the hell is a target triple?

#92
post #80

Earlier quoted context omitted.

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...…

Incredible. Thank you for sharing.

You're welcome! It's a wild story. Sometimes, history happens by accident.

Re: What the hell is a target triple?

#93

Earlier quoted context omitted.

"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.

> "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 aut…

> 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...

Re: What the hell is a target triple?

#94

Sorry, going to keep typing x64. Unlike the article's recommendation of x86, literally everyone knows exactly what it means at all times.

If someone tells me x86, I am certainly thinking 32-bit protected mode not 64-bit long mode... Granted I'm in the weird space where I know enough to be dangerous but not enough to keep me up-to-date with idiomatic naming conventions.

Re: What the hell is a target triple?

#95
post #44

The author's blog is a FANTASTIC source of information. I recommend checking out some of their other posts: - https://mcyoung.xyz/2021/06/01/linker-script/ - https://mcyoung.xyz/2023/08/09/yarns/ - https://mcyoung.xyz/2023/08/01/llvm-ir/

Given TFA's bias against GCC, I'm not so sure. e.g. looking at the linker script article… it's also missing the __start_XYZ and __stop_XYZ symbols automatically created by the linker.

I was really struck by the antipathy toward GCC. I'm not sure I quite understand where it's coming from.

Re: What the hell is a target triple?

#96

Some other sources of target triples (some mentioned in the article, some not): rustc: `rustc --print target-list` golang: `go tool dist list` zig: `zig targets` As the article point out, the complete lack of standardization and consistency in what constitutes a "triple" (sometimes actually a quad!) is kind of hellishly hilarious.

> what constitutes a "triple" (sometimes actually a quad!)

It is actually a quintiple at most because the first part, architecture, may contain a version for e.g. ARM. And yet it doesn't fully describe the actual target because it may require an additional OS version for e.g. macOS. Doubly silly.

Re: What the hell is a target triple?

#97

Why does this person have such negative views of GCC and positive bias towards LLVM?

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…

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.

Re: What the hell is a target triple?

#98
post #74

Earlier quoted context omitted.

That's because on Linux systems it's typical for domain name resolution to be provided by glibc. As a result, people ended up depending on glibc. They were writing GNU/Linux software, not Linux software. https://wiki.archlinux.org/title/Domain_name_resolution https://en.wikipedia.org/wiki/Name_Service_Switch https://man.archlinux.org/man/getaddrinfo.3 This is user space stuff. You can trash all of this and roll your…

I mean, that is fine and all, but it doesn't really matter for making the software run correctly on systems that currently exist.

It works fine on current Linux systems. We can have freestanding executables that talk to Linux directly and link against zero system libraries.

It's just that those executables are going to have to resolve names all by themselves. Chances are they aren't going to do it exactly like glibc does. That may or may not be a problem.

Re: What the hell is a target triple?

#99
post #37

Earlier quoted context omitted.

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

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'…

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).

Re: What the hell is a target triple?

#100

Earlier quoted context omitted.

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?

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...…

Wow that is wild. Imagine how different things could have been...
Post reply on HN