Cross compiling libvpx on Android for x86_64

492 views
Skip to first unread message

Dan Liang

unread,
Mar 15, 2017, 4:51:01 AM3/15/17
to WebM Discussion
Hi,

I'm trying to run the vpxenc on my Android 7.0 device and I downloaded the latest code of libvpx.

What I did are:

$NDK/build/tools/make_standalone_toolchain.py --arch x86_64 --install-dir ~/my_standalone_toolchain
export PATH=$PATH:~/my_standalone_toolchain/bin
CROSS=x86_64-linux-android- CC=clang CXX=clang++ ASFLAGS="-D__ANDROID__" ~/libvpx/configure --target=x86_64-android-gcc --sdk-path=$NDK

The confgiure script runs successfully:
  enabling vp8_encoder
  enabling vp8_decoder
  enabling vp9_encoder
  enabling vp9_decoder
Configuring for target 'x86_64-android-gcc'
  enabling x86_64
  enabling runtime_cpu_detect
  enabling mmx
  enabling sse
  enabling sse2
  enabling sse3
  enabling ssse3
  enabling sse4_1
  enabling avx
  enabling avx2
  using yasm
  enabling postproc
  enabling webm_io
  enabling libyuv
Creating makefiles for x86_64-android-gcc libs
Creating makefiles for x86_64-android-gcc examples
Creating makefiles for x86_64-android-gcc tools
Creating makefiles for x86_64-android-gcc docs


And the compilation is OK. However, when the tool “vpxenc” is pushed to the Android device, there's an error:
"vpxenc": error: only position independent executables (PIE) are supported.
Aborted

So I modified the .mk files manually to add the flags:
CFLAGS += -fPIE
CXXFLAGS += -fPIE
LDFLAGS += -fPIE -pie

However, there're errors during the linking phase for vpxdec:
    [LD] vpxdec
/home/anonymous/my_standalone_toolchain/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ./libvpx.a(fwd_txfm_ssse3_x86_64.asm.o): requires dynamic R_X86_64_32 reloc which may overflow at runtime; recompile with -fPIC
/home/anonymous/my_standalone_toolchain/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ./libvpx.a(quantize_ssse3_x86_64.asm.o): requires dynamic R_X86_64_32 reloc which may overflow at runtime; recompile with -fPIC
/home/anonymous/my_standalone_toolchain/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ./libvpx.a(subpel_variance_sse2.asm.o): requires dynamic R_X86_64_32 reloc which may overflow at runtime; recompile with -fPIC
clang38++: error: linker command failed with exit code 1 (use -v to see invocation)

But even I added -fPIC, the same error is seen.

Could anyone help me on this issue?

Thanks a lot!

Johann Koenig

unread,
Mar 15, 2017, 11:46:37 AM3/15/17
to webm-d...@webmproject.org
On Wed, Mar 15, 2017 at 1:51 AM, Dan Liang <redapp...@gmail.com> wrote:
> $NDK/build/tools/make_standalone_toolchain.py --arch x86_64

Unfortunately I don't have any x86_64 android devices to check this,
but a patch was upload a while ago to AOSP to try to address a build
issue:
https://android-review.googlesource.com/#/c/139090/

I'm not sure if this is the same issue you are seeing. The patch was
not accepted upstream because there was no explanation of how the fix
worked.

Johann Koenig

unread,
Mar 15, 2017, 12:22:46 PM3/15/17
to webm-d...@webmproject.org
On Wed, Mar 15, 2017 at 1:51 AM, Dan Liang <redapp...@gmail.com> wrote:
> So I modified the .mk files manually to add the flags:
> CFLAGS += -fPIE
> CXXFLAGS += -fPIE
> LDFLAGS += -fPIE -pie

You can also pass '--enable-pic' to configure

Dan Liang

unread,
Mar 15, 2017, 11:28:35 PM3/15/17
to WebM Discussion
Thank you Johann. With the option '--enable-pic', the PIC issue found in the linking stage has gone. But the PIE issue is still there when the command line vpxenc is run. Since there's no option of '--enable-pie' in configure script, I manually added the '-fPIE' option as I mentioned previously. Now the vpxenc can work well on the x86_64 Android Device(Android 7.0).

It seems x86 and x86_64 target requires this -fPIE option as I tested.
You could try with the x86_64 Android Emulator.

在 2017年3月16日星期四 UTC+8上午12:22:46,Johann写道:

Dan Liang

unread,
Mar 15, 2017, 11:40:48 PM3/15/17
to WebM Discussion
That patch was submitted two years ago by me when I tried to built the vp8 codecs with x86_64 SIMD optimizations in the libvpx contained in AOSP. As mediaserver/media.codec is running in 32b env, there was no real requirement to enable the 64b sw codecs, it was just an experiment. Would you like me to continue this job?

在 2017年3月15日星期三 UTC+8下午11:46:37,Johann写道:

Johann Koenig

unread,
Mar 16, 2017, 9:56:47 AM3/16/17
to webm-d...@webmproject.org
On Wed, Mar 15, 2017 at 8:40 PM, Dan Liang <redapp...@gmail.com> wrote:
> That patch was submitted two years ago by me when I tried to built the vp8
> codecs with x86_64 SIMD optimizations in the libvpx contained in AOSP. As
> mediaserver/media.codec is running in 32b env, there was no real requirement
> to enable the 64b sw codecs, it was just an experiment. Would you like me to
> continue this job?

Ah sorry! I totally missed that you were the author. If it's still
using 32bit internally, I don't think it's important to fix right now.
Reply all
Reply to author
Forward
0 new messages