#Compiling process
31 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Linking
I mean the last part is linking
The first part is compilation and assembly
Compilation per se just turns source files (text) into assembly files (text too). Only when you assemble those you get object files (binary)
that isn't the only approach, I would doubt it is even the statistically dominant one
gcc does that, msvc and clang - don't
I don't think even gcc does it anymore
Oh wait not it probably does, that's why it needs binutils
But idk if they actually go through the effort of generating an assembly file, don't they just keep it in memory and somehow pass that to the assembler?
Anyway I'm curious, what does clang/llvm do different?
I know I can tell clang to generate assembly files with pretty much the same command line options as with gcc, but maybe they just put that for compatibility reasons
that is compatibility, as far as I know normally the frontend generates just binary intermediate representation (this one can also be dumped in the text format), that one is transformed for optimizations and the backend generates machine code directly
as for gcc:
$ strace -fe openat gcc x.c|&grep -E 'O_(WRONLY|RDWR)'
openat(AT_FDCWD, "/tmp/cct6f6UK.s", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[pid 61621] openat(AT_FDCWD, "/tmp/cct6f6UK.s", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
openat(AT_FDCWD, "/tmp/ccHfVZFG.o", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[pid 61622] openat(AT_FDCWD, "/tmp/ccHfVZFG.o", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3
openat(AT_FDCWD, "/tmp/ccZvGItH.res", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[pid 61623] openat(AT_FDCWD, "/tmp/ccROl07Z.cdtor.c", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[pid 61623] openat(AT_FDCWD, "/tmp/cc0zDhqN.cdtor.o", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[pid 61624] openat(AT_FDCWD, "a.out", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3
That's interesting, I wonder how that interferes with inline assembly
in the gcc mode of operation you just emit the inline assembly, does clang need to also call a completely different assembly front end?
Which would be a kinda trivial one I suppose
I don't know the details, but for sure it is more sophisticated than in gcc, iirc it has even msvc-compatibility mode when it is the compiler role to infer clobbered registers
so it's not a dumb copy-paste
or even just blindly assemble and paste machine code
ineed, and msvc had an easy one for x86-32, but dropped for x86-64 and I thiiiiink I've seen that clang can do MS-way in x86-64 as well
I feel like having a full blown assembler let's you do some powerful and cursed stuff with inline assembly tho, like you could pass inline directives to define a symbol within it and have some kind of nested function definition
Or trick the compiler into jumping from one function to another
I wonder if there are sanity checks for that