Bug 108821 - dlopen example with libm.so is incorrect
Summary: dlopen example with libm.so is incorrect
Status: RESOLVED CODE_FIX
Alias: None
Product: Documentation
Classification: Unclassified
Component: man-pages (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: documentation_man-pages@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-03 14:58 UTC by Florian Weimer
Modified: 2015-12-05 07:03 UTC (History)
1 user (show)

See Also:
Kernel Version:
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Florian Weimer 2015-12-03 14:58:51 UTC
This does not work because libm.so can be a linker script:

           handle = dlopen("libm.so", RTLD_LAZY);

The proper way to do this is to include <gnu/lib-names.h> and use LIBM_SO.
Comment 1 Michael Kerrisk 2015-12-04 19:15:13 UTC
Hi Florian,

I'm reluctant code a glibc dependency into what I would like to be a fairly vanilla dlopen example. What if I used a function from libc itself (e.g., strlen()). Does the same issue exist?

Cheers,

Michael
Comment 2 Florian Weimer 2015-12-04 19:24:31 UTC
(In reply to Michael Kerrisk from comment #1)
> Hi Florian,
> 
> I'm reluctant code a glibc dependency into what I would like to be a fairly
> vanilla dlopen example.

Fair point.  Although the example might confuse users because even where it works, it typically needs development packages at run time (because the .so link are only installed by them).

> What if I used a function from libc itself (e.g.,
> strlen()). Does the same issue exist?

libc.so is a linker script, too.  libm.so.6 and libc.so.6 are not, but they are glibc-specific to (some moderately current Solaris versions use libm.so.2 and libc.so.1, for example).
Comment 3 Michael Kerrisk 2015-12-04 19:48:17 UTC
So, I'm inclined to close this as WONTFIX. I mean: this example will work for most people on most systems, right? The alternative is to create a bigger example where I build a little library that is then dlopen()-ed. But that seems like a little too much work, and might actually be less easy to understand than the current example.

Do you have a strong objection to WONTFIX, Florian?
Comment 4 Florian Weimer 2015-12-04 21:05:51 UTC
(In reply to Michael Kerrisk from comment #3)

> So, I'm inclined to close this as WONTFIX. I mean: this example will work
> for most people on most systems, right?

With glibc, libm.so is increasingly a linker script on x86_64 due to this change:

  <https://sourceware.org/glibc/wiki/libmvec>

This was introduced in glibc 2.22, so few distributions have this change yet.
Comment 5 Michael Kerrisk 2015-12-05 07:03:35 UTC
Thanks for all of the info Florian. So, in the end it seems best to make the change you already suggested :-}. Done!

Note You need to log in before you can comment on or make changes to this bug.