Bug 140143 - [patch] [rtld] dlopen(3) doesn't promote RTLD_GLOBAL for linked libraries
Summary: [patch] [rtld] dlopen(3) doesn't promote RTLD_GLOBAL for linked libraries
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-31 15:40 UTC by David Naylor
Modified: 2014-12-16 14:51 UTC (History)
1 user (show)

See Also:


Attachments
file.shar (4.36 KB, text/plain)
2009-10-31 15:40 UTC, David Naylor
no flags Details
rtld_global.shar (4.67 KB, application/x-shar)
2010-05-31 15:14 UTC, David Naylor
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Naylor 2009-10-31 15:40:01 UTC
If a shared library is linked to another than any attempts from the first library to promote the symbols of the second library to RTLD_GLOBAL does not work [via dlopen("libsecond.so", RTLD_NOLOAD|RTLD_GLOBAL), or using RTLD_LAZY or RTLD_NOW].

This is known to affect devel/kdebindings4-python-pykde4.

This is not a problem under Linux (i.e. linux exhibits expected behaviour).

Fix: There is only a work-around that may not work in all situations:
Promote the first libraries symbols to RTLD_GLOBAL.  This, however, I think is overly broad and deviates from established behaviour (under Linux).  

In the example attached this amounts to:
dlopen("libplugin.so", RTLD_NOLOAD | RTLD_GLOBAL)
where libplugin.so is the first library.  

Patch attached with submission follows:
How-To-Repeat: [skip to bottom for coded example]

Have a shared library that is linked (at compile time) to a second library then have the second library load a third that requires symbols from the second but does not declare its dependency on the second library [e.g. libpython and lib/python26/lib-dynload/*].  

If the second library is loaded (without being linked) with RTLD_GLOBAL then all is well.  

See attached for rtld_global.shar.  Extract content and run:
# make  *
# make -DTRIGGER **

This runs two tests.  The first test is the first library that dlopen's the second library (it should run fine).  The second test is the first library that is linked to the second library and attempts to promote the second libraries symbols to RTLD_GLOBAL.  See below:

* Runs with work-around (see Fix below).  This works
** Runs without work-around [aka dlopen("libmaster.so", RTLD_NOW | RTLD_GLOBAL)] with 'libmaster.so' being the second library.  This does not work.
Comment 1 David Naylor 2010-05-31 15:14:30 UTC
Attached is an undated test case.  Extract and run make.  This works without 
failure under Linux but fails under FreeBSD.  
Comment 2 David Naylor freebsd_committer freebsd_triage 2014-12-16 14:51:41 UTC
This is no longer reproducable on FreeBSD 10.1-RELEASE.