19 - Linking 1 Outline Whatislinkingandwhylinking...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Linking
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5
Background image of page 2
3 Monolithic source file Problems:   efficiency: small change requires complete recompilation  modularity: hard to share common functions (e.g. printf) Translator main.c p ASCII source file binary executable object file (memory image on disk)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Linker (ld) Translators main.c main.o Translators swap.c swap.o p separately compiled relocatable object files executable object file (contains code and data for all functions defined in main.c and swap.c) Separate Compilation
Background image of page 4
5 What is linker Linking is the process of  collecting and combining various pieces of code and data into a  single executable file Executable file Can be loaded (copied) into memory and executed. 
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 What is linker Linking can be performed at compile time, when the source code is translated into machine code  by the linker at load time, when the program is loaded into memory and executed  by the loader at run time, by application programs. 
Background image of page 6
7 Why learning on linking Build large program Avoid missing modules, especially libraries Avoid dangerous programming errors Define multiple global variables Under stand scoping rules Extern and static vs. auto and register 
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
main.c swap.c 1. /*main.c */ 2. void swap() ; 3. 4. int buf[2] = {1, 2}; 5. 6. Int main() 7. { 8. swap() ; 9. return 0 ; 10. } 1. /*swap.c */ 2. extern int buf[]; 3. 4. int *bufp0 = &buf[0] 5. int *bufp1 ; 6. 7. void swap() 8. { 9. int temp ; 10. 11. int bufp1 = &buf[1]; 12. temp = *bufp0 ; 13. *bufp0 = *bufp1 ; 14. *bufp1 = temp ; 15. }
Background image of page 8
9 Example Two functions main() and swap() Three global variables buf, bufp0 which are initialized explicitly  bufp1 implicitly initialized to 0
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Compiler Drivers
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 000 taught by Professor Jing during the Fall '10 term at Fudan University.

Page1 / 33

19 - Linking 1 Outline Whatislinkingandwhylinking...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online