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

conditional branch to PLT in THUMB-2 not supported yet. #337

Closed
ali1234 opened this issue Mar 20, 2017 · 17 comments
Closed

conditional branch to PLT in THUMB-2 not supported yet. #337

ali1234 opened this issue Mar 20, 2017 · 17 comments
Labels
Milestone

Comments

@ali1234
Copy link

ali1234 commented Mar 20, 2017

Description

While compiling a project with the gstreamer SDK:

Bug /home/al/tools/android/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.gold: error: conditional branch to PLT in THUMB-2 not supported yet.
libswresample/arm/audio_convert_neon.S:137: error: unexpected opcode while processing relocation R_ARM_THM_JUMP19
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Environment Details

  • NDK Version: Pkg.Revision = 14.0.3770861
  • Build sytem: ndk-build & ant
  • Host OS: Ubuntu Linux 16.04 (ndk was installed using ubuntu-make)
  • Compiler: Clang (not reproducible with GCC)
  • ABI: armeabi-v7a

To reproduce:

  1. Install android ndk.
  2. Get gstreamer sdk 1.9.2 for armv7 and unpack it somewhere: https://gstreamer.freedesktop.org/data/pkg/android/1.9.2/
  3. Clone the test case: https://github.com/ali1234/ndk-test-case
  4. Edit gstbuild so the paths match your environment.
  5. Run gstbuild. (Watch out, if successful it will try to sideload the built apk onto any connected device).

Uncommenting the toolchain line in jni/Application.mk to switch to GCC makes the error go away.

Note that you can pretty much ignore all of my code, as the error is coming from trying to link the gstreamer sdk libraries.

@DanAlbert
Copy link
Member

Thanks for the report. I've raised this internally as http://b/36451810 (our binutils folks use our internal bug tracker). I'll post updates here as I get them.

@DanAlbert DanAlbert added this to the r16 milestone Mar 24, 2017
@DanAlbert
Copy link
Member

Triaging for r16 since we need a binutils update and it's unlikely that we'll get one in time for r15.

@ludovic-bouguerra
Copy link

ludovic-bouguerra commented Jul 20, 2017

Hi,

You can use this NDK : Android NDK, Revision 10e (May 2015) downloadable here : https://developer.android.com/ndk/downloads/older_releases.html which works with gstreamer example.

Cheers

@enh
Copy link
Contributor

enh commented Jul 20, 2017

internal status:

I've verified that binutils-2.27 doesn't fix this either. In fact, it's still unsupported on ToT binutils upstream.

A few things to try:
1) Use -fno-integrated-assembler (the bug mentions that the issue doesn't show up with gcc).
2) Try ld.bfd (the bfd linker might have support for this).
3) Try passing '-mdisable-tail-calls' on clang command line (this optimization is probably why these jumps are being generated).

Does this have a upstream binutils bug?

It doesn't seem anything specific to Android or Chrome OS, and gold from ToT upstream still doesn't support these opcodes.

A smaller standalone testcase with an upstream bug would be useful.

@DanAlbert DanAlbert modified the milestones: r16, r17 Oct 3, 2017
tetkuz added a commit to tetkuz/TinyGStreamerApplication that referenced this issue Nov 21, 2017
Android.mk は Android tutorials[*1] と同じです。

Application.mk は android-ndk 側の問題[*2] があるため、
clang を使用せず gcc でビルドするように設定しています。

*1: https://gstreamer.freedesktop.org/documentation/tutorials/android/index.html)
*2: android/ndk#337
@harlanc
Copy link

harlanc commented Jan 14, 2018

@DanAlbert Is this problem fixed in version r16b ? I also encounter this issue.

Okay,I see it.It will be fixed in r17 for your plan..

@harlanc
Copy link

harlanc commented Jan 16, 2018

@DanAlbert does this problem has a patch currently or does this problem has a workaround?

