<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 - Missing static function with thinlto on AArch64 when an extern function with same name exists."
   href="https://bugs.llvm.org/show_bug.cgi?id=34966">34966</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing static function with thinlto on AArch64 when an extern function with same name exists.
          </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>All
          </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>lto
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>hiraditya@msn.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The static/internal function with thinlto gets skipped and results in a
miscompile. A reduced test case is as follows:


$cat static.c 

static int __attribute__((__noinline__)) f(int i) {
  volatile int j = i+10;
  return j;
}

int ext() {
  return f(100);
}

$ cat non-static.c 
int f(void) { return 32; }

$ cat reference.c 
int f();
int ext();

int main(void) {
  return f()+ ext();
}

$ cat run.sh

CC=~/llvm/build/bin/clang
LARGS=~/llvm/build/lib/libLTO.dylib

LFLAGS='-fobjc-arc -Xlinker -lto_library -Xlinker'
CFLAGS='--save-temps -v -Xlinker -save-temps'

ARCH='-arch arm64 -isysroot
/Applications/Xcode_9.0.0_fb.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk'

$CC -Oz -flto=thin static.c non-static.c reference.c $ARCH $CFLAGS $LFLAGS
$LARGS

Only one function '_f' is there and the static function 'f' is gone.
$ objdump -d a.out | grep _.*
Disassembly of section __TEXT,__text:
__text:
_ext:
_f:
_main:


However, when you target x86_64 (just remove the ARGS from command line)

$ objdump -d a.out | grep ^_.*
__text:
_ext:
_f.llvm.4247299495:
_f:
_main:</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>