Why are shared libraries executable?

Why have mostly all the common libraries in /usr/lib/ have the executable approval little bit set? I do not see any kind of usage instance for implementing them. Some do take care of to hook - up some kind of main function to publish a brief copyright and also variation note, yet several do not do also that and also segfault upon implementation.

So, what is the factor of establishing this x? Must all collection packagers do that? What will take place if I dlopen() a common collection that has 0644 approvals?

2022-06-07 14:33:14
Source Share
Answers: 2

Under HP - UX, shared libraries are mapped right into memory making use of mmap(), and also all memory web pages in the system have defense little bits which are paired with the bit and also cpu equipment is memory web page defense devices. In order to execute the materials of any kind of web page of memory on the system, that web page has to have PROT_EXEC set - a valuable attribute to stop information implementation ventures.

The mmap() call makes use of the approval little bits on the documents it will map to specify the defense littles the mapped memory web pages which are to have it: rwx - > PROT_READ|PROT_WRITE|PROT_EXEC (from sys/mman. h). so in order for a common collection to be useful on HP - UX, the documents having the common collection has to have execute approvals to guarantee that the mapped collection additionally has execute approval.

A common collection with setting 644 on an HP - UX system will certainly create core dumps.

2022-06-08 05:03:09

Non - executable common things function great, yet libraries noted executable might additionally be runnable as standalone programs.

So, what is the factor of establishing this x?

None, unless you desire them to send out variation or various other details

Must all collection packagers do that?


What will take place if I dlopen() a common collection that has 0644 permissions?

You'll get a new common object take care of (as long as the documents is legible etc) the director little bit does not influence this

As to why libraries which aren't useful as standalone executables still have the director little bit set: this is possibly simply an artefact of the construct system or link manuscript made use of.

instance result, simply for reference:

$ /lib/i386-linux-gnu/libc.so.6
GNU C Library (Ubuntu EGLIBC 2.15-0ubuntu10) stable release version 2.15, by Roland McGrath et al.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
Compiled by GNU CC version 4.6.3.
Compiled on a Linux 3.2.14 system on 2012-04-19.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
For bug reporting instructions, please see:
2022-06-07 14:52:10