1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1992-2021 Free Software Foundation, Inc. 4Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon, 5and David MacKenzie. 6 7Permission is granted to copy, distribute and/or modify this document 8under the terms of the GNU Free Documentation License, Version 1.3 or 9any later version published by the Free Software Foundation; with no 10Invariant Sections, with no Front-Cover Texts, and with no Back-Cover 11Texts. A copy of the license is included in the section entitled "GNU 12Free Documentation License". --> 13<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 14<head> 15<title>STABS: Statics</title> 16 17<meta name="description" content="STABS: Statics"> 18<meta name="keywords" content="STABS: Statics"> 19<meta name="resource-type" content="document"> 20<meta name="distribution" content="global"> 21<meta name="Generator" content="makeinfo"> 22<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 23<link href="index.html#Top" rel="start" title="Top"> 24<link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index"> 25<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 26<link href="Variables.html#Variables" rel="up" title="Variables"> 27<link href="Based-Variables.html#Based-Variables" rel="next" title="Based Variables"> 28<link href="Common-Blocks.html#Common-Blocks" rel="previous" title="Common Blocks"> 29<style type="text/css"> 30<!-- 31a.summary-letter {text-decoration: none} 32blockquote.smallquotation {font-size: smaller} 33div.display {margin-left: 3.2em} 34div.example {margin-left: 3.2em} 35div.indentedblock {margin-left: 3.2em} 36div.lisp {margin-left: 3.2em} 37div.smalldisplay {margin-left: 3.2em} 38div.smallexample {margin-left: 3.2em} 39div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 40div.smalllisp {margin-left: 3.2em} 41kbd {font-style:oblique} 42pre.display {font-family: inherit} 43pre.format {font-family: inherit} 44pre.menu-comment {font-family: serif} 45pre.menu-preformatted {font-family: serif} 46pre.smalldisplay {font-family: inherit; font-size: smaller} 47pre.smallexample {font-size: smaller} 48pre.smallformat {font-family: inherit; font-size: smaller} 49pre.smalllisp {font-size: smaller} 50span.nocodebreak {white-space:nowrap} 51span.nolinebreak {white-space:nowrap} 52span.roman {font-family:serif; font-weight:normal} 53span.sansserif {font-family:sans-serif; font-weight:normal} 54ul.no-bullet {list-style: none} 55--> 56</style> 57 58 59</head> 60 61<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 62<a name="Statics"></a> 63<div class="header"> 64<p> 65Next: <a href="Based-Variables.html#Based-Variables" accesskey="n" rel="next">Based Variables</a>, Previous: <a href="Common-Blocks.html#Common-Blocks" accesskey="p" rel="previous">Common Blocks</a>, Up: <a href="Variables.html#Variables" accesskey="u" rel="up">Variables</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p> 66</div> 67<hr> 68<a name="Static-Variables"></a> 69<h3 class="section">4.5 Static Variables</h3> 70 71<p>Initialized static variables are represented by the ‘<samp>S</samp>’ and 72‘<samp>V</samp>’ symbol descriptors. ‘<samp>S</samp>’ means file scope static, and 73‘<samp>V</samp>’ means procedure scope static. One exception: in XCOFF, IBM’s 74xlc compiler always uses ‘<samp>V</samp>’, and whether it is file scope or not 75is distinguished by whether the stab is located within a function. 76</p> 77<a name="index-N_005fSTSYM"></a> 78<a name="index-N_005fLCSYM"></a> 79<a name="index-N_005fFUN_002c-for-variables"></a> 80<a name="index-N_005fROSYM"></a> 81<p>In a.out files, <code>N_STSYM</code> means the data section, <code>N_FUN</code> 82means the text section, and <code>N_LCSYM</code> means the bss section. For 83those systems with a read-only data section separate from the text 84section (Solaris), <code>N_ROSYM</code> means the read-only data section. 85</p> 86<p>For example, the source lines: 87</p> 88<div class="example"> 89<pre class="example">static const int var_const = 5; 90static int var_init = 2; 91static int var_noinit; 92</pre></div> 93 94<p>yield the following stabs: 95</p> 96<div class="example"> 97<pre class="example">.stabs "var_const:S1",36,0,0,_var_const # <span class="roman">36 is N_FUN</span> 98… 99.stabs "var_init:S1",38,0,0,_var_init # <span class="roman">38 is N_STSYM</span> 100… 101.stabs "var_noinit:S1",40,0,0,_var_noinit # <span class="roman">40 is N_LCSYM</span> 102</pre></div> 103 104<a name="index-C_005fSTSYM"></a> 105<a name="index-C_005fBSTAT"></a> 106<a name="index-C_005fESTAT"></a> 107<p>In XCOFF files, the stab type need not indicate the section; 108<code>C_STSYM</code> can be used for all statics. Also, each static variable 109is enclosed in a static block. A <code>C_BSTAT</code> (emitted with a 110‘<samp>.bs</samp>’ assembler directive) symbol begins the static block; its 111value is the symbol number of the csect symbol whose value is the 112address of the static block, its section is the section of the variables 113in that static block, and its name is ‘<samp>.bs</samp>’. A <code>C_ESTAT</code> 114(emitted with a ‘<samp>.es</samp>’ assembler directive) symbol ends the static 115block; its name is ‘<samp>.es</samp>’ and its value and section are ignored. 116</p> 117<p>In ECOFF files, the storage class is used to specify the section, so the 118stab type need not indicate the section. 119</p> 120<p>In ELF files, for the SunPRO compiler version 2.0.1, symbol descriptor 121‘<samp>S</samp>’ means that the address is absolute (the linker relocates it) 122and symbol descriptor ‘<samp>V</samp>’ means that the address is relative to the 123start of the relevant section for that compilation unit. SunPRO has 124plans to have the linker stop relocating stabs; I suspect that their the 125debugger gets the address from the corresponding ELF (not stab) symbol. 126I’m not sure how to find which symbol of that name is the right one. 127The clean way to do all this would be to have the value of a symbol 128descriptor ‘<samp>S</samp>’ symbol be an offset relative to the start of the 129file, just like everything else, but that introduces obvious 130compatibility problems. For more information on linker stab relocation, 131See <a href="ELF-Linker-Relocation.html#ELF-Linker-Relocation">ELF Linker Relocation</a>. 132</p> 133<hr> 134<div class="header"> 135<p> 136Next: <a href="Based-Variables.html#Based-Variables" accesskey="n" rel="next">Based Variables</a>, Previous: <a href="Common-Blocks.html#Common-Blocks" accesskey="p" rel="previous">Common Blocks</a>, Up: <a href="Variables.html#Variables" accesskey="u" rel="up">Variables</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p> 137</div> 138 139 140 141</body> 142</html> 143