Bug 236581 - /usr/lib/libomp.so underlinking
Summary: /usr/lib/libomp.so underlinking
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords: patch
Depends on:
Blocks: 236062
  Show dependency treegraph
 
Reported: 2019-03-16 21:01 UTC by Jan Beich
Modified: 2019-04-17 20:17 UTC (History)
1 user (show)

See Also:


Attachments
v0 (551 bytes, patch)
2019-03-16 21:48 UTC, Jan Beich
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2019-03-16 21:01:29 UTC
$ fetch https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c
$ cc -fopenmp omp_hello.c
$ ldd a.out
a.out:
        libomp.so => /usr/lib/libomp.so (0x80024b000)
        libc.so.7 => /lib/libc.so.7 (0x8002fd000)
$ ./a.out
OMP: Error #178: Function pthread_key_create failed:
OMP: System error #78: Function not implemented

vs.

$ pkg install llvm80
$ clang80 -fopenmp omp_hello.c
$ ldd ./a.out
./a.out:
        libomp.so => /usr/local/llvm80/lib/libomp.so (0x800249000)
        libc.so.7 => /lib/libc.so.7 (0x8002f2000)
        libthr.so.3 => /lib/libthr.so.3 (0x800706000)
        libm.so.5 => /lib/libm.so.5 (0x800732000)
$ ./a.out
Hello World from thread = 0
Number of threads = 8
Hello World from thread = 5
Hello World from thread = 6
Hello World from thread = 3
Hello World from thread = 2
Hello World from thread = 1
Hello World from thread = 7
Hello World from thread = 4
Comment 1 Jan Beich freebsd_committer freebsd_triage 2019-03-16 21:38:06 UTC
Looks like a common mistake due to bug 236141.

$ cc -fopenmp -fuse-ld=bfd omp_hello.c
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbnl'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbnf'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `pthread_attr_getstack'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbn'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `pthread_getthreadid_np'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `logbl'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `fmaxl'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `pthread_attr_get_np'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `pthread_create'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `pthread_condattr_init'
cc: error: linker command failed with exit code 1 (use -v to see invocation)

$ nm -D /usr/lib/libomp.so | fgrep pthread
                 U pthread_atfork
                 U pthread_attr_destroy
                 U pthread_attr_get_np
                 U pthread_attr_getstack
                 U pthread_attr_init
                 U pthread_attr_setdetachstate
                 U pthread_attr_setstacksize
                 U pthread_cond_destroy
                 U pthread_cond_init
                 U pthread_cond_signal
                 U pthread_cond_wait
                 U pthread_condattr_init
                 U pthread_create
                 U pthread_getspecific
                 U pthread_getthreadid_np
                 U pthread_join
                 U pthread_key_create
                 U pthread_key_delete
                 U pthread_mutex_destroy
                 U pthread_mutex_init
                 U pthread_mutex_lock
                 U pthread_mutex_unlock
                 w pthread_mutexattr_destroy
                 U pthread_mutexattr_init
                 w pthread_mutexattr_settype
                 U pthread_self
                 U pthread_setcancelstate
                 U pthread_setcanceltype
                 U pthread_setspecific
Comment 2 Jan Beich freebsd_committer freebsd_triage 2019-03-16 21:48:02 UTC
Created attachment 202924 [details]
v0

-Wl,--as-needed had to be dropped due to bug 214258. In order to reproduce add -fuse-ld=bfd to LDFLAGS.
Comment 3 commit-hook freebsd_committer freebsd_triage 2019-03-17 11:28:08 UTC
A commit references this bug:

Author: dim
Date: Sun Mar 17 11:27:27 UTC 2019
New revision: 345242
URL: https://svnweb.freebsd.org/changeset/base/345242

Log:
  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581
  MFC after:	1 month
  X-MFC-With:	r344779

Changes:
  head/lib/libomp/Makefile
Comment 4 Jan Beich freebsd_committer freebsd_triage 2019-03-17 12:42:04 UTC
(In reply to commit-hook from comment #3)
Still no good for LLD_UNSAFE ports.

$ cc -fopenmp -fuse-ld=bfd omp_hello.c
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbnl'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `fmaxl'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `logbl'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbnf'
/usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbn'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2019-03-17 19:10:39 UTC
(In reply to Jan Beich from comment #4)
> (In reply to commit-hook from comment #3)
> Still no good for LLD_UNSAFE ports.
> 
> $ cc -fopenmp -fuse-ld=bfd omp_hello.c
> /usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbnl'
> /usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `fmaxl'
> /usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `logbl'
> /usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbnf'
> /usr/local/bin/ld.bfd: /usr/lib/libomp.so: undefined reference to `scalbn'
> cc: error: linker command failed with exit code 1 (use -v to see invocation)

Hm, this is getting annoying. :-)  It looks like these are transitively pulled in via libcompiler-rt:

0000000000063b70 <__kmpc_atomic_cmplx10_div>:
[...]
   63c2d:       e8 4e 50 03 00          callq  98c80 <__divxc3>
[...]
0000000000098c80 <__divxc3>:
[...]
   98cb5:       e8 86 14 00 00          callq  9a140 <fmaxl@plt>
   98cba:       db 3c 24                fstpt  (%rsp)
   98cbd:       e8 8e 14 00 00          callq  9a150 <logbl@plt>
[...]
   98d10:       e8 4b 14 00 00          callq  9a160 <scalbnl@plt>

At some point, we'll have to get libgcc/compiler-rt users automagically pull in -lm.  Or fold libm into libc, like we should also do with libthr. ;-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2019-03-18 19:11:47 UTC
A commit references this bug:

Author: dim
Date: Mon Mar 18 19:11:12 UTC 2019
New revision: 345278
URL: https://svnweb.freebsd.org/changeset/base/345278

Log:
  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581
  MFC after:	1 month
  X-MFC-With:	r344779

Changes:
  head/lib/libomp/Makefile
Comment 7 Jan Beich freebsd_committer freebsd_triage 2019-03-18 19:43:08 UTC
As the custom Makefile copied -Wl,--as-needed from upstream (why?) libomp itself isn't able to link against libm when using BFD linker.

$ LDFLAGS=-fuse-ld=bfd make cleandir all -sj8
$ ldd $(make -V .OBJDIR)/libomp.so
/usr/obj/usr/src/amd64.amd64/lib/libomp/libomp.so:
        libthr.so.3 => /lib/libthr.so.3 (0x8006a8000)
        libc.so.7 => /lib/libc.so.7 (0x80024c000)
Comment 8 commit-hook freebsd_committer freebsd_triage 2019-03-18 19:56:30 UTC
A commit references this bug:

Author: dim
Date: Mon Mar 18 19:56:00 UTC 2019
New revision: 345282
URL: https://svnweb.freebsd.org/changeset/base/345282

Log:
  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581
  MFC after:	1 month
  X-MFC-With:	r344779

Changes:
  head/lib/libomp/Makefile
Comment 9 Dimitry Andric freebsd_committer freebsd_triage 2019-03-18 19:58:03 UTC
(In reply to Jan Beich from comment #7)
> As the custom Makefile copied -Wl,--as-needed from upstream (why?)

I used the upstream linking command lines as a reference, so I copied almost all of the flags.  For some reason, upstream uses --as-needed but does end up with a libm reference, I have no idea how though.
Comment 10 Dimitry Andric freebsd_committer freebsd_triage 2019-03-23 14:21:45 UTC
libomp.so now has all the DT_NEEDED entries it requires.
Comment 11 commit-hook freebsd_committer freebsd_triage 2019-04-17 20:09:04 UTC
A commit references this bug:

Author: dim
Date: Wed Apr 17 20:08:03 UTC 2019
New revision: 346331
URL: https://svnweb.freebsd.org/changeset/base/346331

Log:
  After r346168, also merge build infrastructure for LLVM libomp.

  MFC r345235:

  Add lib/libomp, with a Makefile, and generated configuration headers.
  Not connected to the main build yet, as there is still the issue of the
  GNU omp.h header conflicting with the LLVM one.  (That is, if MK_GCC is
  enabled.)

  PR:		236062

  MFC r345236:

  Connect lib/libomp to the build.

  * Set MK_OPENMP to yes by default only on amd64, for now.
  * Bump __FreeBSD_version to signal this addition.
  * Ensure gcc's conflicting omp.h is not installed if MK_OPENMP is yes.
  * Update OptionalObsoleteFiles.inc to cope with the conflicting omp.h.
  * Regenerate src.conf(5) with new WITH/WITHOUT fragments.

  Relnotes:	yes
  PR:		236062

  MFC r345242:

  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345278:

  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345282:

  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345291:

  Turn on MK_OPENMP for i386 by default, now that it can build.

  Noticed by:	jbeich
  PR:		236062, 236582

Changes:
_U  stable/12/
  stable/12/gnu/lib/Makefile
  stable/12/lib/libomp/
  stable/12/lib/libomp/Makefile
  stable/12/share/man/man5/src.conf.5
  stable/12/share/mk/src.opts.mk
  stable/12/tools/build/mk/OptionalObsoleteFiles.inc
  stable/12/tools/build/options/WITHOUT_OPENMP
  stable/12/tools/build/options/WITH_OPENMP
Comment 12 commit-hook freebsd_committer freebsd_triage 2019-04-17 20:09:06 UTC
A commit references this bug:

Author: dim
Date: Wed Apr 17 20:08:03 UTC 2019
New revision: 346331
URL: https://svnweb.freebsd.org/changeset/base/346331

Log:
  After r346168, also merge build infrastructure for LLVM libomp.

  MFC r345235:

  Add lib/libomp, with a Makefile, and generated configuration headers.
  Not connected to the main build yet, as there is still the issue of the
  GNU omp.h header conflicting with the LLVM one.  (That is, if MK_GCC is
  enabled.)

  PR:		236062

  MFC r345236:

  Connect lib/libomp to the build.

  * Set MK_OPENMP to yes by default only on amd64, for now.
  * Bump __FreeBSD_version to signal this addition.
  * Ensure gcc's conflicting omp.h is not installed if MK_OPENMP is yes.
  * Update OptionalObsoleteFiles.inc to cope with the conflicting omp.h.
  * Regenerate src.conf(5) with new WITH/WITHOUT fragments.

  Relnotes:	yes
  PR:		236062

  MFC r345242:

  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345278:

  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345282:

  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345291:

  Turn on MK_OPENMP for i386 by default, now that it can build.

  Noticed by:	jbeich
  PR:		236062, 236582

Changes:
_U  stable/12/
  stable/12/gnu/lib/Makefile
  stable/12/lib/libomp/
  stable/12/lib/libomp/Makefile
  stable/12/share/man/man5/src.conf.5
  stable/12/share/mk/src.opts.mk
  stable/12/tools/build/mk/OptionalObsoleteFiles.inc
  stable/12/tools/build/options/WITHOUT_OPENMP
  stable/12/tools/build/options/WITH_OPENMP
Comment 13 commit-hook freebsd_committer freebsd_triage 2019-04-17 20:09:15 UTC
A commit references this bug:

Author: dim
Date: Wed Apr 17 20:08:04 UTC 2019
New revision: 346331
URL: https://svnweb.freebsd.org/changeset/base/346331

Log:
  After r346168, also merge build infrastructure for LLVM libomp.

  MFC r345235:

  Add lib/libomp, with a Makefile, and generated configuration headers.
  Not connected to the main build yet, as there is still the issue of the
  GNU omp.h header conflicting with the LLVM one.  (That is, if MK_GCC is
  enabled.)

  PR:		236062

  MFC r345236:

  Connect lib/libomp to the build.

  * Set MK_OPENMP to yes by default only on amd64, for now.
  * Bump __FreeBSD_version to signal this addition.
  * Ensure gcc's conflicting omp.h is not installed if MK_OPENMP is yes.
  * Update OptionalObsoleteFiles.inc to cope with the conflicting omp.h.
  * Regenerate src.conf(5) with new WITH/WITHOUT fragments.

  Relnotes:	yes
  PR:		236062

  MFC r345242:

  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345278:

  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345282:

  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345291:

  Turn on MK_OPENMP for i386 by default, now that it can build.

  Noticed by:	jbeich
  PR:		236062, 236582

Changes:
_U  stable/12/
  stable/12/gnu/lib/Makefile
  stable/12/lib/libomp/
  stable/12/lib/libomp/Makefile
  stable/12/share/man/man5/src.conf.5
  stable/12/share/mk/src.opts.mk
  stable/12/tools/build/mk/OptionalObsoleteFiles.inc
  stable/12/tools/build/options/WITHOUT_OPENMP
  stable/12/tools/build/options/WITH_OPENMP
Comment 14 commit-hook freebsd_committer freebsd_triage 2019-04-17 20:17:37 UTC
A commit references this bug:

Author: dim
Date: Wed Apr 17 20:16:51 UTC 2019
New revision: 346333
URL: https://svnweb.freebsd.org/changeset/base/346333

Log:
  After r346168, also merge build infrastructure for LLVM libomp.

  MFC r345235:

  Add lib/libomp, with a Makefile, and generated configuration headers.
  Not connected to the main build yet, as there is still the issue of the
  GNU omp.h header conflicting with the LLVM one.  (That is, if MK_GCC is
  enabled.)

  PR:		236062

  MFC r345236:

  Connect lib/libomp to the build.

  * Set MK_OPENMP to yes by default only on amd64, for now.
  * Bump __FreeBSD_version to signal this addition.
  * Ensure gcc's conflicting omp.h is not installed if MK_OPENMP is yes.
  * Update OptionalObsoleteFiles.inc to cope with the conflicting omp.h.
  * Regenerate src.conf(5) with new WITH/WITHOUT fragments.

  Relnotes:	yes
  PR:		236062

  MFC r345242:

  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345278:

  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345282:

  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345291:

  Turn on MK_OPENMP for i386 by default, now that it can build.

  Noticed by:	jbeich
  PR:		236062, 236582

Changes:
_U  stable/11/
  stable/11/gnu/lib/Makefile
  stable/11/lib/libomp/
  stable/11/lib/libomp/Makefile
  stable/11/share/man/man5/src.conf.5
  stable/11/share/mk/src.opts.mk
  stable/11/tools/build/mk/OptionalObsoleteFiles.inc
  stable/11/tools/build/options/WITHOUT_OPENMP
  stable/11/tools/build/options/WITH_OPENMP
Comment 15 commit-hook freebsd_committer freebsd_triage 2019-04-17 20:17:45 UTC
A commit references this bug:

Author: dim
Date: Wed Apr 17 20:16:51 UTC 2019
New revision: 346333
URL: https://svnweb.freebsd.org/changeset/base/346333

Log:
  After r346168, also merge build infrastructure for LLVM libomp.

  MFC r345235:

  Add lib/libomp, with a Makefile, and generated configuration headers.
  Not connected to the main build yet, as there is still the issue of the
  GNU omp.h header conflicting with the LLVM one.  (That is, if MK_GCC is
  enabled.)

  PR:		236062

  MFC r345236:

  Connect lib/libomp to the build.

  * Set MK_OPENMP to yes by default only on amd64, for now.
  * Bump __FreeBSD_version to signal this addition.
  * Ensure gcc's conflicting omp.h is not installed if MK_OPENMP is yes.
  * Update OptionalObsoleteFiles.inc to cope with the conflicting omp.h.
  * Regenerate src.conf(5) with new WITH/WITHOUT fragments.

  Relnotes:	yes
  PR:		236062

  MFC r345242:

  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345278:

  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345282:

  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345291:

  Turn on MK_OPENMP for i386 by default, now that it can build.

  Noticed by:	jbeich
  PR:		236062, 236582

Changes:
_U  stable/11/
  stable/11/gnu/lib/Makefile
  stable/11/lib/libomp/
  stable/11/lib/libomp/Makefile
  stable/11/share/man/man5/src.conf.5
  stable/11/share/mk/src.opts.mk
  stable/11/tools/build/mk/OptionalObsoleteFiles.inc
  stable/11/tools/build/options/WITHOUT_OPENMP
  stable/11/tools/build/options/WITH_OPENMP
Comment 16 commit-hook freebsd_committer freebsd_triage 2019-04-17 20:17:47 UTC
A commit references this bug:

Author: dim
Date: Wed Apr 17 20:16:51 UTC 2019
New revision: 346333
URL: https://svnweb.freebsd.org/changeset/base/346333

Log:
  After r346168, also merge build infrastructure for LLVM libomp.

  MFC r345235:

  Add lib/libomp, with a Makefile, and generated configuration headers.
  Not connected to the main build yet, as there is still the issue of the
  GNU omp.h header conflicting with the LLVM one.  (That is, if MK_GCC is
  enabled.)

  PR:		236062

  MFC r345236:

  Connect lib/libomp to the build.

  * Set MK_OPENMP to yes by default only on amd64, for now.
  * Bump __FreeBSD_version to signal this addition.
  * Ensure gcc's conflicting omp.h is not installed if MK_OPENMP is yes.
  * Update OptionalObsoleteFiles.inc to cope with the conflicting omp.h.
  * Regenerate src.conf(5) with new WITH/WITHOUT fragments.

  Relnotes:	yes
  PR:		236062

  MFC r345242:

  Explicitly link libomp.so against -lpthread, as it depends on pthread
  functionality.  This should make example OpenMP programs work out of the
  box.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345278:

  Also explicitly link libomp.so against -lm, as it transitively depends
  on scalbn and a few other math functions, via libcompiler-rt.  This
  should allow OpenMP programs to link with BFD linkers too.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345282:

  Remove --as-needed from the linker flags for libomp.so, as these
  actually prevent the transitive dependency on libm.

  Reported by:	jbeich
  PR:		236062, 236581

  MFC r345291:

  Turn on MK_OPENMP for i386 by default, now that it can build.

  Noticed by:	jbeich
  PR:		236062, 236582

Changes:
_U  stable/11/
  stable/11/gnu/lib/Makefile
  stable/11/lib/libomp/
  stable/11/lib/libomp/Makefile
  stable/11/share/man/man5/src.conf.5
  stable/11/share/mk/src.opts.mk
  stable/11/tools/build/mk/OptionalObsoleteFiles.inc
  stable/11/tools/build/options/WITHOUT_OPENMP
  stable/11/tools/build/options/WITH_OPENMP