Relocations in generic ELF (EM: 62)

7,507 views
Skip to first unread message

Chris Foster

unread,
Jan 25, 2017, 10:32:05 AM1/25/17
to android-ndk
Hi everyone,

I'm trying to build a static library using a standalone toolchain for a project that has its own build process, which I then wrap with a C++ library and expose to Android (compiled with ndk-build). However, on the ndk-build step I receive the following error:

 jni /Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/ndk-build                    
[arm64-v8a] Compile++      : wrapper <= wrapper.cpp
In file included from /Users/chrisfosterelli/workspace/android/jni/wrapper.cpp:9:
In file included from ../prebuild/include/valhalla/meili/universal_cost.h:7:
In file included from ../prebuild/include/valhalla/sif/dynamiccost.h:4:
In file included from ../prebuild/include/valhalla/baldr/directededge.h:5:
../prebuild/include/valhalla/baldr/graphconstants.h:432:11: warning: 21 enumeration values not handled in switch: 'kRoad', 'kRamp', 'kTurnChannel'... [-Wswitch]
 
switch (use) {
         
^
1 warning generated.
[arm64-v8a] SharedLibrary  : libwrapper.so
/Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /Users/chrisfosterelli/workspace/android/jni/../prebuild/libvalhalla_meili.a(libvalhalla_meili_la-map_matcher_factory.o): Relocations in generic ELF (EM: 62)
[...above message repeated many times...]
/Users/chrisfosterelli/workspace/android/jni/../prebuild/libvalhalla_meili.a: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/chrisfosterelli/workspace/android/obj/local/arm64-v8a/libwrapper.so] Error 1
➜  jni ls /Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/

This error indicates, as far as I can tell, that I'm trying to mix and match binaries compiled for different architectures. However, from what I can tell the library is the correct architecture:

root@eacbdb1c0e46:/meili/meili2/newtest# ar x libvalhalla_meili.a
root@eacbdb1c0e46
:/meili/meili2/newtest# file libvalhalla_meili_la-map_matcher_factory.o
libvalhalla_meili_la
-map_matcher_factory.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped
root@eacbdb1c0e46
:/meili/meili2/newtest#

FWIW, these are my current Application.mk and Android.mk files:

APP_STL := c++_static
APP_CPPFLAGS := -frtti -std=gnu++11 -D_GLIBCXX_USE_C99
APP_CPPFLAGS += -fexceptions
NDK_TOOLCHAIN_VERSION := clang
APP_LDFLAGS := -latomic
APP_PLATFORM := android-21
APP_ABI := arm64-v8a

LOCAL_PATH := $(call my-dir)

# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := libvalhalla_meili
LOCAL_SRC_FILES := ../prebuild/libvalhalla_meili.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)

# wrapper info
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += ../prebuild/include
LOCAL_MODULE    := wrapper
LOCAL_SRC_FILES := wrapper.cpp
LOCAL_STATIC_LIBRARIES := libvalhalla_meili
include $(BUILD_SHARED_LIBRARY)

Any ideas how to resolve this? I've tried a number of things but all of them lead to more (more obscure) errors, so I'm hoping someone here can point me in the correct direction!

Dan Albert

unread,
Jan 25, 2017, 2:25:24 PM1/25/17
to android-ndk
"EM: 62" does mean x86_64: https://android.googlesource.com/platform/bionic/+/49f525c47bd383cd6a87db8f067cddb3ab620d17/libc/kernel/uapi/linux/elf-em.h#47

One guess: ar has some pretty interesting behaviors. It's possible that there are actually two libvalhalla_meili_la-map_matcher_factory.o files in libvalhalla_meili.a. I'd check for that.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/17c7e27d-e77d-4b76-b748-0f00a7a863f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Foster

unread,
Jan 25, 2017, 4:22:58 PM1/25/17
to android-ndk
Hi Dan,

Thanks for the response! I was trying for ages to dig out what EM: 62 is, so thanks for clarifying. That'll narrow it down a bit.
Do you know how I can check if libvalhalla_meili.a has two versions of the ".o" file? I tried using nm to verify:

root@eacbdb1c0e46:/meili/meili2/newtest# nm -C libvalhalla_meili.a | grep "\.o"
libvalhalla_meili_la
-universal_cost.o:
libvalhalla_meili_la
-routing.o:
libvalhalla_meili_la
-candidate_search.o:
libvalhalla_meili_la
-map_matching.o:
libvalhalla_meili_la
-geojson_reader.o:
libvalhalla_meili_la
-map_matcher.o:
libvalhalla_meili_la
-map_matcher_factory.o:
libvalhalla_meili_la
-match_route.o:
libvalhalla_meili_la
-traffic_segment_matcher.o:
root@eacbdb1c0e46
:/meili/meili2/newtest#

But that also seems to suggest only a single version as well. 
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

Dan Albert

unread,
Jan 25, 2017, 5:21:10 PM1/25/17
to android-ndk
It's possible that nm is only considering the first occurrence of an archive. Might try `ar tv libvalhalla_meili.a | grep '\.o'`

Another possibility is that the problem is the .a itself rather than the .o files in it. .a files get an index for all the symbols in them to speed up linker processing of them (this is what ranlib does, but it's also built in to gnu ar). You said you were using a standalone toolchain, but it's possible that the build system you were using it with (some autoconf thing I assume) was using raw `ar` (your system's) instead of the one from the cross-compiling toolchain. It's possible that doing that would end up writing some architecture specific stuff (x86_64 stuff to match your system) to the index. Pure speculation, but seems plausible...

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Chris Foster

unread,
Feb 2, 2017, 12:31:30 PM2/2/17
to android-ndk
I wanted to follow up on this, although I have to say the answer is a bit silly :)

Apparently the build process had created two library files. The one that I inspected was, of course, ARM64. However the one that actually copied to the Android device was x86. So, the error message was correct and so was the library file, but there was more than one file involved. Lesson learned: make sure I am checking the library that is actually going into the ndk build! 

Thank you for the help Dan! Your insight was useful in tracking this down.
Reply all
Reply to author
Forward
0 new messages