<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 - Add warning for misplaced TLS sections in linker scripts"
   href="https://bugs.llvm.org/show_bug.cgi?id=45460">45460</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Add warning for misplaced TLS sections in linker scripts
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>ELF
          </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>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The rules for where TLS sections can go are fairly specific. They obviously
must be in the PT_TLS segment (and should be the only ones in said segment),
but also the .tbss section (along with any other SHT_NOBITS TLS sections)
should be at the end of the segment too, and not in any other segment.

Since it's fairly easy to accidentally craft linker scripts that violate one or
more of these rules, it would be nice if a warning could be emitted if
something isn't right, to stop people writing linker scripts that produce
broken output.

Possible examples:

1) TLS sections not in TLS segment:

PHDRS {
  ph_load PT_LOAD FLAGS (0x2 | 0x4);
}

SECTIONS {
  .tdata : { *(.tdata) } : ph_load
}

warning: SHF_TLS section should be assigned to a PT_TLS segment

2) Non-TLS section in TLS segment (caveat - we need to handle empty output
sections here carefully):

PHDRS {
  ph_load PT_LOAD FLAGS (0x2 | 0x4);
  ph_tls  PT_TLS  FLAGS (0x2 | 0x4);
}

SECTIONS {
  .tdata : { *(.tdata) } : ph_load : ph_tls
  .data : { *(.data) }
}

warning: non-SHF_TLS section should not be assigned to a PT_TLS segment

3) Non SHT_NOBITS last section in TLS segment containing other NOBITS sections
(again beware of empty output sections):

PHDRS {
  ph_load PT_LOAD FLAGS (0x2 | 0x4);
  ph_tls  PT_TLS  FLAGS (0x2 | 0x4);
}

SECTIONS {
  .tbss  : { *(.tbss) } : ph_tls
  .tdata : { *(.tdata) } : ph_load : ph_tls
}

warning: non-SHT_NOBITS section found in PT_TLS segment after SHT_NOBITS
section

4) SHT_NOBITS TLS section in non-PT_TLS segment:

PHDRS {
  ph_load PT_LOAD FLAGS (0x2 | 0x4);
  ph_tls  PT_TLS  FLAGS (0x2 | 0x4);
}

SECTIONS {
  .tdata : { *(.tdata) } : ph_load : ph_tls
  .tbss  : { *(.tbss) }
}

warning: SHT_NOBITS TLS section in non-TLS segment</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>