What are the internal processes for compiling C?

I have a set of * .C files (built-in linked). Can someone explain to me the steps / processes (internal information) involved during compilation, followed by a link to create the final executable (I need information / steps on what the preprocessor / compiler usually does with C src code)

Also, I just want to get an idea of ​​the general structure of the final executable (for example: headers followed by symbol tables, etc. etc.)

Also, please let me know if someone has already discussed the same topic before.

__ Kanu

+3
source share
3

gcc, , , - -save-temps.

, , . , (bison, yacc, flex ..), , ascii, - .

a = a + 1;

Load variable named a, size of blah, type unsigned foo
load immediate 1, size blah, unsigned
add
store result a

, , , 1 add. , . , , . , , , . bob, bob, , - , , bob ( ), , bob, , , bob, .

llvm, gcc, . C . bob

unsigned int bob ( unsigned int a )
{
    return(a+1);
}

clang -c -o bob.bc -emit-llvm bob.c

-

llvm-dis bob.bc

bob.ll

define i32 @bob(i32 %a) nounwind {
entry:
  %a.addr = alloca i32, align 4
  store i32 %a, i32* %a.addr, align 4
  %tmp = load i32* %a.addr, align 4
  %add = add i32 %tmp, 1
  ret i32 %add
}

, , , .

, , llvm , , , gcc . .

opt -std-compile-opts bob.bc -o bob_opt.bc
llvm-dis bob_opt.bc

, .

define i32 @bob(i32 %a) nounwind readnone {
entry:
  %add = add i32 %a, 1
  ret i32 %add
}

llc ,

llc -march=arm bob.bc
cat bob.s
...
bob:                                    @ @bob
@ BB#0:                                 @ %entry
    str r0, [sp, #-4]!
    add r0, r0, #1
    add sp, sp, #4
    bx  lr
...
llc -march=arm bob_opt.bc
cat bob_opt.s
...
bob:                                    @ @bob
@ BB#0:                                 @ %entry
    add r0, r0, #1
    bx  lr
...

, . .. llvm, (, qemu) , , , http://bellard.org/fbcc/, , , , , . , , tcc http://bellard.org/tcc/, , , , ().

+3

, , SO. , , A Retargetable C Compiler. C ( , lcc).

+3

, (-) . ( , , ). , , .

, / . , a.c a, b.c a(), b, "" a, . ( , , , .. ..)

; .EXE(32 64 ), ELF Mach-O.

Linux , .

+1

Source: https://habr.com/ru/post/1766955/


All Articles