1<html lang="en"> 2<head> 3<title>Output Section Keywords - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="SECTIONS.html#SECTIONS" title="SECTIONS"> 9<link rel="prev" href="Output-Section-Data.html#Output-Section-Data" title="Output Section Data"> 10<link rel="next" href="Output-Section-Discarding.html#Output-Section-Discarding" title="Output Section Discarding"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13This file documents the GNU linker LD 14(Sourcery CodeBench Lite 2011.09-69) 15version 2.21.53. 16 17Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 182001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 19 20Permission is granted to copy, distribute and/or modify this document 21under the terms of the GNU Free Documentation License, Version 1.3 22or any later version published by the Free Software Foundation; 23with no Invariant Sections, with no Front-Cover Texts, and with no 24Back-Cover Texts. A copy of the license is included in the 25section entitled ``GNU Free Documentation License''.--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Output-Section-Keywords"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Output-Section-Discarding.html#Output-Section-Discarding">Output Section Discarding</a>, 45Previous: <a rel="previous" accesskey="p" href="Output-Section-Data.html#Output-Section-Data">Output Section Data</a>, 46Up: <a rel="up" accesskey="u" href="SECTIONS.html#SECTIONS">SECTIONS</a> 47<hr> 48</div> 49 50<h4 class="subsection">3.6.6 Output Section Keywords</h4> 51 52<p>There are a couple of keywords which can appear as output section 53commands. 54 55 56<a name="index-CREATE_005fOBJECT_005fSYMBOLS-434"></a> 57<a name="index-input-filename-symbols-435"></a> 58<a name="index-filename-symbols-436"></a> 59<dl><dt><code>CREATE_OBJECT_SYMBOLS</code><dd>The command tells the linker to create a symbol for each input file. 60The name of each symbol will be the name of the corresponding input 61file. The section of each symbol will be the output section in which 62the <code>CREATE_OBJECT_SYMBOLS</code> command appears. 63 64 <p>This is conventional for the a.out object file format. It is not 65normally used for any other object file format. 66 67 <p><a name="index-CONSTRUCTORS-437"></a><a name="index-C_002b_002b-constructors_002c-arranging-in-link-438"></a><a name="index-constructors_002c-arranging-in-link-439"></a><br><dt><code>CONSTRUCTORS</code><dd>When linking using the a.out object file format, the linker uses an 68unusual set construct to support C++ global constructors and 69destructors. When linking object file formats which do not support 70arbitrary sections, such as ECOFF and XCOFF, the linker will 71automatically recognize C++ global constructors and destructors by name. 72For these object file formats, the <code>CONSTRUCTORS</code> command tells the 73linker to place constructor information in the output section where the 74<code>CONSTRUCTORS</code> command appears. The <code>CONSTRUCTORS</code> command is 75ignored for other object file formats. 76 77 <p>The symbol <code>__CTOR_LIST__</code><!-- /@w --> marks the start of the global 78constructors, and the symbol <code>__CTOR_END__</code><!-- /@w --> marks the end. 79Similarly, <code>__DTOR_LIST__</code><!-- /@w --> and <code>__DTOR_END__</code><!-- /@w --> mark 80the start and end of the global destructors. The 81first word in the list is the number of entries, followed by the address 82of each constructor or destructor, followed by a zero word. The 83compiler must arrange to actually run the code. For these object file 84formats <span class="sc">gnu</span> C++ normally calls constructors from a subroutine 85<code>__main</code>; a call to <code>__main</code> is automatically inserted into 86the startup code for <code>main</code>. <span class="sc">gnu</span> C++ normally runs 87destructors either by using <code>atexit</code>, or directly from the function 88<code>exit</code>. 89 90 <p>For object file formats such as <code>COFF</code> or <code>ELF</code> which support 91arbitrary section names, <span class="sc">gnu</span> C++ will normally arrange to put the 92addresses of global constructors and destructors into the <code>.ctors</code> 93and <code>.dtors</code> sections. Placing the following sequence into your 94linker script will build the sort of table which the <span class="sc">gnu</span> C++ 95runtime code expects to see. 96 97 <pre class="smallexample"> __CTOR_LIST__ = .; 98 LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) 99 *(.ctors) 100 LONG(0) 101 __CTOR_END__ = .; 102 __DTOR_LIST__ = .; 103 LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) 104 *(.dtors) 105 LONG(0) 106 __DTOR_END__ = .; 107</pre> 108 <p>If you are using the <span class="sc">gnu</span> C++ support for initialization priority, 109which provides some control over the order in which global constructors 110are run, you must sort the constructors at link time to ensure that they 111are executed in the correct order. When using the <code>CONSTRUCTORS</code> 112command, use ‘<samp><span class="samp">SORT_BY_NAME(CONSTRUCTORS)</span></samp>’ instead. When using the 113<code>.ctors</code> and <code>.dtors</code> sections, use ‘<samp><span class="samp">*(SORT_BY_NAME(.ctors))</span></samp>’ and 114‘<samp><span class="samp">*(SORT_BY_NAME(.dtors))</span></samp>’ instead of just ‘<samp><span class="samp">*(.ctors)</span></samp>’ and 115‘<samp><span class="samp">*(.dtors)</span></samp>’. 116 117 <p>Normally the compiler and linker will handle these issues automatically, 118and you will not need to concern yourself with them. However, you may 119need to consider this if you are using C++ and writing your own linker 120scripts. 121 122 </dl> 123 124 </body></html> 125 126