<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 --- - -fno-builtin gets lost on the way to Gold plugin"
   href="https://llvm.org/bugs/show_bug.cgi?id=30403">30403</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fno-builtin gets lost on the way to Gold plugin
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>krasin@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=17272" name="attach_17272" title="libc_free.c">attachment 17272</a> <a href="attachment.cgi?id=17272&action=edit" title="libc_free.c">[details]</a></span>
libc_free.c

Consider the following program (also attached):

__attribute__((noinline))
void touch(char *random_buffer) {
  random_buffer[0] = 17;
}

void _start(void* info) {
  char buf[512];
  int i;
  for (i = 0; i < 512; ++i) {
    buf[i] = 0;
  }
  touch(buf);
}

Let's build it w/o libc and with ThinLTO:

$ clang -flto=thin -fno-builtin -c libc_free.c -o libc_free.o
$ clang -nostdlib -Wl,--no-undefined -fuse-ld=gold -flto=thin -o libc_free
libc_free.o
/tmp/lto-llvm-e2379d.o:libc_free.o:function _start: error: undefined reference
to 'memset'
clang-3.9: error: linker command failed with exit code 1 (use -v to see
invocation)

What happens here is the first command line forgets to attach nobuiltin
attribute to _start, and the second command line recognizes memset in the loop
and then fails by not being able to find the symbol.

With full LTO the command line succeeds, most likely (I have not looked
closely) due to some optimization pass disabled and therefore not triggering
the issue. Still, the blame is on the Clang frontend.</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>