<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - incomplete support for -fdata-sections in clang/llvm for C++ static data members"
   href="https://llvm.org/bugs/show_bug.cgi?id=26570">26570</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>incomplete support for -fdata-sections in clang/llvm for C++ static data members
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>thanm@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15875" name="attach_15875" title="test case">attachment 15875</a> <a href="attachment.cgi?id=15875&action=edit" title="test case">[details]</a></span>
test case

The attached test case and makefile illustrate a limitation in the current
clang/llvm implementation of the "-fdata-sections" command line option. This
option tells the compiler to place each named data item into a separate ELF
section in the resulting object file; doing this has benefits in that it helps
enable linker GC of unused sections and (if desired) linker reordering of
sections for performance/size reasons.

In the test case ("ex.cc") note the following two variables:

  char foo::ID = 0;
  char baz::ID = 0;

When you compile with -fdata-sections, these two vars are still placed into the
same ".bss" section, which effectively defeats the option.

To illustrate why this is a problem, download the testcase + makefile and run
"make doit", then diff the two files

   ex.so.od.clang.txt ex.so.od.gcc.txt

For gcc (which doesn't make the same mistake), the linker is able to
garbage-collect the storage for "_ZN12_GLOBAL__N_13foo2IDE", whereas in the
LLVM case this dead storage can't be reclaimed (since the var in question is in
the same section with another variable that is not dead).

NB: there maybe other cases in which -fdata-sections also doesn't work (I
haven't done an exhaustive search). It does seem to work ok for C-style
variable declarations as far as I can tell.</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>