120 likes | 215 Views
UEE0UQC122S3. Special compilation problems for cross development. Breaking down the compilation process. Compilation is made up of a number of phases Preprocessing Compilation Can be a number of passes Optimisation Link/loading. The compilation process. cc –flags myfile.c thisfile.o.
E N D
UEE0UQC122S3 Special compilation problems for cross development
Breaking down the compilation process • Compilation is made up of a number of phases • Preprocessing • Compilation • Can be a number of passes • Optimisation • Link/loading
The compilation process cc –flags myfile.c thisfile.o Preprocessing Compilation Optimisation* Link/loading Assembler or Object format Relocatable Object file Executable Binary Text #includes .h header files #defines Object files Library file Start-up code *optional
Preprocessing • ccp is the C preprocessor • Really a text editor – text input and output • Uses in #include file ( /usr/include in UNIX) • Related to libraries & systems calls through prototypes and struct definitions • Deals with macros and constants • Can get output • Cc –E file.c
Compilation • This is often called c1 or cl • Can be 1 or 2 passes • Creates either intermediate object format or assembler file • Can contain the optimisation phase turned on/off by a command line flag • Several/separate files can be compiled to object files • cc –c file.c creates file.o
Optimisation • Can be a separate phase or part of main C compiler • Is optional – quite often turned off for cross development
Assembly • If the compiler produces assembler code then this can be sent to the assembler • It is worth noting • That the assembly code can be non-standard • Debugging may have to be done at assembly level • Can hand optimise • Helpful for understanding ALP/HLL linkage
Link Loading • Normally the program ld, gld, l1 • Can link together various object and library file • Controlled by a linker language • Produces map and symbol table output • Very important for cross development
Code Data BSS Heap Stack Program Segments char strng=“hello”; int count, this, that; main() { int i, j, k; char *sp; …….. for (i=0;i != 100;i++) …… sp= (char*) malloc(sizeof(i));
Executable formats • There are a number of different exectuable formats • A.out is the traditional UNIX format • Elf – executable and linking format • COFF – common object format • Plus lots of others
Variable initialisation • Some is done by the compiler • .data instructions • Some by the linker • And some by the operating system
Elf format e_indent e_entry e_phoff e_phentsize e_phnum ‘E’ ‘L’ ‘F’ 0x8048090 52 52 2 PT_LOAD 0 0x804800 68532 68532 PF_R, PF_X p_type p_offset p_vaddr p_filesz p_memsz p_flags Physical Header p_type p_offset p_vaddr p_filesz p_memsz p_flags PT_LOAD 68536 0x8059BB8 2200 4248 PF_R, PF_W Physical Header CODE DATA