Operating System/System Programming(Arif Butt)

Lec03) Working of Linkers: Creating your own Libraries

Tony Lim 2021. 6. 11. 22:34
728x90

every .o file start with 0 memory address.

relocate symbols from thier relative locations in the .o files to their final absolute memory location in the executables.

 

Global symbol = that are defined in one module and can be reference by other module.

External symbol = Gobal symbol that are referenced by a module but are defined in some other module. declared with 'external' keyword

Local symbol = taht are reference in their own module. any global variable or function declared with 'static' keyword.

#include <stdio.h>
void swap();
int buf[2] = {1,2};
int main() 
{
    swap();
    printf("buf[0]= %d, buf[1]= %d \n", buf[0], buf[1]);
    return 0;
}

swap is external symbol , main is global symbol , printf is global external symbol

 

extern int buf[];
int *bufp0 = &buf[0];
static int *bufp1;
void swap()
{
    int temp;
    bufp1 = &buf[1];
    temp = *bufp0;
    *bufp0 = *bufp1;
    *bufp1 = temp;
    
}

bufp0 is global symbol ,  bufp1 is  local symbol 

linker knows nothing abou temp.

 

Strong symbol = function names and initialized globals

Weak symbol = uninitialized globals

there cannot be mutiple strong symbol with same name , e.g) mutiple definition of 'main' is not allowed.

 

 

728x90