<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Stop clearing all non-alloc string tables"
   href="https://bugs.llvm.org/show_bug.cgi?id=43931">43931</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Stop clearing all non-alloc string tables
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llvm-objcopy/strip
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jh7370.2008@my.bristol.ac.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>alexander.v.shaposhnikov@gmail.com, jake.h.ehrlich@gmail.com, jh7370.2008@my.bristol.ac.uk, llvm-bugs@lists.llvm.org, rupprecht@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>llvm-objcopy (and llvm-strip), when it reads in an object, ignores the current
contents of all non-SHF_ALLOC SHT_STRTAB sections, and regenerates them when
writing out. This is fine for string tables that solely represent the symbol
table string table/section header string table, but if they contain contents
that are used by other sections (presumably user-defined/os-specific sections
etc), then the corresponding contents will be lost.

I'm not entirely sure what the solution is: we still want to remove names from
the symbol name table and section header string table if they aren't needed any
more after all. Perhaps the fix here is to preserve the existing contents of a
string table if it is referenced by another section's sh_link field (excepting
the special case of the reference from the symbol table). Optionally, it might
be okay to add new strings to the end of that section, but I think we'd need to
preserve the order of the other strings, so that any references to them are
maintained. Alternatively, we should only remove from/reorganise strings in
string tables when we know it is safe to do so.

GNU objcopy does not appear to clear the contents of such sections. I haven't
checked to see what it does for string tables that are symbol table or section
header string tables.

Example:

## test.yaml
--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name:    .foo
    Type:    SHT_PROGBITS
    Link:    .strings
  - Name:    .strings
    Type:    SHT_STRTAB
    Content: "00666700626300"

C:\Work> yaml2obj test.yaml -o test.o
C:\Work> llvm-readelf test.o --sections
There are 5 section headers, starting at offset 0x70:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00     
0   0  0
  [ 1] .foo              PROGBITS        0000000000000000 000040 000000 00     
2   0  0
  [ 2] .strings          STRTAB          0000000000000000 000040 000007 00     
0   0  0
  [ 3] .strtab           STRTAB          0000000000000000 000047 000001 00     
0   0  1
  [ 4] .shstrtab         STRTAB          0000000000000000 000048 000021 00     
0   0  1

C:\Work> llvm-objcopy test.o test2.o
C:\Work> llvm-readelf test2.o --sections
There are 5 section headers, starting at offset 0x68:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00     
0   0  0
  [ 1] .foo              PROGBITS        0000000000000000 000040 000000 00     
2   0  0
  [ 2] .strings          STRTAB          0000000000000000 000040 000001 00     
0   0  0
  [ 3] .strtab           STRTAB          0000000000000000 000041 000001 00     
0   0  1
  [ 4] .shstrtab         STRTAB          0000000000000000 000042 000021 00     
0   0  1

C:\Work> objcopy test.o test3.o
C:\Work> llvm-readelf test3.o --sections
There are 5 section headers, starting at offset 0x70:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00     
0   0  0
  [ 1] .foo              PROGBITS        0000000000000000 000040 000000 00     
0   0  1
  [ 2] .strings          STRTAB          0000000000000000 000040 000007 00     
0   0  1
  [ 3] .strtab           STRTAB          0000000000000000 000047 000001 00     
0   0  1
  [ 4] .shstrtab         STRTAB          0000000000000000 000048 000021 00     
0   0  1

Note that the size of .strings is 1 in test2.o, but 7 in the other two.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>