본문 바로가기
시스템sw및실습

[시소실] 4. System Software and Program Execution (1)

by leziwn.cs 2023. 9. 23.
  • 고급 언어 프로그램 (source file)
    --> 컴파일러
  • 어셈블리 프로그램
    --> 어셈블러
  • 기계어 프로그램 (object file)
    --> 링커
  • 기계어 프로그램 (실행파일; executable file): object file + library file
    --> 로더
  • 메모리

 

Program Execution과 관련한 System Software
  • 컴파일러: 고급 언어 프로그램 --> 어셈블리 프로그램(ex: MIPS)
  • 어셈블러: 어셈블리 프로그램 --> 기계어 프로그램(object file)
  • 링커: 기계어 프로그램(object file) --> + library file --> 기계어 프로그램(실행파일; executable file)
  • 로더: 기계어 프로그램(실행파일; executable file)을 메모리로 올린다.

 

Programming Language
  • 고급 언어(high level language)
  • 어셈블리 언어(assembly language)
  • 기계어(machine language)

Programming Language: 고급 언어 --> 어셈블리 언어 --> 기계어

 

Separate Compile
  • Compile: 고급 언어 프로그램(one.c, two.c, three.c) --> 어셈블리 프로그램
  • Assemble: 어셈블리 프로그램 --> 기계어 프로그램(object file -- one.o, two.o, three.o)
  • Link: 기계어 프로그램(object file) --> 기계어 프로그램(실행파일: x.exe)

 

▶ Separate compile

: symbol(변수, 함수 등의 이름)의 위치 불명확, type만 파악 --> object file (*.o, *.obj)

 

▶ Linking

: symbol의 위치 명확 --> execution file (a.out, *.exe)

 

고급 언어 프로그램 - extern

고급 언어 프로그램 -  extern

: 고급 언어 프로그램에서 같은 변수 공유한다. --> extern을 통해 변수를 통합한다.

 

실행파일 - Symbol Table
  • 컴파일러: file.c --> 어셈블리 프로그램
  • 어셈블러: 어셈블리 프로그램 --> file.o
  • 링커: file.o --> file.o (실행파일)
  • file.c --> file.o로 변환할 때, linker는 file의 symbol table을 확인한다.

Symbol table

 

Compile and Linking

file.c --> file.o --> file.o(실행파일)

 


Problem: What  if there are so many externs?

Problem: What  if there are so many externs?

 

Solution: Header file
  • #include <x.h> --> extern

Solution: Header file

 


C preprocessor
  1. Preprocess
  2. Comile
  3. Link

C preprocessor

 

Library
  • 헤더파일에는 라이브러리 함수의 선언만 있고, 실제 함수의 정의는 라이브러리 파일에 있다.

Library

 

Compile and Linking (Revisited)

1. Compiler: file.c --> 어셈블리 프로그램

2. Assembler: 어셈블리 프로그램 --> file.o

3. Linker: file.o --> file.o(실행파일) 

  • Static library - Static linking

4. Loader: file.o(실행파일) 실행

  • Dynamic library - Dynamic linking

Static library, Dynamic library

 


Static Linking vs. Dynamic Linking
  • Static linking: 라이브러리가 프로그램의 실행파일 코드에 포함된다. (static library)
  • Dynamic linking: 라이브러리가 실행 시 link된다. (shared library)