String table sections hold null-terminated character sequences or strings. The object file uses these strings to represent symbol and section names. An empty string table section is permitted; its section header's sh_size contains zero. Non-zero indexes are invalid for an empty string table. If the string table is not empty, you can reference a string as an index into the string table section. The first byte, which is index zero, holds a null character. Likewise, a string table's last byte holds a null character to ensure null termination for all strings. A string whose index is zero, specifies either no names or a null name, depending on the context.
A section header's sh_name holds an index into the section header string table section, as designed by the e_shstrndx structure of the ELF header. The following figures show a string table with 25 bytes and the strings associated with various indexes:
Index | +0 | +1 | +2 | +3 | +4 | +5 | +6 | +7 | +8 | +9 |
---|---|---|---|---|---|---|---|---|---|---|
0 |
\0 |
n |
a |
m |
e |
\0 |
\0 |
V |
a |
r |
10 |
i |
a |
b |
l |
e |
\0 |
a |
b |
l |
e |
20 |
\0 |
\0 |
x |
x |
\0 |
|
|
|
|
|
Index | String |
---|---|
0 |
none |
1 |
name |
7 |
Variable |
11 |
able |
16 |
able |
24 |
null string |
A string table index may refer to any byte in the section. A string may appear more than once; references to substrings may exist, and a single string may be referenced multiple times. Unreferenced strings are also allowed.