Yesterday I do some tests and maybe found a workaround

  1. I use r14b and clang to compile the project and the error mentioned above appears
  2. Then I change the compiler to gcc(do not clean),means that I only use gcc to link,and it is passed.The so library can be generated successfully.

I want to know that if this is a good library?Is it dangerous to use it?

I also test it using r16b,and the error cannot disappear.

@enh
Copy link
Contributor

enh commented Jan 16, 2018

from the internal bug:

I've verified that binutils-2.27 doesn't fix this either. In fact, it's still unsupported on ToT binutils upstream.

A few things to try:

  1. Try ld.bfd (the bfd linker might have support for this).
  2. Try passing '-mdisable-tail-calls' on clang command line (this optimization is probably why these jumps are being generated).

Does this have a upstream binutils bug?
It doesn't seem anything specific to Android or Chrome OS, and gold from ToT upstream still doesn't support these opcodes.
A smaller standalone testcase with an upstream bug would be useful.

@DanAlbert
Copy link
Member

Can switch to bfd with -fuse-ld=bfd in your ldflags (I think it's -fuse-ld=bfd.exe on Windows, sadly).

@manang
Copy link

manang commented Jan 27, 2018

did you solve this issue?
Thanks

@kwatkins
Copy link

kwatkins commented Feb 2, 2018

-fuse-ld=bfd got further, still encountered another issue possibly related:

GStreamer      : [LINK] => gst-build-armeabi-v7a/libgstreamer_android.so
/Users/kwatts/workspace/gstreamer/armv7/lib/libswresample.a(audio_convert_neon.o): In function `swri_oldapi_conv_fltp_to_s16_nch_neon':
/home/jan/devel/gstreamer/cerbero/build/sources/android_universal/armv7/gst-libav-1.0-static-1.12.4/gst-libs/ext/libav/libswresample/arm/audio_convert_neon.S:137:(.text+0x186): relocation truncated to fit: R_ARM_THM_JUMP19 against symbol `swri_oldapi_conv_fltp_to_s16_2ch_neon' defined in .text section in 
/workspace/gstreamer/armv7/lib/libswresample.a(audio_convert_neon.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [buildsharedlibrary_armeabi-v7a] Error 1

@DanAlbert DanAlbert modified the milestones: r17, r18 Feb 14, 2018
@DanAlbert
Copy link
Member

Not fixed in binutils yet, and we're past the point that it would make it to r17 if it were submitted today.

@agallers
Copy link

https://bugzilla.gnome.org/show_bug.cgi?id=793980
so not ideal but try >= android-universal-1.13.91

@rahulchaudhry
Copy link

It is true that the gold linker does not support "conditional branch to PLT in THUMB-2", and the bfd linker does. However, adding this support in the linker will not be a lasting solution. The conditional branch to PLT using a R_ARM_THM_JUMP19 relocation has a small range. Even if gold were to support it, it would only be useful in a small number of cases.

In this example, if I change the linker to ld.bfd with this patch:

--- share/gst-android/ndk-build/gstreamer-1.0.mk
+++ share/gst-android/ndk-build/gstreamer-1.0.mk
@@ -83 +83 @@ GSTREAMER_DEPS                := $(GSTREAMER_EXTRA_DEPS) gstreamer-1.0
-GSTREAMER_LD                  := -fuse-ld=gold -Wl,-soname,lib$(GSTREAMER_ANDROID_MODULE_NAME).so
+GSTREAMER_LD                  := -fuse-ld=bfd -Wl,-soname,lib$(GSTREAMER_ANDROID_MODULE_NAME).so

The build completes successfully. However, when I upgrade to gstreamer 1.14.0, I get a different build failure:

gstreamer-1.14.0/lib/libcrypto.a(poly1305-armv4.o): In function `poly1305_blocks_neon':
openssl-1.1.0g/crypto/poly1305/poly1305-armv4.s:510:(.text+0x474): relocation truncated to fit: R_ARM_THM_JUMP19 against symbol `poly1305_blocks' defined in .text section in gstreamer-1.14.0/lib/libcrypto.a(poly1305-armv4.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This shows the problem with R_ARM_THM_JUMP19 relocation. It does not have a good enough range. Even if a linker handles it today, an increase in the size of .so file will cause the linker to fail at a later date.

A better solution is to avoid this relocation, by converting this conditional branch into an unconditional branch, or by converting this branch through PLT into a direct jump.

I've sent patches for doing this to upstream ffmpeg and openssl projects:

The build issues should be fixed once these patches are merged upstream and make their way into gstreamer. Here are the two gstreamer bugs for re-enabling asm optimizations for libav and openssl/poly1305:

levitte pushed a commit to openssl/openssl that referenced this issue Apr 18, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable poly1305 optimization assembly,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/beab607d2b1ff23c41b7e01aa9c64be5e247d1e6

CLA: trivial

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #5949)
levitte pushed a commit to openssl/openssl that referenced this issue Apr 18, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable poly1305 optimization assembly,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/beab607d2b1ff23c41b7e01aa9c64be5e247d1e6

CLA: trivial

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #5949)

(cherry picked from commit 5bb1cd2)
TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Apr 19, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Apr 20, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Jun 18, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
@rprichard
Copy link
Collaborator

FWIW: I built the test case here with r15c and both Clang and GCC. It fails with Clang and succeeds with GCC. Both toolchains use -fuse-ld=gold. GCC succeeds because its driver passes -Bsymbolic to the linker. With -Bsymbolic, the 19-bit branch targets the nearby function symbol rather than the PLT. With r16, the GCC driver doesn't pass -Bsymbolic anymore (https://github.com/android-ndk/ndk/wiki/Changelog-r16#ndk).

The R_ARM_THM_JUMP19 relocation is in the swri_oldapi_conv_fltp_to_s16_nch_neon function in the prebuilt object file lib/libswresample.a(audio_convert_neon.o) that's packaged as part of gstreamer-1.0-android-armv7-1.9.2.tar.bz2.

@enh
Copy link
Contributor

enh commented Jul 6, 2018

we've upstreamed fixes to openssl and ffmpeg.

there are no R_ARM_THM_JUMP19 relocations in https://gstreamer.freedesktop.org/data/pkg/android/1.14.1/

-Bsymbolic is a workaround for those building old versions of gstreamer from source.

@enh enh closed this as completed Jul 6, 2018
@ystreet
Copy link

ystreet commented Jul 7, 2018

There's no relocations in the gstreamer 1.14.1 binaries because we disabled neon optimzations in ffmpeg due to this issue.

https://cgit.freedesktop.org/gstreamer/cerbero/commit/recipes/gst-libav-1.0.recipe?id=41556c415739fbc3a72c7eaee7e70a565b719b2f

Do you have references to the specific commits in openssl and ffmpeg that fixed this issue?

TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Jul 8, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
@enh
Copy link
Contributor

enh commented Jul 9, 2018

see rahulchaudhry's comment above for links to the patches.

TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Jul 10, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Jul 16, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Oct 23, 2018
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
syphyr pushed a commit to syphyr/android_external_ffmpeg that referenced this issue Apr 21, 2021
Branch to global symbol results in reference to PLT, and when compiling
for THUMB-2 - in a R_ARM_THM_JUMP19 relocation. Some linkers don't
support this relocation (ld.gold), while others can end up truncating
the relocation to fit (ld.bfd).

Convert this branch through PLT into a direct branch that the assembler
can resolve locally.

See android/ndk#337 for background.

The current workaround is to disable neon during gstreamer build,
which is not optimal and can be reverted after this patch:
https://github.com/freedesktop/gstreamer-cerbero/commit/41556c415739fbc3a72c7eaee7e70a565b719b2f

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b22db4f465c9adb2cf1489e04f7b65ef6bb55b8b)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests