Bug 206899

Summary: [ld-elf] core dump when linking against x11/nvidia-driver's libGL.so and another library that links against libthr.so
Product: Base System Reporter: David Naylor <dbn>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Many People CC: amd64
Priority: ---    
Version: 10.2-RELEASE   
Hardware: amd64   
OS: Any   

Description David Naylor freebsd_committer freebsd_triage 2016-02-03 19:20:53 UTC
I believe this to be the root cause for bug #205149.  I will be committing a work-around that will fix that bug however the underlying issue still remains.  

I'm not sure if this is a bug with ld-elf or x11/nvidia-driver however given that this is not an issue with Linux I am opting for the former.  

I think the best wau to explain the bug is with a (reproducable) demonstration:

> sudo pkg install -y nvidia-driver > /dev/null
> touch libtest.c
> cc -shared -o libtest.so -lthr libtest.c
> echo 'int main(int argc, char **argv) { return 0; }' > test.c
> cc -o test -L/usr/local/lib -L. -ltest -lGL test.c
> env LD_LIBRARY_PATH=. ./test
Segmentation fault (core dumped)
> gdb test test.core 
GNU gdb 6.1.1 [FreeBSD]
<snip/>
(gdb) bt
#0  0x000000080060b2a2 in _rtld_is_dlopened () from /libexec/ld-elf.so.1
#1  0x0000000800604c8d in _r_debug_postinit () from /libexec/ld-elf.so.1
#2  0x000000080060246d in .text () from /libexec/ld-elf.so.1
#3  0x0000000802d3a365 in _nv003glcore () from /usr/local/lib/libnvidia-glcore.so.1
#4  0x000000080299e690 in _nv023glcore () from /usr/local/lib/libnvidia-glcore.so.1
#5  0x0000000802d1effc in _nv015glcore () from /usr/local/lib/libnvidia-glcore.so.1
#6  0x0000000800aa64eb in glXCreateNewContext () from /usr/local/lib/libGL.so.1
#7  0x0000000800a6ee5a in .init () from /usr/local/lib/libGL.so.1
#8  0x0000000800604a9f in r_debug_state () from /libexec/ld-elf.so.1
#9  0x00000008006040ee in __tls_get_addr () from /libexec/ld-elf.so.1
#10 0x0000000800602439 in .text () from /libexec/ld-elf.so.1
#11 0x0000000000000000 in ?? ()
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-02-08 04:21:47 UTC
A commit references this bug:

Author: dbn
Date: Mon Feb  8 04:20:50 UTC 2016
New revision: 408463
URL: https://svnweb.freebsd.org/changeset/ports/408463

Log:
  x11/kde4-workspace: fix OpenGL tests with nVidia's libGL

  nVidia's libGL causes a segfault in ld-elf if the application that is linking
  to libGL also links to another library (ordered before linking to libGL) and
  the second library links to libthr.  For example:

  kwin_opengl_test
   -> libXft
     -> libthr
   -> libGL

  Two workarounds are known:
   1) Change the linking order to have libGL linked first, or
   2) Also link to libthr in the (base) application.

  This patch implements the latter fix.

  PR:	205149, 206899
  MFH:	2016Q1

Changes:
  head/x11/kde4-workspace/Makefile
  head/x11/kde4-workspace/files/patch-kwin_opengltest_CMakeLists.txt
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-02-08 17:57:02 UTC
A commit references this bug:

Author: dbn
Date: Mon Feb  8 17:56:13 UTC 2016
New revision: 408489
URL: https://svnweb.freebsd.org/changeset/ports/408489

Log:
  MFH: r408463

  x11/kde4-workspace: fix OpenGL tests with nVidia's libGL

  nVidia's libGL causes a segfault in ld-elf if the application that is linking
  to libGL also links to another library (ordered before linking to libGL) and
  the second library links to libthr.  For example:

  kwin_opengl_test
   -> libXft
     -> libthr
   -> libGL

  Two workarounds are known:
   1) Change the linking order to have libGL linked first, or
   2) Also link to libthr in the (base) application.

  This patch implements the latter fix.

  PR:		205149, 206899
  Approved by:	ports-secteam (feld@)

Changes:
_U  branches/2016Q1/
  branches/2016Q1/x11/kde4-workspace/Makefile
  branches/2016Q1/x11/kde4-workspace/files/patch-kwin_opengltest_CMakeLists.txt
Comment 3 David Naylor freebsd_committer freebsd_triage 2018-12-11 07:17:48 UTC
Unable to reproduce on 11.2-RELEASE-p4.  Thus, I am assuming this has been fixed :-)