After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 694485 - GIRepository: add API for extending library paths
GIRepository: add API for extending library paths
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-02-22 22:00 UTC by Giovanni Campagna
Modified: 2015-02-07 16:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GIRepository: add API for extending library paths (4.70 KB, patch)
2013-02-22 22:00 UTC, Giovanni Campagna
reviewed Details | Review
GIRepository: add API for extending library paths (5.88 KB, patch)
2013-02-24 18:45 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2013-02-22 22:00:25 UTC
Previously we would require applications that shipped with private
typelibs to add the private path to LD_LIBRARY_PATH, or to have a
launcher binary with the right RPATH.
Now they can just call GIRepository.prepend_library_path() before
they access the module.
Comment 1 Giovanni Campagna 2013-02-22 22:00:28 UTC
Created attachment 237215 [details] [review]
GIRepository: add API for extending library paths
Comment 2 Colin Walters 2013-02-23 15:45:45 UTC
Review of attachment 237215 [details] [review]:

I know I filed the gjs application bug, and this came from that, but after thinking about this more:

The thing I don't like about this is that it only works for the one shared library used by the typelib.  But what if you have an introspectable library that depends on a non-introspectable library, and you want to put them both in an app-private libdir?

The app will try to load the first, but the dynamic linker will fail to find the second.

I think the best way to solve this is to set an rpath to your app's private directory.
This is actually *really* easy to do with automake/libtool.

Failing that you can wrapper script LD_LIBRARY_PATH, but the rpath approach works really well.

::: girepository/gitypelib.c
@@ +2066,3 @@
+
+void
+g_irepository_prepend_library_path (const char *directory)

Needs documentation, and Since:
Comment 3 Giovanni Campagna 2013-02-23 16:44:05 UTC
No, prepend_library_path is not an alternative to RPATH, is an addition to one. Of course, it's expected that you use libtool, so the introspectable library will have the private directory in the RPATH and find the non-introspectable one just fine.
(Ok, I did not test this, but it should work according to the manual)

The problem is when you can't modify RPATH. Ie, what I'm trying to achieve is avoiding a compiled binary whose only purpose is the RPATH. It should work with stock gjs-console or python.

(OK, I just found that you can invoke ld.so with --library-path
Comment 4 Colin Walters 2013-02-23 17:14:03 UTC
(In reply to comment #3)
>
> The problem is when you can't modify RPATH. Ie, what I'm trying to achieve is
> avoiding a compiled binary whose only purpose is the RPATH. It should work with
> stock gjs-console or python.

Oh right, duh.  Hrm...ideally there'd be this API, except in glibc.  <looks>  There's this glibc-specific /usr/include/link.h which has a variety of interesting lowlevel API for the dynamic linker.  

Although if we wanted to be a bit more portable, we *could* call setenv("LD_LIBRARY_PATH").  The downside of that is that we must do it before any threads are created.  Except, ew...it would get inherited by child processes =/

Well, if we modified glibc today, we'd still have to wait a while before we could hard-depend on it.  So I'm not opposed to this new API now, but we should at least *consider* modifying glibc.
Comment 5 Giovanni Campagna 2013-02-23 17:28:23 UTC
It's worse than that, LD_LIBRARY_PATH is cached when the dynamic linker is loaded (before main()), so setting it after has no effect.

And even if we modified glibc, we could never hard depend on it to the extent of having gjs or pygobject using that API directly, because they're expect to work on all glib supported platforms, so we would still go through some form of prepend_library_path() in g-i.
Comment 6 Colin Walters 2013-02-24 15:28:33 UTC
(In reply to comment #5)

> And even if we modified glibc, we could never hard depend on it to the extent
> of having gjs or pygobject using that API directly, because they're expect to
> work on all glib supported platforms, so we would still go through some form of
> prepend_library_path() in g-i.

Yeah...but I still feel too often we lose out on the opportunity to add useful features to e.g. glibc because of that.

If it was added to glibc, maybe other libcs eventually would pick it up too..


Anyways, let's get your patch in.  Can you just add a doc comment?
Comment 7 Giovanni Campagna 2013-02-24 18:45:32 UTC
Created attachment 237299 [details] [review]
GIRepository: add API for extending library paths

Previously we would require applications that shipped with private
typelibs to add the private path to LD_LIBRARY_PATH, or to have a
launcher binary with the right RPATH.
Now they can just call GIRepository.prepend_library_path() before
they access the module.
Comment 8 Colin Walters 2013-02-24 19:25:39 UTC
Review of attachment 237299 [details] [review]:

Minor feeling that the change to delete the SHLIB_SUFFIX fallback should be a separate patch, but eh, not a big deal.

ACN after the minor doc comment updates.

::: girepository/gitypelib.c
@@ +2080,3 @@
+ * in this way, loading will fall back to the system library
+ * path (ie. LD_LIBRARY_PATH and DT_RPATH in ELF systems).
+ * See the documentation of your dynamic linkers for full details.

"dynamic linker" parses better

@@ +2081,3 @@
+ * path (ie. LD_LIBRARY_PATH and DT_RPATH in ELF systems).
+ * See the documentation of your dynamic linkers for full details.
+ */

Since: 1.35.8
Comment 9 Giovanni Campagna 2013-02-24 22:11:22 UTC
Attachment 237299 [details] pushed as 9faf4b4 - GIRepository: add API for extending library paths
Comment 10 André Klapper 2015-02-07 16:57:05 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]