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

[FR] Support for gold linker for Gradle & CMake #1288

Closed
HaiPhan2002 opened this issue Jun 23, 2020 · 7 comments
Closed

[FR] Support for gold linker for Gradle & CMake #1288

HaiPhan2002 opened this issue Jun 23, 2020 · 7 comments

Comments

@HaiPhan2002
Copy link

When I try to use gold linker to test my sample project, I figure out that Gradle doesn't have an option to do select gold linker.
The available option is '-DANDROID_LD=lld', otherwise, default linker (bfd) will be used.
The build system is Gradle & Cmake.

The suggestion is that have one more option is '-DANDROID_LD=gold'. The solution is simple as we add the code below to android.toolchain.cmake

if(ANDROID_LD STREQUAL lld)
  list(APPEND ANDROID_LINKER_FLAGS -fuse-ld=lld)
else(ANDROID_LD STREQUAL gold)
  list(APPEND ANDROID_LINKER_FLAGS -fuse-ld=gold)
endif()

I have tried to add set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold") to CMakeList.txt but it doesn't effect.
I guess the linker option is clear when android.toolchain.cmake invoked.

And why I would like to use Gold linker ? because Firebase CrashAnalytics has trouble with dSym parser when the linker is lld. They are working on this issue but have not ETA for it. And for some reason, my team consider to use gold linker until Firebase has the fix for their tool.

@DanAlbert
Copy link
Member

The first release this could possibly ship in is also the one where gold is deprecated, so I don't think there's much point in fixing this.

because Firebase CrashAnalytics has trouble with dSym parser when the linker is lld. They are working on this issue but have not ETA for it.

Would love a pointer to that bug. We can help chase it.

In the mean time, what's the issue with using bfd for aarch64?

@HaiPhan2002
Copy link
Author

HaiPhan2002 commented Jun 23, 2020

Hi, thanks for your quick reply.
Getting your point. Anyway, we can modify the change in the local ndk.

Regarding the firebase issues, Here is the first issue.

The second issue is the dSym missing function instruction so we don't see anything in Firebase console. I will send the detail later cause it is the email from me to Firebase team.

As I recall, we have the linker problem with bfd - linker can not generate SO file - a long time ago (1 - 2 years - with ndk below r17 and -g option) so we switch to gold and lld later.
Will recheck with bfd on ndk-21c tomorrow next week.

@enh-google
Copy link
Collaborator

there's a comment on that bug (firebase/firebase-android-sdk#1588 (comment)) claiming that lld in r21d does work:

2: use most recent NDK r21d and set linker flag -fuse-ld=lld

hopefully they're right!

@DanAlbert
Copy link
Member

DanAlbert commented Jun 23, 2020

Reading through that bug, it sounds like this being a gold or LLD issue is just incidental, and that firebase is prone to crashing on whichever produces that larger output? No one in that bug is reporting this as being an issue with LLD (except maybe one, but I can't tell if they're saying LLD improved it or made it worse), but in fact they report switching to LLD is a possible fix.

@HaiPhan2002
Copy link
Author

Recheck through that bug and have 2 guys confirm it works with r21d - lld linker.
Forwarding the email discussing with Firebase team about stack trace missing to @DanAlbert , and asking them to check my issue if it still happens or not, hopefully everything works fine.
In parallel, will recheck with ndk 21d.

@HaiPhan2002
Copy link
Author

After rechecking with default linker (bfd?) on arm64-v8a, everything is work well.
The reason that we use GOLD linker & LLD latter is the size of SO file become bigger around 10 MB as we can not pass the option --icf=all to default linker.
One more thing, seem the default linker of arm64-v8a is bfd, other architectures (arm, x86, x86-64) is gold linker? (r21c & r21d - Windows is same ).
Please let me know if have something is not right.

@DanAlbert
Copy link
Member

That's correct.

Closing this since I don't think we have anything to do here. Keeping an eye on the firebase bug though.

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

No branches or pull requests

3 participants