Operating System/System Programming(Arif Butt)

Lec02) C Compilation: A System Programmer Perspective

Tony Lim 2021. 6. 9. 15:09
728x90

-E = Stop after the preprocessing stage. the output is form of preprocessed soruce code.

-S = Stop after the stage of compilation proper. don't assemble. form of an assembler code file for each non-assembler input file specified. basically just do compilation

 

-c = Compile or assemble the source files, but don't link. output is form of an object file for each source file.

-ggdb = Produce debugging information for use by GDB.

 

we need to link printf.o file with our hello.o file.  libc.a is dynamic library.

 

notice size is much smaller on dynamicexe. it don't contain code of printf.o. to execute with dynamic library system must have specific library.

 

ELF format

it is a format for storing programs or fragments of programs on disk, created as a result of compiling and linking.

An executable file using the ELF format consist of ELF Header , Program Header Table an Section Header Table.

  • Relocatable file ojbects (.o)
  • Normal excutabl efiles (a.out)
  • Shared object files (.so)

Magic number act as file extension telling OS this is a certain format.

 

16 general purpose registers , rip== instruction pointer , segment registers.

with "info all-registers" command we can see rest of registers.

 

psuedo code for statring executable file. 

 

executing systemcall using syscall , no wrapper function and with assembly code.

 

728x90