Gcc generates a shared object with execute permissions

I am creating a shared library on linux using gcc. I do not see compilation errors or references, but my shared object always has a run bit set (although readelf indicates its shared object). I just do this:

> echo "int f() {return 1;}" > a.cpp > gcc -c a.cpp > gcc -shared -o liba.so ao > ls -l liba.so -rwxr-xr-x 1 me me 6652 2011-06-09 17:05 liba.so 

Why does a shared object have a run bit?

+4
source share
2 answers

Because you can usually run shared libraries. Most shared libraries will crash when they run, but you can run them.

Some libraries have an entry point defined (-Wl, -e, the_name_of_your_entry_point, the main function in standard C programs), after which you can execute them without crashing.

+5
source

HP-UX requires that, for example, executable libraries be executable. If this is not the case, the memory card using the dynamic loader fails with the resolution allowed. And, apparently, this does not hurt to have bit bits on other platforms, so GCC takes a safe route and sets the x bit.

+1
source

All Articles