<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 - More aggressive garbage-collection"
   href="https://bugs.llvm.org/show_bug.cgi?id=43253">43253</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>More aggressive garbage-collection
          </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>Linux
          </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>All Bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>There seems to be room for improving -gc-sections so that the garbage collector
reclaims more sections that it does now. Let me describe the idea in this bug.

`-gc-sections` is a linker option to make the linker to do mark-sweep garbage
collection on input file sections. It is perhaps not very wrong to think that
adding a new unrelated (unused) object file to the command line as well as
`-gc-sections` flag doesn't increase the resulting executable size at all
because the new file is garbage-collected.

Unfortunately that naive understanding is not correct. If an object file
contains a global variable that has a nontrivial constructor, that initializer
must run before `main()`, so the linker handles global initializers as GC root
objects. Garbage-collecting such global variable changes program's semantics
even if the variable is not used at all, because a constructor may have a side
effect. For example, you can print out "Hello world" from a constructor, and
removing a global variable from the program changes the program's behavior.

But I'd think it is probably OK to garbage-collect global variables and their
ctors if they are read from archive files.

Object files in archive files are not guaranteed to be linked. They are linked
only when there are undefined symbols that cannot be resolved from them. So, we
can garbage-collect a whole object file if that is not reachable, maybe?

Another view of this proposal: if we run a mark-sweep garbage collector after
reading all object files and before reading any archive files, no file will be
read from archives if they would be dead after GC.

There's of course a risk of changing the existing programs behaviors, but I
think it's worth trying.</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>