What are possible causes of "failed to map segment from shared object: operation not permitted", and how to debug?
Asked Answered
J

4

37

I have two executables, both cross compiled to run in Android. I have put both on the device in the same directory. I have put all the shared libraries that they are dependent on in the same directory, including ld-linux.so.3. I run the executables by using:

ld-linux.so.3 --library-path /path/to/libraries executable_name

both work on older versions of Android when running as any user. The both work on the latest version of Android if running as root. Only one works on the latest version of android when running as any user. Instead it gives:

failed to map segment from shared object: executable_name operation not permitted

How can I find out what is different with the executable that won't run?

I read a lot online and most people that get this error, either:

A) don't have execute permissions for one of the libraries they are dependent on or the executable itself.

or

B) are trying to run from a directory that is mounted as NOEXEC.

both of these don't appear to be the case. It can find all libraries and I can load any library by itself and see what other things it is dependent on being resolved. Also, I can run basic scripts from the directories of interest.

The newer version of Android, Jelly Bean, is a different linux kernel version and I wonder if that is related.

What give? How do I debug?

Jerrylee answered 21/11, 2012 at 21:12 Comment(1)
Asked a different way (with bounty) here: #13468451Jerrylee
J
3

The issue was with how the executables were compiled. They needed to be compiled with a cross compiler that properly supported newer arm devices. The compiler I used generated executables that would only work on a subset of arm devices. The issue was not with the different versions of android.

Jerrylee answered 21/8, 2014 at 18:44 Comment(0)
H
41

Permission issue. Need to remount /tmp. The following command works for me (Centos 7):

sudo mount /tmp -o remount,exec

Hoodmanblind answered 15/4, 2019 at 16:23 Comment(1)
The same thing happened in java when our /tmp folder was switched to be noexec. We can't remount it, so instead we add -Djava.io.tmpdir=/scratch/30day_tmp when launching our application.Bikales
W
34

I had this error in a different context. For some reason it causes an error when trying to use the /tmp folder.

To solve this I simply:

mkdir tmp
export TMPDIR=`pwd`/tmp

The TMPDIR is a constant that tells where the temporary folder of the system is. This solutions resolves by creating a directory where we are allowed to and settings this directory into the system. Therefore we can now write to the new system default temporary folder.

Wolff answered 4/6, 2017 at 7:53 Comment(3)
What is TMPDIR?Cabana
it is an environment variable which I guess some scripts use to find the location of a temporary directory where they can do book-keepingSurrebuttal
This helped solve a completely unrelated issue (Python/Anaconda installation on a machine where I didn't have access to /tmp). May be useful for some who end up with this error outside of the Android context. :)Orchid
J
3

The issue was with how the executables were compiled. They needed to be compiled with a cross compiler that properly supported newer arm devices. The compiler I used generated executables that would only work on a subset of arm devices. The issue was not with the different versions of android.

Jerrylee answered 21/8, 2014 at 18:44 Comment(0)
P
0

SELinux is enabled by default on Android 4.3, however it is supposed to be "permissive" [0]. Maybe your phone vendor added more restrictive rules.

[0] https://source.android.com/devices/tech/security/se-linux.html

Problem answered 20/8, 2013 at 7:43 Comment(1)
This problem showed up on the first version of Jelly Bean, so pre this change. But, this is an interesting read. I haven't used 4.3 much.Jerrylee

© 2022 - 2024 — McMap. All rights reserved.