#Compiling process

31 messages · Page 1 of 1 (latest)

modest copper
#

Just a quick question, what is the compiling process called where you have your source files, they turn into obj, linked then you get your executable? I wanted to find some videos or documentation to learn more about this process. Thanks!!

wispy zincBOT
#

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.

bleak crag
#

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)

mint prism
#

gcc does that, msvc and clang - don't

bleak crag
#

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

mint prism
#

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
bleak crag
#

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

mint prism
#

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

bleak crag
#

That's neat, the gcc syntax is a bit of a headache

#

The extended one

mint prism
#

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

bleak crag
#

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 definitionhmmge

#

Or trick the compiler into jumping from one function to another

#

I wonder if there are sanity checks for that

livid kindle
#

Hi

#

Does anyone use vs code here

#

I have problem while running code

#

Code is not running

#

Give me suggestions what to do