[Dreamhack] Quiz: Linux Memory Layout

Sisyphus·2022년 7월 18일
0

Q1. "d_str"이 위치하는 세그먼트는 어디인가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : 문자열 "d_str"은 읽기 전용 데이터(rodata) 세그먼트에 저장됩니다.



Q2. b가 위치하는 세그먼트는 어디인가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : b는 전역상수이기 때문에 데이터 세그먼트에 위치합니다.



Q3. e는 어느 세그먼트의 데이터를 가리키는가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : e는 malloc()으로 동적할당 되었기 때문에, 힙 세그먼트 데이터를 가리킵니다.



Q4. d가 위치하는 세그먼트는 어디인가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : d는 지역변수 이기 때문에 스택 세그먼트에 위치합니다.



Q5. foo가 위치하는 세그먼트는 어디인가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : 함수 코드는 코드 세그먼트에 위치합니다.



Q6. a가 위치하는 세그먼트는 어디인가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : 초기화된 전역변수는 데이터 세그먼트에 위치합니다.



Q7. c가 위치하는 세그먼트는 어디인가?

int a = 0xa;                
const char *b[] = "d_str";  
int c;                      
int foo(int arg) {          
  int d = 0xd;              
  return 0;
}
int main()  
{
  int *e = malloc(sizeof(*e));  
  return 0;
}

정답 : 초기화 되지 않은 전역변수는 BSS 세그먼트에 위치합니다.



Quiz: Linux Memory Layout

0개의 댓글