7.8 Executable Object Files(실행 가능한 객체 파일)
- 우리는 linker가 여러개의 object file들을 하나의 executable object file로 합치는 것을 보았다.
- 예제인 C 프로그램은 ASCII text file에서 시작해서 프로그램이 메모리에 load되고 실행되기 위해 필요한 모든 정보를 가지고 있는 binary file로 바뀌었다.
- 아래 그림은 ELF executable file에 그런 정보들을 요약한 것이다.
- executable object file의 format은 relocatable object file과 비슷하다.
- ELF header가 파일의 전체적인 format을 설명한다.
- 이것은 프로그램의 entry point도 포함한다. entry point는 프로그램이 실행될 때 처음 명령어의 주소이다.
- .text, .rodata, .data section은 relocatable object file과 비슷하다. 다른점은 이 section들이 최종 run time 메모리 주소로 relocated되었다는 것이다.
- .init section은 _init이라는 작은 함수를 정의한다. 이 함수는 프로그램의 초기화 code에 의해 호출된다.
- executable file은 완전히 linked = relocated 되었기 때문에 .rel section을 필요가 없다.
- ELF executable file은 연속된 memory segment와 mapping된 연속된 executable file의 chunck로 메모리에 쉽게 load되게 설계되었다.
- 이 mapping은 프로그램의 header table에 있다.
- 아래 그림은 prog 프로그램의 header table의 일부를 보여준다.
- off: object file의 offset
- vaddr/paddr: 메모리 주소
- align: alignment requirement
- filesz: object file에서 segment size
- memsz: 메모리에서 segment size
- flags: run time permissions
- 이런 의미를 가진다.
- 위의 header table에서 2개의 memory segment가 executable object file의 내용으로 초기화 되는 것을 볼 수 있다.
- 1,2 line이 알려주는 것은 다음과 같다.


- 첫번째 segment = code segment
- read/execute permission 있음
- 메모리 주소 0x400000에서 시작
- 메모리에서 전체 사이즈는 0x69c 바이트 차지
- executable object file의 첫 0x69c 바이트로 초기화 됨
- 초기화 된 이곳엔 ELF heaer, program header table, .init, .text, .rodata section 있다.
- 3, 4 line이 알려주는 것은 다음과 같다.
- 두번째 segement = data segment
- read/write permission 있음
- 메모리 주소 0x600df8에서 시작
- 메모리에서 전체 사이즈는 0x230 바이트 차지
- object file에서 offset 0xdf8에서 시작하는 .data section에서 0x228 바이트로 초기화 됨
- segment의 남은 8바이트는 .dss data로 run time에 0으로 초기화 된다.
- 모든 segment에 대해서 linker는 아래와 같은 시작 주소 vaddr을 선택해야 한다.
- vaddr mod align = off mod align
- 여기서 off는 object file에서 segment의 첫번째 section offset이다.
- align은 program header에서 지정된 alignment이다. ($2^{21}$ = 0x200000).
- 예를 들어 위의 그림에 있는 data segment를 보자.
- vaddr mod align = 0x600df8 mod 0x200000 = 0xdf8 and off mod align = 0xdf8 mod 0x200000 = 0xdf8
- 이 alignment requirement는 최적화 하는 것이다.
- 뭘 최적화 하는가 하면 object file의 segments가 프로그램이 실행될 때 효율적으로 메모리로 전송할 수 있도록 하는 최적화다.
- 이유는 chapter 9에서 가상 메모리 할 때 배운다.

'Computer Science > 컴퓨터 구조' 카테고리의 다른 글
[CSAPP] 8.5 Signal(시그널) (0) | 2023.02.22 |
---|---|
[CSAPP] 7.9 Loading Executable Object Files(실행 가능한 객체 파일 로딩) (0) | 2023.02.21 |
[CSAPP] 7.7 Relocation(재배치) (0) | 2023.02.21 |
[CSAPP] 7.6 Symbol Resolutions(심볼 해석) (0) | 2023.02.21 |
[CSAPP] 7.12 Position-Independent Code (PIC)(위치 독립성 코드) (0) | 2023.02.17 |