Writing-Symbols.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 BFD library.
  4. Copyright (C) 1991-2017 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3 or
  7. any later version published by the Free Software Foundation; with the
  8. Invariant Sections being "GNU General Public License" and "Funding
  9. Free Software", the Front-Cover texts being (a) (see below), and with
  10. the Back-Cover Texts being (b) (see below). A copy of the license is
  11. included in the section entitled "GNU Free Documentation License".
  12. (a) The FSF's Front-Cover Text is:
  13. A GNU Manual
  14. (b) The FSF's Back-Cover Text is:
  15. You have freedom to copy and modify this GNU Manual, like GNU
  16. software. Copies published by the Free Software Foundation raise
  17. funds for GNU development. -->
  18. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  19. <head>
  20. <title>Untitled Document: Writing Symbols</title>
  21. <meta name="description" content="Untitled Document: Writing Symbols">
  22. <meta name="keywords" content="Untitled Document: Writing Symbols">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  27. <link href="index.html#Top" rel="start" title="Top">
  28. <link href="BFD-Index.html#BFD-Index" rel="index" title="BFD Index">
  29. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  30. <link href="Symbols.html#Symbols" rel="up" title="Symbols">
  31. <link href="Mini-Symbols.html#Mini-Symbols" rel="next" title="Mini Symbols">
  32. <link href="Reading-Symbols.html#Reading-Symbols" rel="prev" title="Reading Symbols">
  33. <style type="text/css">
  34. <!--
  35. a.summary-letter {text-decoration: none}
  36. blockquote.smallquotation {font-size: smaller}
  37. div.display {margin-left: 3.2em}
  38. div.example {margin-left: 3.2em}
  39. div.indentedblock {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  44. div.smalllisp {margin-left: 3.2em}
  45. kbd {font-style:oblique}
  46. pre.display {font-family: inherit}
  47. pre.format {font-family: inherit}
  48. pre.menu-comment {font-family: serif}
  49. pre.menu-preformatted {font-family: serif}
  50. pre.smalldisplay {font-family: inherit; font-size: smaller}
  51. pre.smallexample {font-size: smaller}
  52. pre.smallformat {font-family: inherit; font-size: smaller}
  53. pre.smalllisp {font-size: smaller}
  54. span.nocodebreak {white-space:nowrap}
  55. span.nolinebreak {white-space:nowrap}
  56. span.roman {font-family:serif; font-weight:normal}
  57. span.sansserif {font-family:sans-serif; font-weight:normal}
  58. ul.no-bullet {list-style: none}
  59. -->
  60. </style>
  61. </head>
  62. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  63. <a name="Writing-Symbols"></a>
  64. <div class="header">
  65. <p>
  66. Next: <a href="Mini-Symbols.html#Mini-Symbols" accesskey="n" rel="next">Mini Symbols</a>, Previous: <a href="Reading-Symbols.html#Reading-Symbols" accesskey="p" rel="prev">Reading Symbols</a>, Up: <a href="Symbols.html#Symbols" accesskey="u" rel="up">Symbols</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  67. </div>
  68. <hr>
  69. <a name="Writing-symbols"></a>
  70. <h4 class="subsection">2.7.2 Writing symbols</h4>
  71. <p>Writing of a symbol table is automatic when a BFD open for
  72. writing is closed. The application attaches a vector of
  73. pointers to pointers to symbols to the BFD being written, and
  74. fills in the symbol count. The close and cleanup code reads
  75. through the table provided and performs all the necessary
  76. operations. The BFD output code must always be provided with an
  77. &ldquo;owned&rdquo; symbol: one which has come from another BFD, or one
  78. which has been created using <code>bfd_make_empty_symbol</code>. Here is an
  79. example showing the creation of a symbol table with only one element:
  80. </p>
  81. <div class="example">
  82. <pre class="example"> #include &quot;sysdep.h&quot;
  83. #include &quot;bfd.h&quot;
  84. int main (void)
  85. {
  86. bfd *abfd;
  87. asymbol *ptrs[2];
  88. asymbol *new;
  89. abfd = bfd_openw (&quot;foo&quot;,&quot;a.out-sunos-big&quot;);
  90. bfd_set_format (abfd, bfd_object);
  91. new = bfd_make_empty_symbol (abfd);
  92. new-&gt;name = &quot;dummy_symbol&quot;;
  93. new-&gt;section = bfd_make_section_old_way (abfd, &quot;.text&quot;);
  94. new-&gt;flags = BSF_GLOBAL;
  95. new-&gt;value = 0x12345;
  96. ptrs[0] = new;
  97. ptrs[1] = 0;
  98. bfd_set_symtab (abfd, ptrs, 1);
  99. bfd_close (abfd);
  100. return 0;
  101. }
  102. ./makesym
  103. nm foo
  104. 00012345 A dummy_symbol
  105. </pre></div>
  106. <p>Many formats cannot represent arbitrary symbol information; for
  107. instance, the <code>a.out</code> object format does not allow an
  108. arbitrary number of sections. A symbol pointing to a section
  109. which is not one of <code>.text</code>, <code>.data</code> or <code>.bss</code> cannot
  110. be described.
  111. </p>
  112. </body>
  113. </html>