Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm just curious.

bash-3.00$  ldd libmylibrary.so
ldd: warning: you do not have execution permission for `libmylibrary.so'

Everything seems to work fine just with +r. I noticed that most of the .so's in /usr/lib do have +x set...

Why shared libs are supposed to have executable bit set? What could happen if I don't set it?

share|improve this question
2  
Libraries definitely don't need +x to run properly. Perhaps they're links however? Links would need +x to be followed. –  Chris S Aug 24 '10 at 13:56
    
Yes, they don't need +x, yet most of the libraries has it set. –  Tomo Aug 24 '10 at 20:09
add comment

4 Answers

up vote 3 down vote accepted

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).

share|improve this answer
add comment

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.

share|improve this answer
add comment

think like having an executable file with -x. You won't be able to execute it. Consider these libraries as a collection of general functions, that are being called by another program (let's say myProgra). If you cannot execute the libraries / function ... then you have nothing

An example

function1() {} 
function2() {} 
int main() { 
printf("Let's call func1"); 
function1(); 
printf("Let's call func2"); 
function2(); 
} 

Now if you place function1 and function2 in another file and you include it, then you a library. (Of course it's something more complicated. This is just an example)

But in any case, as you can see, you have to execute the code that is being included in the library

share|improve this answer
    
But you execute executables, not libraries. –  Ignacio Vazquez-Abrams Aug 24 '10 at 12:16
    
See the edited version above –  Nikolaidis Fotis Aug 24 '10 at 12:46
add comment

The key is the file format, Executable and Linkable Format. Since the same exact file format is used to identify both an executable and a shared library, both must have the appropriate executable permissions for the OS loader. This allows for a single loader and for executables to be used as a DSO if they include a symbol table.

share|improve this answer
    
So, the loader uses permission bits, not the file header, to identify things to load? –  Tomo Aug 24 '10 at 20:09
    
The loader uses the file header to identify the contents as DYN or EXEC and do the appropriate thing. The execute bit is for the OS, not the loader. ELF is an executable format, without the execute bit, the OS won't allow the loader to execute the file in order to read the headers. Check out wikipedia for more on ELF en.wikipedia.org/wiki/Executable_and_Linkable_Format. –  nzwulfin Aug 25 '10 at 12:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.