Initialized static variables are represented by the ‘S’ and ‘V’ symbol descriptors. ‘S’ means file scope static, and ‘V’ means procedure scope static. One exception: in XCOFF, IBM’s xlc compiler always uses ‘V’, and whether it is file scope or not is distinguished by whether the stab is located within a function.
In a.out files,
N_STSYM means the data section,
means the text section, and
N_LCSYM means the bss section. For
those systems with a read-only data section separate from the text
N_ROSYM means the read-only data section.
For example, the source lines:
static const int var_const = 5; static int var_init = 2; static int var_noinit;
yield the following stabs:
.stabs "var_const:S1",36,0,0,_var_const # 36 is N_FUN … .stabs "var_init:S1",38,0,0,_var_init # 38 is N_STSYM … .stabs "var_noinit:S1",40,0,0,_var_noinit # 40 is N_LCSYM
In XCOFF files, the stab type need not indicate the section;
C_STSYM can be used for all statics. Also, each static variable
is enclosed in a static block. A
C_BSTAT (emitted with a
‘.bs’ assembler directive) symbol begins the static block; its
value is the symbol number of the csect symbol whose value is the
address of the static block, its section is the section of the variables
in that static block, and its name is ‘.bs’. A
(emitted with a ‘.es’ assembler directive) symbol ends the static
block; its name is ‘.es’ and its value and section are ignored.
In ECOFF files, the storage class is used to specify the section, so the stab type need not indicate the section.
In ELF files, for the SunPRO compiler version 2.0.1, symbol descriptor ‘S’ means that the address is absolute (the linker relocates it) and symbol descriptor ‘V’ means that the address is relative to the start of the relevant section for that compilation unit. SunPRO has plans to have the linker stop relocating stabs; I suspect that their the debugger gets the address from the corresponding ELF (not stab) symbol. I’m not sure how to find which symbol of that name is the right one. The clean way to do all this would be to have the value of a symbol descriptor ‘S’ symbol be an offset relative to the start of the file, just like everything else, but that introduces obvious compatibility problems. For more information on linker stab relocation, See ELF Linker Relocation.