Skip to content

switch aarch64 to ld.gold #556

Closed
Closed

Description

@nsabovic

When using NDK r16 Beta 2 (16.0.4414007-beta2), compiling with clang still uses ld.bfd on aarch64 (aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld is aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.bfd).

This makes -flto fail, but only on ARM64, because the linker does not recognize LLVM bitcode files. LTO works just fine on arm and x86.

Activity

  1. DanAlbert commented on Oct 29, 2017

    @DanAlbert
    Contributor

    Add -fuse-ld=gold to your ldflags.

    We should probably change the default at this point though. It's been the default in the platform for quite a while now.

  2. added this to the r17 milestone on Oct 29, 2017
  3. self-assigned this
    on Oct 29, 2017
  4. nsabovic commented on Nov 1, 2017

    @nsabovic
    Author

    That worked, thanks so much!

    I added -Wl,-flto=gold to CMAKE_SHARED_LINKER_FLAGS_RELEASE and it fixed the arm64 build.

    FYI, adding that flag breaks the x86 build (which works fine without it) with a bunch of errors like this one:

    ~/Library/Android/sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/darwin-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: ../../../../src/main/jniLibs/x86/Release/libippicv.a(jmp_icvippiDFTGetSize_C_32fc_as.s.o): relocation R_386_GOTOFF against preemptible symbol icv_ippJumpIndexForMergedLibs cannot be used when making a shared object
    
  5. DanAlbert commented on Nov 1, 2017

    @DanAlbert
    Contributor

    Really? x86 already defaults to gold.

  6. DanAlbert commented on Nov 1, 2017

    @DanAlbert
    Contributor

    Oh, I see a couple problems.

    First, I gave you the wrong flag. It's -fuse-ld=gold. Second, it's -fuse-ld=gold, not -Wl,-fuse-ld=gold. -Wl flags are passed to the linker. If you've reached the linker, it's too late to choose which linker you want :) -f does very different things to the linker.

  7. nsabovic commented on Nov 3, 2017

    @nsabovic
    Author

    Now that worked perfectly! Thanks again!

    If only Clang's documentation did not look like a Siberian tundra—the flag is listed in there, but not what it does :(

    Should I close this?

  8. DanAlbert commented on Nov 3, 2017

    @DanAlbert
    Contributor

    No, I'm going to leave it open to track switching the default. Glad to hear that worked for you though.

  9. DanAlbert commented on Nov 3, 2017

    @DanAlbert
    Contributor

    BTW, for a lot of Clang flags you can actually find pretty good documentation in the GCC docs. A fortunate side effect of Clang trying to maintain command line compatibility with GCC (though probably also a reason Clang's docs aren't as thorough as they ought to be).

  10. nsabovic commented on Nov 3, 2017

    @nsabovic
    Author

    Thanks, and you're right, it's well documented on the gcc side.

  11. changed the title [-]ARM64 still uses ld.bfd as main linker with clang, breaks LTO[/-] [+]switch aarch64 to ld.gold[/+] on Jan 29, 2018
  12. DanAlbert commented on Jan 29, 2018

    @DanAlbert
    Contributor

    This doesn't actually block LTO any more. The latest Clang LTO works with bfd as well.

  13. modified the milestones: r17, r18 on Jan 29, 2018
  14. rprichard commented on Jan 29, 2018

    @rprichard
    Contributor

    This doesn't actually block LTO any more. The latest Clang LTO works with bfd as well.

    Is this true on Windows, too? I'm currently seeing an LLVMgold.dll: error loading plugin error with the bfd linker. To fix that, I have to enable Gold (using -fuse-ld=gold.exe, not -fuse-ld=gold).

  15. DanAlbert commented on Jan 29, 2018

    @DanAlbert
    Contributor

    Ugh, that's frustrating. Unfortunately this is a no-go for r17 either way because of https://issuetracker.google.com/70838247.

  16. DanAlbert commented on Jan 29, 2018

    @DanAlbert
    Contributor

    iirc I needed to fix gold to do the right thing when searching for LLVMgold (since Windows doesn't use rpath and by default only searches the executable's directory). Maybe we just need the same thing for bfd and can get that in time for r17 beta 2.

  17. rprichard commented on Jan 29, 2018

    @rprichard
    Contributor

    The Clang driver is passing an absolute path to LLVMgold.dll to ld.bfd.exe.

    I see that LTO works on 32-bit Windows, but not 64-bit Windows. I also see that LLVMgold.dll is provided both as part of the GCC toolchain and as part of the LLVM toolchain. For 32-bit Windows, the copy provided with the GCC toolchain is the wrong architecture -- it's a 64-bit binary.

  18. modified the milestones: r18, unplanned on May 14, 2018
  19. DanAlbert commented on May 14, 2018

    @DanAlbert
    Contributor

    Given that we're now shipping lld, I'm guessing this won't ever happen and we'll just go straight to LLD.

  20. DanAlbert commented on Oct 19, 2018

    @DanAlbert
    Contributor

    Closing in favor of lld.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions