operation.hss 2.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. [Main]
  2. Title=TIGCC Linker Purpose and Operation
  3. [Top]
  4. The purpose of a linker is to take executable code and data from different
  5. files and merge it into a single program. It must resolve dependencies
  6. between the files, and there are many architecture-dependent features linkers
  7. are required to support. The complicated part about linking is that binary
  8. code can be encapsulated in different formats; most linkers, including the
  9. TIGCC linker, can import code from several formats and export it to yet
  10. another one (see <A HREF="$$LINK(formats)">TIGCC Linker File Formats</A>).
  11. <BR><BR>
  12. The TIGCC linker can handle two kinds of files: object files and archive
  13. files. Object files are produced by the compiler or assembler. They contain
  14. the code and global variables of the program; all object files passed to the
  15. linker are processed and then included in the final output. Archive files,
  16. also known as static libraries, are collections of object files. An archive
  17. member is included only if this is requested by another file.
  18. <BR><BR>
  19. Files can reference each other via text strings called <U>symbols</U>. These
  20. symbols are usually labels in assembly code, or functions and global
  21. variables in C code. The most popular way of referencing symbols is to ask
  22. that the final address or offset of a specific symbol be inserted at or added
  23. to a specific location in the code. This is called <U>relocation</U>.
  24. <BR><BR>
  25. When the linker is executed, it first reads all object files passed to it and
  26. imports their contents into its internal data structures. Then it tries to
  27. resolve the references to symbols defined in another file. If a symbol cannot
  28. be resolved, it is looked up in the symbol tables of all archive files passed
  29. to the linker; if it is still not found, this is an error. Archive members
  30. are imported immediately if required, and they may reference symbols defined
  31. in other files as well. Some special actions are performed based on the
  32. contents of the imported files, code and data blocks (<U>sections</U>) are
  33. sorted and merged if required, and offsets between different locations in the
  34. code are inserted whereever the object files requested this. Finally, the
  35. program is exported to an executable file.