[llvm-bugs] [Bug 38547] New: Undefined reference to math library symbols, with '-flto -fno-math-errno'

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 13 11:42:26 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38547

            Bug ID: 38547
           Summary: Undefined reference to math library symbols, with
                    '-flto -fno-math-errno'
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sunil_srivastava at playstation.sony.com
                CC: llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180813/b8520bce/attachment-0001.html>


More information about the llvm-bugs mailing list