<html>
    <head>
      <base href="http://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 --- - The plugin can drop a symbol gold has asked for"
   href="http://llvm.org/bugs/show_bug.cgi?id=19901">19901</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>The plugin can drop a symbol gold has asked for
          </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>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>gold-plugin
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rafael.espindola@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, nlewycky@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat test.ll
define linkonce_odr void @f() {
  ret void
}
$ cat test2.ll
define i32 @main() {
  call void @f()
  ret i32 0
}
define linkonce_odr void @f() {
  ret void
}
$ llc test2.ll -o test2.o -filetype=obj
$ llvm-as test.ll -o test.o
$ clang -flto test.o test2.o -o test
$ ./test
Segmentation fault

What is going on is:

gold decides to keep the 'f' defined in the IR file and tells the plugin that.
The plugin calls lto_codegen_add_must_preserve_symbol, but that does nothing
since the symbol is linkonce_odr and the IR linker will not copy it in if it is
not needed (from its narrow point of view).

The fix for the the gold plugin is clear if a bit laborious: apply the
restrictions to the unmerged module. If we are told to keep a symbol, change
the linkage to make sure we do. If we are told to drop a symbol, drop it before
even passing it down to the IR linker.

I will test this on OS X with ld64 in a sec.</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>