Why are shared libraries on Linux executable?

Actually it depends on the ldd implementation. ldd is usually a script, you can edit it to see where and why you get that error.

On Ubuntu 10.04, ldd checks for the read permission only. It may give the error not a dynamic executable if the file is not a ELF (Executable and Linkable Format). The libs here are all -rw-r--r--, for instance

$ find /usr/lib -type f -name "libm*.so*" -ls
(...)
-rw-r--r--   1 root     root       216800 Feb 26 22:20 /usr/lib/libmp.so.3.1.16
-rw-r--r--   1 root     root        76728 Mar 14 04:23 /usr/lib/libmjpegutils-1.9.so.0.0.0
-rw-r--r--   1 root     root       134464 Jan 29  2010 /usr/lib/libm17n-core.so.0.3.0
-rw-r--r--   1 root     root       290480 Feb 17  2010 /usr/lib/libmtp.so.8.3.2

It isn't shocking to want an x access for a shared library. The executable mode is a convention that gives the OS another level of access rights control. The executable loader controls that access, to ensure the user can execute it, but also to prevent errors (some scripts or programs should not be executed by some people).

This could be extended to the shared libraries for the same reason - but shared libraries cannot run by themselves, and are less error prone to be used by accident). Thus the need is less obvious (the r access suffices).


You can actually execute a lot of libraries, see for example what happens when you type /lib/libc.so.6 at your shell on a recent GNU/Linux system.

Tags:

Linux