Shared Library/Compiler/Linker/Loader 역할

숲사람·2022년 3월 24일
0

UNIX & C

목록 보기
3/12

컴파일러가 하는일 (gcc)

  1. C Pre Processor(cpp) 가 #define, #include 구문등을 전처리하여 hello.i 생성
cpp hello.c > hello.i
  1. C compiler(cc1) 가 전처리한 hello.i 소스를 어셈블리로 컴파일하여 hello.s 생성
gcc -S hello.i
  1. assembler(as) 는 hello.s 를 어셈블하여 object (hello.o) 생성
as -o hello.o hello.s
  1. linker(collect2) 는 printf 등 외부 library 에 있는 symbol 을 링크해서 최종 프로그램 생성(a.out)

공유 라이브러리

static library -> .a
dynamic library ->
.so

$ file a.out

a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.18, not stripped

Dynamic Loader

공유 라이브러리와 연결된 프로그램을 실행하면 내부적으로 Dynamic Loader 라는 프로그램이 실행됨
1. dynamic link 된 공유 라이브러리를 찾아서 메모리에 로딩
2. entry function (C 언어일 경우 main 함수)를 찾아서 호출
3. 프로그램 실행

runtime environment

프로그램 실행시 main함수 호출 및 여러가지 수행. C runtime env 좀 더 찾아보기.
https://en.wikipedia.org/wiki/Runtime_system
https://en.wikipedia.org/wiki/Crt0

References

https://www.lesstif.com/software-architect/shared-library-linker-loader-12943542.html

profile
기록 & 정리 아카이브 용도 (보다 완성된 글은 http://soopsaram.com/documentudy)

0개의 댓글