⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 output-section-keywords.html

📁 gcc手册
💻 HTML
字号:
<html lang="en">

<head>

<title>Untitled</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="Untitled">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

</head>

<body>

<div class="node">

<p>

Node:<a name="Output%20Section%20Keywords">Output Section Keywords</a>,

Next:<a rel="next" accesskey="n" href="Output-Section-Discarding.html#Output%20Section%20Discarding">Output Section Discarding</a>,

Previous:<a rel="previous" accesskey="p" href="Output-Section-Data.html#Output%20Section%20Data">Output Section Data</a>,

Up:<a rel="up" accesskey="u" href="SECTIONS.html#SECTIONS">SECTIONS</a>

<hr><br>

</div>



<h4 class="subsection">Output section keywords</h4>



   <p>There are a couple of keywords which can appear as output section

commands.



     <dl>

<dt><code>CREATE_OBJECT_SYMBOLS</code>

     <dd>The command tells the linker to create a symbol for each input file. 

The name of each symbol will be the name of the corresponding input

file.  The section of each symbol will be the output section in which

the <code>CREATE_OBJECT_SYMBOLS</code> command appears.



     <p>This is conventional for the a.out object file format.  It is not

normally used for any other object file format.



     <br><dt><code>CONSTRUCTORS</code>

     <dd>When linking using the a.out object file format, the linker uses an

unusual set construct to support C++ global constructors and

destructors.  When linking object file formats which do not support

arbitrary sections, such as ECOFF and XCOFF, the linker will

automatically recognize C++ global constructors and destructors by name. 

For these object file formats, the <code>CONSTRUCTORS</code> command tells the

linker to place constructor information in the output section where the

<code>CONSTRUCTORS</code> command appears.  The <code>CONSTRUCTORS</code> command is

ignored for other object file formats.



     <p>The symbol <code>__CTOR_LIST__</code> marks the start of the global

constructors, and the symbol <code>__DTOR_LIST</code> marks the end.  The

first word in the list is the number of entries, followed by the address

of each constructor or destructor, followed by a zero word.  The

compiler must arrange to actually run the code.  For these object file

formats <small>GNU</small> C++ normally calls constructors from a subroutine

<code>__main</code>; a call to <code>__main</code> is automatically inserted into

the startup code for <code>main</code>.  <small>GNU</small> C++ normally runs

destructors either by using <code>atexit</code>, or directly from the function

<code>exit</code>.



     <p>For object file formats such as <code>COFF</code> or <code>ELF</code> which support

arbitrary section names, <small>GNU</small> C++ will normally arrange to put the

addresses of global constructors and destructors into the <code>.ctors</code>

and <code>.dtors</code> sections.  Placing the following sequence into your

linker script will build the sort of table which the <small>GNU</small> C++

runtime code expects to see.



     <pre class="smallexample">                __CTOR_LIST__ = .;

                LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)

                *(.ctors)

                LONG(0)

                __CTOR_END__ = .;

                __DTOR_LIST__ = .;

                LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)

                *(.dtors)

                LONG(0)

                __DTOR_END__ = .;

          </pre>



     <p>If you are using the <small>GNU</small> C++ support for initialization priority,

which provides some control over the order in which global constructors

are run, you must sort the constructors at link time to ensure that they

are executed in the correct order.  When using the <code>CONSTRUCTORS</code>

command, use <code>SORT(CONSTRUCTORS)</code> instead.  When using the

<code>.ctors</code> and <code>.dtors</code> sections, use <code>*(SORT(.ctors))</code> and

<code>*(SORT(.dtors))</code> instead of just <code>*(.ctors)</code> and

<code>*(.dtors)</code>.



     <p>Normally the compiler and linker will handle these issues automatically,

and you will not need to concern yourself with them.  However, you may

need to consider this if you are using C++ and writing your own linker

scripts.



   </dl>



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -