<div dir="ltr">Over on the generic-abi mailing list, Fang-Rui Song recently proposed a new compressed relocation format for ELF, motivated in part by the number of relocations for string in the .debug_names tables. Regardless of the resolution of that proposal, some simple changes to the DWARF spec could help eliminate a substantial number of those relocations. In fact, parts of the split DWARF series of proposals in DWARF 5 were all about minimizing the quantity of relocations (e.g., DW_FORM_addrx and DW_FORM_strx).<div><br></div><div>This proposal adds an indirect string form to the name table (for use when a non-split DWARF compilation is already using .debug_str_offsets), and a local string pool in the name table (for use in a split-DWARF compilation).<div><div><div><br></div><div>-cary</div><div> <h1 style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;margin-top:0px;color:rgb(0,0,0)">Add Local and Indirect Strings to Name Index</h1><h2 style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">Background</h2><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">The name table in the<span class="gmail-Apple-converted-space"> </span><code>.debug_names</code><span class="gmail-Apple-converted-space"> </span>section currently references strings via offsets to the<span class="gmail-Apple-converted-space"> </span><code>.debug_str</code><span class="gmail-Apple-converted-space"> </span>section. Each string offset, therefore, requires a relocation unless some under-the-table agreement is made between the compiler and linker. This can get expensive, as the number of names can be quite large.</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">For non-split DWARF, the use of<span class="gmail-Apple-converted-space"> </span><code>.debug_str</code><span class="gmail-Apple-converted-space"> </span>makes sense, as many or most of the names in the name index are also referenced from entries in the<span class="gmail-Apple-converted-space"> </span><code>.debug_info</code><span class="gmail-Apple-converted-space"> </span>section. If the<span class="gmail-Apple-converted-space"> </span><code>.debug_info</code><span class="gmail-Apple-converted-space"> </span>section is using<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strx</code><span class="gmail-Apple-converted-space"> </span>and a<span class="gmail-Apple-converted-space"> </span><code>.debug_str_offsets</code><span class="gmail-Apple-converted-space"> </span>section, however, it would also be beneficial for the name index to use string references in the style of<code>DW_FORM_strx</code>, which would eliminate the need for any relocations in the name table.</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">For split DWARF, there is little overlap between the strings referenced by the skeleton<span class="gmail-Apple-converted-space"> </span><code>.debug_info</code><span class="gmail-Apple-converted-space"> </span>section and those referenced by the<span class="gmail-Apple-converted-space"> </span><code>.debug_names</code><span class="gmail-Apple-converted-space"> </span>section, and there is no advantage gained by storing the strings in the separate section.</p><h2 style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">Overview</h2><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">This proposal adds two alternative string representations to the name index: one in the style of<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strx</code><span class="gmail-Apple-converted-space"> </span>for non-split DWARF compilation units that use<span class="gmail-Apple-converted-space"> </span><code>.debug_str_offsets</code>, and one with a local string table stored directly in the<span class="gmail-Apple-converted-space"> </span><code>.debug_names</code>section that requires no relocations.</p><h2 style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">Proposed Changes</h2><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Section 6.1.1.2 Structure of the Name Index, change “eight individual parts” to “nine individual parts,” and add the following to the enumerated list of parts between items 6 and 7:</p><blockquote style="margin-left:1em;padding-left:1em;color:rgb(0,0,0);font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif"><ol start="7"><li>An optional local string pool.</li></ol></blockquote><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">(Renumber the last two items.)</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Figure 6.1 Name Index Layout (part 1), under “Name Index”, add a box for “Local String Pool” between “Name Table” and “Abbrev Table”. The box expands to a box on the right labeled “Strings”.</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">Also in Figure 6.1 Name Index Layout (part 1), change “String Offsets” to “String Pointers or Indexes” in the expansion of “Name Table”.</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Section 6.1.1.4.1 Section Header, replace field 3 (“padding”) with the following:</p><blockquote style="margin-left:1em;padding-left:1em;color:rgb(0,0,0);font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif"><ol start="3"><li><p><code>str_format</code><span class="gmail-Apple-converted-space"> </span>(ubyte)</p><p>An enumerated constant that specifies the representation of string references in the name index. The possible values are:<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strp</code>,<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strp8</code>, and<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strx4</code><span class="gmail-Apple-converted-space"> </span>(see Section 7.5.5 Classes and Forms).</p></li><li><p>padding (ubyte)</p><p>Reserved to DWARF (must be zero).</p></li></ol></blockquote><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">Renumber fields 4-8, and add the following fields after “name_count”:</p><blockquote style="margin-left:1em;padding-left:1em;color:rgb(0,0,0);font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif"><ol start="10"><li><p><code>local_str_pool_size</code><span class="gmail-Apple-converted-space"> </span>(uword)</p><p>Size of the local string pool. If this value is non-zero, string offsets (when str_format is<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strp</code><span class="gmail-Apple-converted-space"> </span>or<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strp8</code>) reference the local string pool. If this value is 0, string offsets reference the .debug_str section. If<span class="gmail-Apple-converted-space"> </span><code>str_format</code><span class="gmail-Apple-converted-space"> </span>is<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strx4</code>, this field should be 0.</p></li><li><p><code>str_offsets</code><span class="gmail-Apple-converted-space"> </span>(section offset)</p><p>A 4-byte or 8-byte unsigned offset that points to the header of the compilation unit’s contribution to the<span class="gmail-Apple-converted-space"> </span><code>.debug_str_offsets</code><span class="gmail-Apple-converted-space"> </span>section. Indirect string references (when str_format is<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strx4</code>) are interpreted as zero-based indexes into the array of offsets following the header. If<span class="gmail-Apple-converted-space"> </span><code>str_format</code><span class="gmail-Apple-converted-space"> </span>is<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strp</code><span class="gmail-Apple-converted-space"> </span>or<span class="gmail-Apple-converted-space"> </span><code>DW_FORM_strp8</code>, this field should be 0.</p></li></ol></blockquote><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Section 6.1.1.4.6 Name Table, replace the first paragraph with the following:</p><blockquote style="margin-left:1em;padding-left:1em;color:rgb(0,0,0);font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif"><p>The name table immediately follows the hash lookup table. It consists of two arrays: an array of string pointers or indexes, followed immediately by an array of entry offsets. The items in the first array are determined by the<span class="gmail-Apple-converted-space"> </span><code>str_format</code><span class="gmail-Apple-converted-space"> </span>field in the section header, and may be 4-byte or 8-byte offsets into either the<span class="gmail-Apple-converted-space"> </span><code>.debug_str</code><span class="gmail-Apple-converted-space"> </span>section or the local string pool, or 4-byte indexes into the array of offsets in the<span class="gmail-Apple-converted-space"> </span><code>.debug_str_offsets</code><span class="gmail-Apple-converted-space"> </span>section. The items in the second array are section offsets: 4-byte unsigned integers for the DWARF-32 format or 8-byte unsigned integers for the DWARF-64 format. The entry offsets in the second array refer to index entries, and are relative to the start of the entry pool area.</p></blockquote><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">Following Section 6.1.1.4.6, add a new section:</p><blockquote style="margin-left:1em;padding-left:1em;color:rgb(0,0,0);font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif"><p>Section 6.1.1.4.7 Local String Pool</p><p>The local string pool, if present, immediately follows the name table. It consists of a series of null-terminated strings. Its size is given by<span class="gmail-Apple-converted-space"> </span><code>local_str_pool_size</code>.</p><p>[non-normative]<span class="gmail-Apple-converted-space"> </span><em>For non-split DWARF compilation units, strings used by the name table will have significant overlap with strings used by the<span class="gmail-Apple-converted-space"> </span><code>.debug_info</code><span class="gmail-Apple-converted-space"> </span>section, and a local string pool is not advisable. Relocations for the string references may be minimized by using the indirect string forms in both<span class="gmail-Apple-converted-space"> </span><code>.debug_info</code><span class="gmail-Apple-converted-space"> </span>and<span class="gmail-Apple-converted-space"> </span><code>.debug_names</code>. For split DWARF compilation units, there is likely little overlap, and relocations for string references in the name table can be minimized by using the local string pool.</em></p></blockquote><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Section 6.1.1.4.8 Abbreviations Table (was 6.1.1.4.7), change the first sentence to:</p><blockquote style="margin-left:1em;padding-left:1em;color:rgb(0,0,0);font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif"><p>The abbreviations table immediately follows the local string pool (or, if the local string pool is absent, the name table).</p></blockquote><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Appendix B, Figure B.1, add an arc from<span class="gmail-Apple-converted-space"> </span><code>.debug_names</code><span class="gmail-Apple-converted-space"> </span>to<span class="gmail-Apple-converted-space"> </span><code>.debug_str</code><span class="gmail-Apple-converted-space"> </span>and to<span class="gmail-Apple-converted-space"> </span><code>.debug_str_offsets</code>. (There should have already been an arc to<span class="gmail-Apple-converted-space"> </span><code>.debug_str</code><span class="gmail-Apple-converted-space"> </span>in the DWARF 5 spec.)</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)">In Figure B.2, add similar arcs.</p><p style="font-family:"Nunito Sans","Lucida Grande","Lucida Sans Unicode","Lucida Sans",Lucida,sans-serif;color:rgb(0,0,0)"><br></p></div></div></div></div></div>