Basic-Script-Concepts.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU linker LD
  4. (GNU Binutils)
  5. version 2.28.
  6. Copyright (C) 1991-2017 Free Software Foundation, Inc.
  7. Permission is granted to copy, distribute and/or modify this document
  8. under the terms of the GNU Free Documentation License, Version 1.3
  9. or any later version published by the Free Software Foundation;
  10. with no Invariant Sections, with no Front-Cover Texts, and with no
  11. Back-Cover Texts. A copy of the license is included in the
  12. section entitled "GNU Free Documentation License". -->
  13. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>LD: Basic Script Concepts</title>
  16. <meta name="description" content="LD: Basic Script Concepts">
  17. <meta name="keywords" content="LD: Basic Script Concepts">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Scripts.html#Scripts" rel="up" title="Scripts">
  26. <link href="Script-Format.html#Script-Format" rel="next" title="Script Format">
  27. <link href="Scripts.html#Scripts" rel="prev" title="Scripts">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Basic-Script-Concepts"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Script-Format.html#Script-Format" accesskey="n" rel="next">Script Format</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="Basic-Linker-Script-Concepts"></a>
  65. <h3 class="section">3.1 Basic Linker Script Concepts</h3>
  66. <a name="index-linker-script-concepts"></a>
  67. <p>We need to define some basic concepts and vocabulary in order to
  68. describe the linker script language.
  69. </p>
  70. <p>The linker combines input files into a single output file. The output
  71. file and each input file are in a special data format known as an
  72. <em>object file format</em>. Each file is called an <em>object file</em>.
  73. The output file is often called an <em>executable</em>, but for our
  74. purposes we will also call it an object file. Each object file has,
  75. among other things, a list of <em>sections</em>. We sometimes refer to a
  76. section in an input file as an <em>input section</em>; similarly, a section
  77. in the output file is an <em>output section</em>.
  78. </p>
  79. <p>Each section in an object file has a name and a size. Most sections
  80. also have an associated block of data, known as the <em>section
  81. contents</em>. A section may be marked as <em>loadable</em>, which means that
  82. the contents should be loaded into memory when the output file is run.
  83. A section with no contents may be <em>allocatable</em>, which means that an
  84. area in memory should be set aside, but nothing in particular should be
  85. loaded there (in some cases this memory must be zeroed out). A section
  86. which is neither loadable nor allocatable typically contains some sort
  87. of debugging information.
  88. </p>
  89. <p>Every loadable or allocatable output section has two addresses. The
  90. first is the <em>VMA</em>, or virtual memory address. This is the address
  91. the section will have when the output file is run. The second is the
  92. <em>LMA</em>, or load memory address. This is the address at which the
  93. section will be loaded. In most cases the two addresses will be the
  94. same. An example of when they might be different is when a data section
  95. is loaded into ROM, and then copied into RAM when the program starts up
  96. (this technique is often used to initialize global variables in a ROM
  97. based system). In this case the ROM address would be the LMA, and the
  98. RAM address would be the VMA.
  99. </p>
  100. <p>You can see the sections in an object file by using the <code>objdump</code>
  101. program with the &lsquo;<samp>-h</samp>&rsquo; option.
  102. </p>
  103. <p>Every object file also has a list of <em>symbols</em>, known as the
  104. <em>symbol table</em>. A symbol may be defined or undefined. Each symbol
  105. has a name, and each defined symbol has an address, among other
  106. information. If you compile a C or C++ program into an object file, you
  107. will get a defined symbol for every defined function and global or
  108. static variable. Every undefined function or global variable which is
  109. referenced in the input file will become an undefined symbol.
  110. </p>
  111. <p>You can see the symbols in an object file by using the <code>nm</code>
  112. program, or by using the <code>objdump</code> program with the &lsquo;<samp>-t</samp>&rsquo;
  113. option.
  114. </p>
  115. <hr>
  116. <div class="header">
  117. <p>
  118. Next: <a href="Script-Format.html#Script-Format" accesskey="n" rel="next">Script Format</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  119. </div>
  120. </body>
  121. </html>