[CSAPP] 7.4 Relocatable Object Files

JunHyeok Kim·2024년 4월 22일
0

Relocatable Ojbect Files

해당 그림은 전형적인 ELF의 포맷을 보여줍니다.

ELF Header begins with a 16-byte sequence that describes the word size and byte ordering of the system that generated the file.
ELF 헤더는 이 파일을 생성한 워드 크기와 시스템의 바이트 순서를 나타내는 16바이트 배열로 시작합니다.

ELF헤더의 나머지는 링커가 목적파일을 구문분석하고 해석하도록 하는 정보를 포함하고 있다.

  • .text : 컴파일된 프로그램의 머신 코드

  • .rodata : Read-only data such as the format strings in printf statements, and jump tables for switch statements.

    문장의 포맷 스트링, switch 문의 점프 테이블과 같은 read-only 데이터.

  • .data : Initialized global and static C variables. Local C variables are maintained at run time on the stack and do not appear in either the .data or .bss sections.

    초기화된 글로벌 및 정적 C 변수들이 저장됩니다. C의 지역변수들은 런 타임때 스택지역에 저장되며, .data 나 .bss 섹션에 나타나지 않습니다.

  • .bss : Uninitialized global and static C variables, along with any global or static variables that are initialized to zero. This section occupies no actual space in the object file; it is merely a placeholder. Object file formats distinguish between initialized and uninitialized variables for space efficiency: uninitialized variables do not have to occupy any actual disk space in the object file. At run time, these variables are allocated in memory with an initial value of zero.

    초기화되지 않은 글로벌 및 정적 C 변수 (0으로 초기화 된 것 포함)이 저장됩니다. 이 섹션을 목적 파일에서 실질적인 공간을 차지하지 않고 'place holder' 역할을 할 뿐 입니다. 목적파일 포맷은 초기화 및 초기화되지 않은 변수들을 구분하는데 이는 공간 효율성을 위함 입니다. 아직 초기화되지 않은 변수들은 목적파일에 공간을 굳이 차지할 필요가 없지요! 런타임때, 0으로 초기화되어 저장됩니다.

  • .symtab : A symbol table with information about functions and global variables that are defined and referenced in the program. Some programmers mistakenly believe that a program must be compiled with the -g option to get symbol table information. In fact, every relocatable object file has a symbol table in .symtab (unless the programmer has specifically removed it with the strip command). However, unlike the symbol table inside a compiler, the .symtab symbol table does not contain entries for local variables.

    프로그램에서 정의되고, 참조되는 전역변수들과 함수들에 대한 정보를 가지고 있는 것이 심볼테이블 이다. 몇몇 프로그래머들은 심볼테이블 정보를 얻기 위해서는 -g 컴파일 옵션을 줘야 한다고 믿는데, 사실 모든 재배치 가능 목적 파일은 심볼테이블을 갖고있습니다!(strip command로 제거하지 않는 한) 그러나 심볼테이블은 지역변수 엔트리를 갖고있진 않습니다.

  • rel. text : A list of locations in the.text section that will need to be modified when the linker combines this object file with others. In general, any instruction that calls an external function or references a global variable will need to be modified. On the other hand, instructions that call local functions do not need to be modified. Note that relocation information is not needed in executable object files, and is usually omitted unless the user explicitly instructs the linker to include it.

    링커가 다른 목적 파일들을 연결할 때, .text 섹션에서 수정되어야 할 로케이션을 담은 리스트 입니다. 일반론적으로, 어떠한 인스트럭션이라도 외부 함수나 참조를 호출하는 경우 수정되어야 합니다. 위치 조정 정보는 사실 실행 목적 파일에 필요가 없음을 주목해야합니다. 그리고 위치 조정 정보들은 사용자가 명시적으로 링커에 포함시키지 않는 한, 생략됩니다.

  • rel.data : Relocation information for any global variables that are referenced or defined by the module. In general, any initialized global variable whose initial value is the address of a global variable or externally defined function will need to be modified.

    이것은 모듈에서 참조되거나 정의된 전역 변수에 대한 재배치 정보를 나타냅니다. 일반적으로, 초기화된 전역 변수 중 초기 값이 전역 변수나 외부에서 정의된 함수의 주소인 경우에는 수정이 필요합니다.

  • .debug : A debugging symbol table with entries for local variables and typedefs defined in the program, global variables defined and referenced in the program, and the original C source file. It is only present if the compiler driver is invoked with the -g option.

    지역 변수에 대한 엔트리와 프로그램 내부에 정의된 typedefs, 프로그램 내에서의 전역변수 및 참조들과 C 소스코드가 담긴 디버깅 심볼 테이블 입니다. -g 옵션으로 컴파일 한 경우에 포함됩니다.

  • .line : A mapping between line numbers in the original C source program and machine code instructions in the .text section. It is only present if the compiler driver is invoked with the -g option.

    최초 C 소스 프로그램과 .text 섹션 내 머신 코드 인스트럭션 내 라인 번호들간의 매핑. 컴파일 옵션을 -g 로 주었을 때 생성된다.

  • A string table for the symbol tables in the .symtab and .debug sec- tions and for the section names in the section headers. A string table is a sequence of null-terminated character strings.

    .strtab과 .debug 섹션들 내에 있는 심볼 테이블과 섹션 헤더들에 있는 섹션 이름들을 위한 스트링 테이블이다. 스트링 테이블은 널 무자로 종료된 스트링의 배열이다.

0개의 댓글