Bug 20469 - [x86_64] Link fail with -fopenmp and -ffast-math
Summary: [x86_64] Link fail with -fopenmp and -ffast-math
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Andrew Senkevich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-14 19:33 UTC by guanx
Modified: 2016-08-18 16:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
strace output of gcc (3.13 KB, text/x-log)
2016-08-15 17:23 UTC, guanx
Details

Note You need to log in before you can comment on or make changes to this bug.
Description guanx 2016-08-14 19:33:02 UTC
+++ This bug was initially created as a clone of Bug #19058 +++

-bash-4.2$ cat test.c
#include <math.h>
#define size 4096
double x[size];
double y[size];

__attribute__((noinline))
int foo()
{
  int i;

#pragma omp simd
  for (i = 0; i < size; i++)
    {
      x[i] = log(y[i]);
    }

  return (int) x[0];
}

int main()
{
  int i = 0;

  for (i = 0; i < size; i++)
    {
      y[i] = sin(i);
    }

  return (foo());
}

-bash-4.2$ gcc -O1 -fopenmp -ffast-math test.c -lm
/tmp/cccKGzmh.o: In function `foo':
test.c:(.text+0xf): undefined reference to `_ZGVbN2v___log_finite'
collect2: error: ld returned 1 exit status

gcc version 5.3.0
glibc version 2.23
Linux distribution Slackware64-14.2.
Tried to upgrade to gcc 5.4.0 and/or glibc 2.24 but the error persists.

Related discussion: https://sourceware.org/ml/libc-alpha/2015-06/msg00213.html
Comment 1 Andrew Senkevich 2016-08-15 12:57:32 UTC
Unable to reproduce with Glibc 2.23 (build both from 2.23 release branch and release tarball).

Glibc 2.23 version must have libmvec_nonshared.a installed and referenced with that installation path in AS_NEEDED part of libm.so, please check it.
Comment 2 guanx 2016-08-15 17:23:14 UTC
Created attachment 9435 [details]
strace output of gcc

The library "/usr/lib64/libmvec_nonshared.a" exists but gcc does not try to link to it according to the output from strace.
Comment 3 guanx 2016-08-15 17:27:25 UTC
When explicitly link with "libmvec_nonshared.a", there comes more undefined references:

$ gcc -O1 -fopenmp -ffast-math test.c /usr/lib64/libmvec_nonshared.a -lm
/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS): In function `_ZGVbN2v___log_finite':
(.text+0x2): undefined reference to `_ZGVbN2v_log'
/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS): In function `_ZGVcN4v___log_finite':
(.text+0x12): undefined reference to `_ZGVcN4v_log'
/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS): In function `_ZGVdN4v___log_finite':
(.text+0x22): undefined reference to `_ZGVdN4v_log'
/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS): In function `_ZGVeN8v___log_finite':
(.text+0x32): undefined reference to `_ZGVeN8v_log'
... ...
... (snip)
Comment 4 H.J. Lu 2016-08-15 17:27:58 UTC
(In reply to guanx from comment #2)
> Created attachment 9435 [details]
> strace output of gcc
> 
> The library "/usr/lib64/libmvec_nonshared.a" exists but gcc does not try to
> link to it according to the output from strace.

Please show the output of

# ls -l /lib64/libm.so
# file /lib64/libm.so
Comment 5 guanx 2016-08-15 17:34:38 UTC
(In reply to H.J. Lu from comment #4)
> (In reply to guanx from comment #2)
> > Created attachment 9435 [details]
> > strace output of gcc
> > 
> > The library "/usr/lib64/libmvec_nonshared.a" exists but gcc does not try to
> > link to it according to the output from strace.
> 
> Please show the output of
> 
> # ls -l /lib64/libm.so
> # file /lib64/libm.so

$ ls -l /lib64/libm.so
/bin/ls: cannot access '/lib64/libm.so': No such file or directory
$ ls -l /usr/lib64/libm.so
lrwxrwxrwx 1 root root 21 Jul 25 11:55 /usr/lib64/libm.so -> ../../lib64/libm.so.6*
$ ls -l /lib64/libm.so.6
lrwxrwxrwx 1 root root 12 Jul 25 11:55 /lib64/libm.so.6 -> libm-2.23.so
$ file /lib64/libm-2.23.so
/lib64/libm-2.23.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, not stripped
Comment 6 H.J. Lu 2016-08-15 18:06:07 UTC
(In reply to guanx from comment #5)
> (In reply to H.J. Lu from comment #4)
> > (In reply to guanx from comment #2)
> > > Created attachment 9435 [details]
> > > strace output of gcc
> > > 
> > > The library "/usr/lib64/libmvec_nonshared.a" exists but gcc does not try to
> > > link to it according to the output from strace.
> > 
> > Please show the output of
> > 
> > # ls -l /lib64/libm.so
> > # file /lib64/libm.so
> 
> $ ls -l /lib64/libm.so
> /bin/ls: cannot access '/lib64/libm.so': No such file or directory
> $ ls -l /usr/lib64/libm.so
> lrwxrwxrwx 1 root root 21 Jul 25 11:55 /usr/lib64/libm.so ->
> ../../lib64/libm.so.6*
> $ ls -l /lib64/libm.so.6
> lrwxrwxrwx 1 root root 12 Jul 25 11:55 /lib64/libm.so.6 -> libm-2.23.so
> $ file /lib64/libm-2.23.so
> /lib64/libm-2.23.so: ELF 64-bit LSB shared object, x86-64, version 1
> (GNU/Linux), dynamically linked, not stripped

/usr/lib64/libm.so is incorrect.  It should be

--
/* GNU ld script
*/
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libm.so.6  AS_NEEDED ( /usr/lib64/libmvec_nonshared.a /lib64/libmvec.so.1 ) )
---
Comment 7 guanx 2016-08-15 18:12:19 UTC
(In reply to H.J. Lu from comment #6)
> 
> /usr/lib64/libm.so is incorrect.  It should be
> 
> --
> /* GNU ld script
> */
> OUTPUT_FORMAT(elf64-x86-64)
> GROUP ( /lib64/libm.so.6  AS_NEEDED ( /usr/lib64/libmvec_nonshared.a
> /lib64/libmvec.so.1 ) )
> ---

Putting this script into "/usr/lib64/libm.so" solved the problem.

Thank you!
Comment 8 guanx 2016-08-15 18:14:07 UTC
This is *probably* a distribution specific bug.
Comment 9 Andrew Senkevich 2016-08-18 16:24:03 UTC
You can also check why libm.so wasn't installed as linker script in your case and show these conditions. It should be linker script since Glibc 2.22. Or libm.so was overwritten after installation?
Comment 10 guanx 2016-08-18 16:33:13 UTC
(In reply to Andrew Senkevich from comment #9)
> You can also check why libm.so wasn't installed as linker script in your
> case and show these conditions. It should be linker script since Glibc 2.22.
> Or libm.so was overwritten after installation?

Yes, libm.so was overwritten during the packaging process according to this post:

http://www.linuxquestions.org/questions/slackware-14/[bug]-slackware64-14-2-gcc-fails-to-link-with-libmvec_nonshared-a-4175587133/#post5591681

This is a distribution specific bug and has nothing to do with upstream, so I have marked it as RESOLVED/INVALID.