본문 바로가기

System programming6

Linking 6 - Library interpositioning Dynamic Linking at Run-Time dlopen으로 라이브러리를 열고 dlsym으로 fucntiond을 찾는다. Library interpositioning 임의의 fucntion에 추가적인 기능을 시킬 수 있다. 다음과 같은 시점들에 가능하다. Complie time Link time Load/run time 목적 Security Monitoring and Profiling Complie time interpositioning 실제로 코드가 있어야 한다. 컴파일을 다시 해야한다. maloc을 mymalloc으로 바꾼다. #define malloc(size ) mymalloc(size , __FILE__, __LINE__) #define free(ptr ) myfree(ptr , __FIL.. 2022. 4. 7.
Linker 문제2 다음과 같이 모듈이 주어졌을때 임의의 symbolx에 대해 REF(x.i)→DEF(x.k)로 나타낼 수 있다. 임의의 symbol x에 대해서 어떤 모듈에서 정의된 것을 사용하는가? Problem A. //Module1 int main() {} //Module 2 int main; int p2(){ } 정답: REF(main.1)→DEF(main.1) REF(main.2)→DEF(main.1) 풀이: main() -> strong symbol 변수 main -> weak symbol strong과 weak가 있을때 string을 선택 ProblemB //Module1 int main() {} //Module 2 int main = 1; int p2(){ } 정답 : Error 풀이: strong symb.. 2022. 4. 6.
Linker 문제1 다음 두개의 파일에서 symbol type과 section을 나누어 빈칸을 채워라. sybol(swap.o / m.o) symbol type(local, golbal, extern) section(.text, .data, .bss, or COMON) Symbol .symtab entry? Symbol type Module where defined Section buf bufp0 bufp1 swap temp //m.c void swap(); int buf[2] = {1, 2}; int main() { swap(); return 0; } //swap.c extern int buf[]; int *bufp0 = &buf[0]; int *bufp1; void swap() { int temp; bufp1 = &bu.. 2022. 4. 6.
Linker2 Relocatable object file(.o file) Executable object file(.a.out file) Shared object file (.so file) runtime에 symbol resoulution을 한다. 리눅스에서는 shared file, 윈도우에서는 dll이라고 부른다. - Executable and linkable format(ELF) 오브젝트 파일의 표준 바이너리 포맷 bss : 굳이 메모리에 올라가기 전까지 space를 차지할 필요가 없는것. -Linker Sysmbols Global symbols External symbols 접근 가능하지만 내가 define하지 않은것 Local symbols 나혼자만 쓰는 variable, static 2022. 4. 5.