Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i686] OpenJDK has text relocations #7215

Closed
ghost opened this issue Jul 30, 2021 · 3 comments
Closed

[i686] OpenJDK has text relocations #7215

ghost opened this issue Jul 30, 2021 · 3 comments
Labels
arch-i686 Issue reproducible on packages compiled for i686 bug report Something is not working properly help wanted Help is wanted in order to solve the issue

Comments

@ghost
Copy link

ghost commented Jul 30, 2021

Problem description

Dynamic linker detects text relocations in one or more binaries. As result, it isn't possible to run utilities like java, jshell, etc.

~ $ java
linker: "/data/data/com.termux/files/usr/opt/openjdk/lib/server/libjvm.so" has text relocations (https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-Enforced-for-API-level-23)
Error: dl failure on line 542
Error: failed /data/data/com.termux/files/usr/opt/openjdk/lib/server/libjvm.so, because dlopen failed: "/data/data/com.termux/files/usr/opt/openjdk/lib/server/libjvm.so" has text relocations (https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-Enforced-for-API-level-23)

Same issue affects https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/tree/buildjre16 on which the current build is based.

Additional information

As I don't have real i686 device, test was executed in Termux environment packaged as Docker image. Assume it is equivalent to Android 9 since it uses libc and dynamic linker from its GSI image.

docker run -it --rm xeffyr/termux:i686
apt update
apt upgrade -yq
apt install openjdk-17
@ghost ghost added bug report Something is not working properly help wanted Help is wanted in order to solve the issue arch-i686 Issue reproducible on packages compiled for i686 labels Jul 30, 2021
@w4123
Copy link
Contributor

w4123 commented Aug 25, 2021

Probably related to this part: https://github.com/termux/openjdk-mobile-termux/blob/1b8989d1093511649da820fd108794dd424279d9/make/hotspot/lib/JvmOverrideFiles.gmk#L68

When building for x86, some codes are not built with -fPIC, so they may have text relocations. Commenting this part out may help.

@w4123
Copy link
Contributor

w4123 commented Aug 26, 2021

Applying the above-mentioned fix does remove TEXTREL from libjvm.so, but now it reports TEXTREL in libandroid-spawn.so
It seems that libandroid-spawn is also not built with -fPIC.

@w4123
Copy link
Contributor

w4123 commented Aug 26, 2021

#7406

Grimler91 added a commit that referenced this issue Aug 26, 2021
When adding this, we go from compiling with

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/clang++ [...] -mrelocation-model pic -pic-level 2 -pic-is-pie [...]

to

  /home/builder/.termux-build/_cache/android-r21d-api-24-v5/bin/clang++ [...] -mrelocation-model pic -pic-level 2 [...]

Before, we got a warning when compiling libandroid-spawn:

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable

and trying to use a program linked against libandroid-spawn gave an
error, see
#7215 (comment)
the Without this, libraries might end up with text relocations. For
some reason it does not seem to be an issue on the other arches.
Grimler91 added a commit that referenced this issue Aug 27, 2021
When adding this, we go from compiling with

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/clang++ [...] -mrelocation-model pic -pic-level 2 -pic-is-pie [...]

to

  /home/builder/.termux-build/_cache/android-r21d-api-24-v5/bin/clang++ [...] -mrelocation-model pic -pic-level 2 [...]

Before, we got a warning when compiling libandroid-spawn:

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable

and trying to use a program linked against libandroid-spawn gave an
error, see
#7215 (comment)
the Without this, libraries might end up with text relocations. For
some reason it does not seem to be an issue on the other arches.

%ci:no-build
Grimler91 added a commit that referenced this issue Aug 27, 2021
When adding this, we go from compiling with

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/clang++ [...] -mrelocation-model pic -pic-level 2 -pic-is-pie [...]

to

  /home/builder/.termux-build/_cache/android-r21d-api-24-v5/bin/clang++ [...] -mrelocation-model pic -pic-level 2 [...]

