<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 --- - LTO changes results when alias point to weak symbols"
   href="http://llvm.org/bugs/show_bug.cgi?id=19848">19848</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LTO changes results when alias point to weak symbols
          </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>All
          </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>Linker
          </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, nicholas@mxc.ca, t.p.northover@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When building with GCC without LTO, a program composed of the files
------------------
#include<stdio.h>
int a = 42;
extern int b;
int main(void) {
  printf("%d %d\n", a, b);
  return 0;
}
----------------

-------------------
__attribute__((weak)) int a = 23;
extern int b __attribute__((alias("a")));
-------------------

prints "42 23".

The reason that the object linker just sees 'a' and 'b' as two independent
symbols. The symbol 'a' is replaced, but 'b' stays.

When building with clang without LTO, the program crashes because clang tells
the linker that 'b' can be discarded and now 'a' points to garbage.

With LTO (both clang and gcc!), this prints "42 42".

This will be a more serious issue when we add comdats: An alias from outside a
comdat that points to a discarded comdat would be an error, but LTO would make
it work.

Changing lib/Linker to work like a native linker would probably involve:

* Expanding alias to not contain other aliases in their ConstantExpr (assuming
we go with aliases that point to ConstantExpr).
* If anything the alias points to is about to be discarded, error.

Given the above existing differences in behaviour I wonder if we could get away
some claver wording in the spec saying that aliases have an undefined value if
the aliasee changes during link.</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>