<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 - Undefined reference to math library symbols, with '-flto -fno-math-errno'"
   href="https://bugs.llvm.org/show_bug.cgi?id=38547">38547</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Undefined reference to math library symbols, with '-flto -fno-math-errno'
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sunil_srivastava@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following script demonstrates a bug of lto.

$ cat main.c
extern double pow(double, double);
volatile double x,z;
double y;
int main()
{
  y = pow(x, z);
}
$ cat test.c
double fake_pow(double x, double y)
{
  return x+y;
}
double pow(double x, double y) __attribute__((alias("fake_pow")));
$ clang --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/C6/bin
$ clang -c -fno-math-errno -flto -O1 -o main.o main.c
$ clang -c -fno-math-errno -flto -O1 -o test.o test.c
$ clang -fno-math-errno -flto -O1 -o test.elf main.o test.o -lm
/tmp/lto-llvm-f22340.o: In function `main':
ld-temp.o:(.text.main+0x12): undefined reference to `pow'
clang-6.0: error: linker command failed with exit code 1 (use -v to see
invocation)
-----------------------------------------------

-O1 is needed in this trimmed example, because without it fake_pow gets inlined 
and the problem does not show up. In our full example we see the same error
at higher optimization levels.

Conversion of pow to llvm.pow.f64 in the front end is a key to this bug. 

We found this bug with other symbols, like logf or sin, whose conversions were
enabled in r319593. However, r319593 did not cause the bug. It merely made 
the bug hit more functions. The bug with pow, as shown above, exists even
before
r319593.

-fno-math-errno is needed to enable this conversion of pow to llvm.pow.f64.</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>