Before, we got a warning when compiling libandroid-spawn:

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable

and trying to use a program linked against libandroid-spawn gave an
error, see
#7215 (comment)
the Without this, libraries might end up with text relocations. For
some reason it does not seem to be an issue on the other arches.

%ci:no-build
Grimler91 added a commit that referenced this issue Aug 27, 2021
When adding this, we go from compiling with

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/clang++ [...] -mrelocation-model pic -pic-level 2 -pic-is-pie [...]

to

  /home/builder/.termux-build/_cache/android-r21d-api-24-v5/bin/clang++ [...] -mrelocation-model pic -pic-level 2 [...]

Before, we got a warning when compiling libandroid-spawn:

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable

and trying to use a program linked against libandroid-spawn gave an
error, see
#7215 (comment)
the Without this, libraries might end up with text relocations. For
some reason it does not seem to be an issue on the other arches.

%ci:no-build
@termux termux deleted a comment from pakarat512 Aug 29, 2021
omecamtiv pushed a commit to omecamtiv/termux-packages that referenced this issue Aug 29, 2021
When adding this, we go from compiling with

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/clang++ [...] -mrelocation-model pic -pic-level 2 -pic-is-pie [...]

to

  /home/builder/.termux-build/_cache/android-r21d-api-24-v5/bin/clang++ [...] -mrelocation-model pic -pic-level 2 [...]

Before, we got a warning when compiling libandroid-spawn:

  /home/builder/.termux-build/_cache/android-r21d-api-24-v4/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: warning: shared library text segment is not shareable

and trying to use a program linked against libandroid-spawn gave an
error, see
termux#7215 (comment)
the Without this, libraries might end up with text relocations. For
some reason it does not seem to be an issue on the other arches.

%ci:no-build
Grimler91 added a commit that referenced this issue Oct 22, 2021
As we have seen [1], i686 seem to explicitly need -fPIC.  Pass
CPPFLAGS in more places when building aapt, to avoid an error like:

ld: error: relocation R_386_PC32 cannot be used against symbol config_free; recompile with -fPIC
>>> defined in /tmp/config_utils-70060d.o
>>> referenced by config_utils.c
>>>               /tmp/config_utils-70060d.o:(config_free)

[1] #7215 (comment)
Grimler91 added a commit that referenced this issue Oct 22, 2021
As we have seen [1], i686 seem to explicitly need -fPIC.  Pass
CPPFLAGS in more places when building aapt, to avoid an error like:

ld: error: relocation R_386_PC32 cannot be used against symbol config_free; recompile with -fPIC
>>> defined in /tmp/config_utils-70060d.o
>>> referenced by config_utils.c
>>>               /tmp/config_utils-70060d.o:(config_free)

[1] #7215 (comment)
Grimler91 added a commit that referenced this issue Oct 22, 2021
As we have seen [1], i686 seem to explicitly need -fPIC.  Pass
CPPFLAGS in more places when building aapt, to avoid an error like:

ld: error: relocation R_386_PC32 cannot be used against symbol config_free; recompile with -fPIC
>>> defined in /tmp/config_utils-70060d.o
>>> referenced by config_utils.c
>>>               /tmp/config_utils-70060d.o:(config_free)

[1] #7215 (comment)
metayan pushed a commit to metayan/termux-packages that referenced this issue Nov 28, 2021
As we have seen [1], i686 seem to explicitly need -fPIC.  Pass
CPPFLAGS in more places when building aapt, to avoid an error like:

ld: error: relocation R_386_PC32 cannot be used against symbol config_free; recompile with -fPIC
>>> defined in /tmp/config_utils-70060d.o
>>> referenced by config_utils.c
>>>               /tmp/config_utils-70060d.o:(config_free)

[1] termux#7215 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-i686 Issue reproducible on packages compiled for i686 bug report Something is not working properly help wanted Help is wanted in order to solve the issue
Projects
None yet
Development

No branches or pull requests

2 participants