Balaraman L
Balaraman L

Reputation: 196

FFmpeg linker error: Error due to text relocations in libavcodec shared object

I am trying to build an Android app which uses FFmpeg native code for video decoding and encoding. I have a 64-bit machine running 32-bit Ubuntu 14.04, ADT version 23. I downloaded FFmpeg-2.4.4 (32-bit) and built it for Android following the steps mentioned here - http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/

I used latest Android NDK, that is NDK r10c. For testing, I used FFmpeg's API example code given in this link - http://ffmpeg.org/doxygen/trunk/decoding__encoding_8c-source.html

I was able to build all the shared objects successfully and Android project gets compiled successfully without any errors.

Following code is Android code to load all shared objects

public class CallNative {
public static String libName = "decode_encode" ;
public CallNative(){
    System.loadLibrary("avutil-54");
    System.loadLibrary("swresample-1");
    System.loadLibrary("avcodec-56");
    System.loadLibrary("avformat-56");
    System.loadLibrary("swscale-3");
    System.loadLibrary("avfilter-5");
    System.loadLibrary(libName);
}

public native int decode(String Filename, int length);

}

And, this is how, decode function is called from Android.

Uri videoURI = Uri.parse(fileUri.toString());
                   String videoFilePath = getFilePathFromURI(getApplicationContext(), videoURI);
                   Log.d("SPLASH","Entering native decode call");
                   CallNative n = new CallNative();
                   n.decode(videoFilePath, videoFilePath.length());
                   Log.d("SPLASH","successfully returned from decode call");

When I debugged, App crashes when it enters native function call. I get following linker error.

W/linker(32244): libavcodec-56.so has text relocations. This is wasting memory and prevents security hardening. Please fix.

I tried the same with FFmpeg 2.4.3 and 2.0.6 packages as well. I am getting the same error.

How to resolve this?

Upvotes: 2

Views: 1595

Answers (1)

Guy
Guy

Reputation: 12512

The code will work on all android version < 23. I.e. if you set your targetSkdVersion to 21, the code will run with a warning.

Unfortunately, since Marshmallow (v23), Google no longer allows loading libraries with text relocations. Thus if you set your target sdk version to 23, your app will crash.

Google will not change this behavior, see: https://code.google.com/p/android/issues/detail?id=191235&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

Ffmpeg team won't remove the text relocations "anytime soon", see: https://trac.ffmpeg.org/ticket/4928

So currently it seems your only option is to set your target sdk to 21.

Upvotes: 1

Related Questions