DOC PREVIEW
CMU CS 15213 - Linking

This preview shows page 1-2-15-16-17-32-33 out of 33 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15 213 The course that gives CMU its Zip Linking Oct 9 2003 Topics class14 ppt Static linking Dynamic linking Case study Library interpositioning Example C Program main c swap c int buf 2 1 2 extern int buf int main swap return 0 int bufp0 buf 0 int bufp1 void swap int temp bufp1 buf 1 temp bufp0 bufp0 bufp1 bufp1 temp 2 15 213 F 03 Static Linking Programs are translated and linked using a compiler driver unix gcc O2 g o p main c swap c unix p main c swap c Translators cpp cc1 as Source files Translators cpp cc1 as main o swap o Separately compiled relocatable object files Linker ld p 3 Fully linked executable object file contains code and data for all functions defined in main c and swap c 15 213 F 03 Why Linkers Modularity Program can be written as a collection of smaller source files rather than one monolithic mass Can build libraries of common functions more on this later e g Math library standard C library Efficiency Time Change one source file compile and then relink No need to recompile other source files Space Libraries of common functions can be aggregated into a single file Yet executable files and running memory images contain only code for the functions they actually use 4 15 213 F 03 What Does a Linker Do Symbol resolution Programs define and reference symbols variables and functions code a data int xp x reference to symbol a reference to symbol x Symbol definitions are stored by compiler in symbol table Each entry includes name size and location of object Linker associates each symbol reference with exactly one symbol definition Relocation 5 Merges separate code and data sections into single sections Relocates symbols from their relative locations in the o files to new absolute positions in the executable Updates all references to these symbols to reflect their new positions 15 213 F 03 Object Files Modules Relocatable object file o file Contains code and data in a form that can be combined with other relocatable object files at compile time to form an executable Executable object file Contains code and data in a form that can be copied directly into memory and then executed Shared object file so file 6 Special type of relocatable object file that can be loaded into memory and linked dynamically at either load time or runtime Called Dynamic Link Libraries DLLs by Windows 15 213 F 03 Executable and Linkable Format ELF Standard binary format for object files Derives from AT T System V Unix Later adopted by BSD Unix variants and Linux One unified format for Relocatable object files o Executable object files Shared object files so Generic name ELF binaries 7 15 213 F 03 ELF Object File Format Elf header Magic number type o exec so machine byte ordering etc Program header table Page size virtual addresses memory segments sections segment sizes text section Code data section Initialized static data bss section 8 Uninitialized static data Block Started by Symbol Better Save Space Has section header but occupies no space ELF header Program header table required for executables text section data section bss section symtab rel txt rel data debug Section header table required for relocatables 15 213 F 03 0 ELF Object File Format cont symtab section Symbol table Procedure and static variable names Section names and locations rel text section Relocation info for text section Addresses of instructions that will need to be modified in the executable Instructions for modifying rel data section Relocation info for data section Addresses of pointer data that will need to be modified in the merged executable debug section 9 ELF header Program header table required for executables text section data section bss section symtab rel text rel data debug Section header table required for relocatables Info for symbolic debugging gcc g 15 213 F 03 0 Linker Symbols Global symbols Symbols defined by module m that can be referenced by other modules Ex non static C functions and non static global variables External symbols Global symbols that are referenced by module m but defined by some other module Local symbols Symbols that are defined and referenced exclusively by module m Ex C functions and variables that are defined with the static attribute Key Point Local linker symbols are not local program variables 10 15 213 F 03 Resolving Symbols Ref to external symbol buf Def of global symbol buf swap c main c int buf 2 1 2 static int bufp0 buf 0 static int bufp1 int main swap return 0 Ref to external symbol swap extern int buf void swap int temp Def of local symbol bufp0 Linker knows nothing of temp bufp1 buf 1 temp bufp0 bufp0 bufp1 bufp1 temp 11 15 213 F 03 Relocating Symbol Definitions and References Relocatable Object Files system code text system data data Executable Object File 0 headers system code main m o a o 12 main text int e 7 data a text int ep e int x 15 int y data bss text a more system code system data int e 7 int ep e int x 15 uninitialized data symtab debug data bss 15 213 F 03 main o Relocation Info int buf 2 1 2 int main swap return 0 0000000 main 0 55 1 89 e5 3 83 ec 08 6 e8 fc ff ff ff b d f 10 31 c0 89 ec 5d c3 push ebp mov esp ebp sub 0x8 esp call 7 main 0x7 7 R 386 PC32 swap xor eax eax mov ebp esp pop ebp ret Disassembly of section data 00000000 buf 0 01 00 00 00 02 00 00 00 Source objdump 13 15 213 F 03 swap o Relocation Info text extern int buf static int bufp0 buf 0 static int bufp1 void swap int temp bufp1 buf 1 temp bufp0 bufp0 bufp1 bufp1 temp Disassembly of section text 00000000 swap 0 55 1 8b 15 00 00 00 00 7 a1 c 89 e c7 15 00 18 1a 1c 1e 89 8b 89 a1 23 89 25 5d 26 c3 14 push ebp mov 0x0 edx 3 R 386 32 bufp0 0 00 00 00 mov 0x4 eax 8 R 386 32 buf e5 mov esp ebp 05 00 00 00 00 04movl 0x4 0x0 00 00 10 R 386 32 bufp1 14 R 386 32 buf ec mov ebp esp 0a mov edx ecx 02 mov eax edx 00 00 00 00 mov 0x0 eax 1f R 386 32 bufp1 08 mov ecx eax pop ebp ret 15 213 F 03 a o Relocation Info data extern int buf Disassembly of section data static int bufp0 buf 0 static int bufp1 00000000 bufp0 0 00 00 00 00 0 R 386 32 buf void swap int temp bufp1 buf 1 temp bufp0 bufp0 bufp1 bufp1 temp 15 15 213 F 03 Executable After Relocation text 080483b4 main 80483b4 55 80483b5 89 80483b7 83 80483ba e8 80483bf 31 80483c1 89 80483c3 5d 80483c4 c3 080483c8 swap 80483c8 55 80483c9 8b 80483cf a1 80483d4 89 80483d6 c7 80483dd …


View Full Document

CMU CS 15213 - Linking

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Linking
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Linking and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Linking and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?