Warning: shared library text segment is not shareable

When I try to build my app in Android studio I get next error:

[x86] Compile        : mpg123 <= getcpuflags.S
  [x86] Compile        : mpg123 <= dither.c
  [x86] Compile        : mpg123 <= feature.c
  [x86] SharedLibrary  : libmpg123.so
  /Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable
  /Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: treating warnings as errors
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [/app/build/intermediates/ndkBuild/debug/obj/local/x86/libmpg123.so] Error 1

It is happen only for x86 ABI. I build successfully for armeabi-v7a ABI. But for x86 I get error. I am using SDL2-2.0.7, SDL2_image-2.0.2 and SDL2_mixer-2.0.2.

Android with armeabi-v7a is very slow that is why I need android with x86 to test my app.

How to fix this issue?

1 Like

It’s likely to be because of the change at API level 23, requiring that x86 shared libraries not contain text relocations (see here). That means they must be compiled as Position Independent Code (for example using the -fPIC compiler flag).

@rtrussell, thanks!

I was trying set

LOCAL_LDLIBS += -Wl,–no-warn-shared-textrel

but it didn’t help and I got another issue which I have described in my another question.

I will try compile with -fPIC compiler flag.

@rtrussell, I have added

LOCAL_LDFLAGS :=

LOCAL_LDFLAGS += -fPIC

to the /SDL2_mixer/Android.mk, but it didn’t help. I still get

warning: shared library text segment is not shareable
error: treating warnings as errors

What am I doing wrong?

Also, I had tried add

LOCAL_DISABLE_FATAL_LINKER_WARNINGS = true

to the /SDL2_mixer/Android.mk

but no results.

Two points. Firstly, disabling the warning (even if you can succeed in doing that) isn’t going to help, because recent versions of Android will not install an app that has Text Relocations in shareable libraries. So by disabling the warning you are simply transferring the problem from build-time to install-time!

Secondly, I think LOCAL_LDFLAGS controls the linker flags, not the compiler flags. Try putting the ‘-fPIC’ in LOCAL_CFLAGS.

1 Like

@rtrussell
I have added this line:

LOCAL_CFLAGS += -fPIC

after line:

LOCAL_CFLAGS := $(DECODER_CFLAGS)

but I still get error:

[x86] Compile        : mpg123 <= getcpuflags.S
  [x86] Compile        : mpg123 <= dither.c
  [x86] Compile        : mpg123 <= feature.c
  [x86] SharedLibrary  : libmpg123.so
  /Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable
  /Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: treating warnings as errors
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [/app/build/intermediates/ndkBuild/debug/obj/local/x86/libmpg123.so] Error 1

I have added that line to the /SDL2_mixer/external/mpg123-1.25.6/Android.mk. Have I changed the right Android.mk?

I use this sdk version:

minSdkVersion 16
targetSdkVersion 27

which means targetSdkVersion >= 23

getcpuflags.S is an assembly language file so the -fPIC switch is not going to have any effect on that. If the text relocation is in that module, the only solution will be to re-write the assembler code. If it’s a trivial function - which I’m guessing from the filename it probably is - that may not be too difficult.

It’s even possible that the code is already position-independent but the object module generated by the assembler contains a flag to say it isn’t. Until this issue arose that would have been harmless, but now it isn’t.

Arguably whoever maintains SDL_mixer should make the modification because it’s not very satisfactory for a standard SDL extension to be incompatible with x86 Android. On the other hand it’s the fault of Google for introducing this questionable restriction.

Richard.

1 Like

I even tried run my app on android with 22 API and still get this error? How it can be?

@rtrussell, are you a SDL2 developer?

I have sent a letter to the email which I have found on the mercurial repository of SDL2_mixer. I hope that developer will answer me.

No, just a user. But because my app is affected by this issue I have done some research into it. At the moment I can’t support x86 Android later than Lollipop, and probably I never will. It’s less of a problem than it might have been because Intel have pulled out of mobile CPU development, so there probably won’t be any more x86-based mobile devices. However it stops my app running on most Chromebooks which is more serious.

I think you mentioned earlier that an ARM build (which should not be affected by this issue) is too slow, but that’s not been my experience. The best ARM-based products (for example my OnePlus 5 phone) are much faster than any x86-based mobile devices I have ever tested. Perhaps you should consider that route.

Richard.

It is very slow on android emulator. Besides it takes a lot of CPU when I start run app on armeabi-v7a emulator. I will buy some android device (or devices) for testing but only after I will run successfully and test on emulators.

I see only one option at current moment: connect somehow with SDL2 developers and ask them.

Thank you for the help!

Oh, I see. I’ve never used an Android emulator; I’ve read too many reports of them giving misleading results. I’ve found testing on a real device to be entirely satisfactory, using USB debugging (adb).

@rtrussell, I have got an email from moderator of this forum. He have wrote that latest SDL_mixer changes have fixed the compile error:
http://hg.libsdl.org/SDL_mixer .

I have downloaded latest changes from this page from line

2 days ago Sam Lantinga Added support for building mpg123 on Android arm64-v8a default tip

from field “files” which lead me to this page but it still doesn’t work for me. Besides, in new changes in file /app/src/main/cpp/SDL2_mixer/external/mpg123-1.25.6/Android.mk I see lines:

# This disables the following warning:
#   warning: shared library text segment is not shareable
# However, the library still has PIC unaware assembly!
LOCAL_DISABLE_FATAL_LINKER_WARNINGS = true

I have tried earlier to set LOCAL_DISABLE_FATAL_LINKER_WARNINGS to the true, but every time I got an error:

dlopen failed: /data/app/com.myapp-1/lib/x86/libmpg123.so: has text relocations

and I got this error at this time after using the latest changes in SDL2_mixer. I got this error on Android emulator in pop-up window.

So, latest changes in mercurial repository don’t work.

Problem is in the mpg123 library and it was added to SDL2_mixer only in 2.0.2 version of mixer. mpg123 is absent in the 2.0.1 version of SDL2_mixer. Is it really so needed in the mixer if mixer became a broken in android x86?

I wonder if the issue has been misunderstood by whoever made those changes. Disabling the warning (which is what you were also trying to do) does not address the true problem, it simply defers it from being reported at build time (which is helpful) to it becoming a fatal error at install time (which is unhelpful). I don’t know of any solution other than modifying the assembly language code to be position-independent.

1 Like

I have reported about this bug to the bugzilla https://bugzilla.libsdl.org/show_bug.cgi?id=3991

I’ve got an email that this issue is fixed https://bugzilla.libsdl.org/show_bug.cgi?id=3991#c3 .