28

When I'm compiling Android 5.1.1, I get dozens of errors like this:

...
...
...
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43

and the make process finally fails:

clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libnativehelper.so' failed
make: *** [out/host/linux-x86/obj32/lib/libnativehelper.so] Error 1

I've tried building sources with and without clang, and with different versions of clang. But on newer branches, clang is a requirement and make doesn't start without it.

What might be wrong?

5 Answers 5

24

One should apply this patch to get the things working https://android-review.googlesource.com/#/c/223100/

Open build/core/clang/HOST_x86_common.mk file in your android source code directory with some editor add these lines, as mentioned in this link

For Android Lollipop or any earlier version, make sure to keep -no-integrated-as while applying this patch. Make sure the line continuations are proper(\ at the end of each line except the last line).

But, -no-integrated-as is removed in Marshmallow.

2
  • thanks for link to the patch, I used git cherry-pick and seems it works OK (the build is still in progress and it was only one of the faults I had to fix... waiting for the next one...)
    – Mixaz
    Oct 17, 2016 at 18:15
  • 2
    Please see the answer from @Rémi Cohen-Scali also: He mentioned to clear ccache and make clean build. Oct 23, 2016 at 2:09
24

It works to me:
in file /art/build/Android.common_build.mk, find out:

# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
  # By default, host builds use clang for better warnings.
  ART_HOST_CLANG := true
endif

change to :

# Host.
ART_HOST_CLANG := false
ifeq ($(WITHOUT_HOST_CLANG),false)
  # By default, host builds use clang for better warnings.
  ART_HOST_CLANG := true
endif

If it still not works,try this in your android root path: cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld

4
  • 1
    Makefile change is gold! great find Jul 22, 2016 at 17:50
  • FWIW, I had the same error while building libcxx and libcxxabi. Copying does not work for me (i have ".../ld not found (maybe ld is not installed), but soft-linking does (no idea why).
    – autra
    Sep 17, 2016 at 9:33
  • The cp command worked without needing to do any other messing around for me. Thanks! Apr 10, 2017 at 21:59
  • Works for me. This should be the selected answer
    – PC.
    Apr 13, 2017 at 11:25
4

Problems comes from an incompatible change in binutils: some section were added. Some build platform have the new binutils and android build tree have old one. The bug comes from clang invocation variables definition. These doesn't tell clang to use the provided build chain. Then clang uses the native build platform binutils (here /usr/bin/as instead the prebuilts provided as). Then the fix imply applying the patch pointed by mysticTot and then removing all binaries produced by the toolchain (according to where the error appears this could change but removing all STATIC_LIBRARIES/SHARED_LIBRARIES/EXECUTABLES etc dirs in out tree should do it). Also remove the ccache cache (as it stores .o) then rebuild. Fix provided by Ov3r1oad consisting in replacing the prebuilt toolchain ld by the native ld is not a solution, just a workaround and could be dangerous (mixing section number is not good). Hope it willl help.

3

As a hard workaround I just replaced prebuilt linker with soft link on /usr/bin/ld.gold . It described here: https://bbs.archlinux.org/viewtopic.php?id=209698 .

2
  • Works for me, thanks! (I'm building cm12.1, Lollipop, on Arch Linux) Mar 24, 2016 at 11:31
  • 1
    does not work on me : ubuntu 16.04 ,compile android 5.1.1_r6.
    – Ezio
    May 1, 2016 at 8:37
2

Are you building on Arch Linux? I have the same problem since today. My previous builds were 3 days ago and were all fine. Today all fail.

I see the admin upgraded some packages 2 days ago, especially these

[2016-03-16 15:29] [ALPM] upgraded glibc (2.22-3 -> 2.23-1)
[2016-03-16 15:29] [ALPM] upgraded lib32-glibc (2.22-3.1 -> 2.23-1)
[2016-03-16 15:29] [ALPM] upgraded lib32-gcc-libs (5.3.0-3 -> 5.3.0-5)
[2016-03-16 15:29] [ALPM] upgraded gcc-libs-multilib (5.3.0-3 -> 5.3.0-5)
[2016-03-16 15:29] [ALPM] upgraded libcap (2.24-2 -> 2.25-1)
[2016-03-16 15:29] [ALPM] upgraded binutils (2.25.1-3 -> 2.26-3)
[2016-03-16 15:29] [ALPM] upgraded gcc-multilib (5.3.0-3 -> 5.3.0-5)
[2016-03-16 15:29] [ALPM] upgraded libcups (2.1.2-3 -> 2.1.3-1)

binutils could be the culprit? (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808206)

also see https://groups.google.com/d/msg/android-x86/U1XpL0tUpqw/y4W3wRCdJgAJ ...

3
  • So did you fix it somehow? I have the same issue with Lollipop on Arch recently.
    – Ov3r1oad
    Mar 18, 2016 at 14:39
  • I'm stumbled upon this debian bugreport too: This would happen with gcc-5 and with gcc-4.9. Downgrading libc6 would fix it. After some fiddling I realized that upgrading to binutils =2.25.90.20151209-1 (currently latest in sid) fixes it. I.e. with the latest libc6 and the latest binutils packages things work. My build system is an ubuntu 16.10 container on an arch linux host and it is not using one of the affected versions. But the Android build system is picking his linker from its own prebuilt directory (gcc 4.6, glibc 2.11). So: how can we use the system-wide build tools with Android? Mar 21, 2016 at 6:25
  • As I understand the idea, using docker can help with setting build time environment: github.com/justfortherec/fairphone2-build-env I haven't used it myself though, but probably I'll give it a try because of endless number of faults building FP2 Android from source, which was supposed to be a flawless process. But I'm not surprised since I already had problems like that building CM on Arch Linux, then I understood that next time I'll build in an recommended environment (Ubuntu), but it appears to be not enough. So is the docker our future? ;)
    – Mixaz
    Oct 17, 2016 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.