-
Notifications
You must be signed in to change notification settings - Fork 257
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
lld + objcopy/strip breaks relro #843
Comments
Thanks for the diagnosis! @stephenhines should we be moving to llvm-objcopy/llvm-strip? Are they command line compatible? I don't think we can outright remove binutils strip in a timely manner since the gradle plugin expects it to exist at its current location and to have its current interface, but if we can install llvm-strip in its place and it Just Works then that's probably our best option. |
i know |
Weird, I only just got the email notification of Dan's mention. I do think we should be asking users to switch. I don't believe these tools are fully command-line compatible, but we should be able to fix any egregious missing parts. Just like switching to Clang, this is going to involve some transition time, but it's probably better to start early. |
Sounds like it's reasonable for us to start moving. I'm not brave enough to clobber the binutils tools with the LLVM tools in r19 since beta 1 has shipped, but we'll note the upcoming transition in the changelog at the very least and I'll think about moving ndk-build/cmake in beta 2, but probably r20. |
The issue I found was in https://b.corp.google.com/issues/80093681
…On Mon, Nov 12, 2018 at 12:49 PM Elliott Hughes ***@***.***> wrote:
i know strip -o caused some trouble. @chih-hung
<https://github.com/chih-hung> has been switching AOSP over, so he'll
know how much of this (if any) is already fixed...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#843 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQ5CvAfDgEcx_Wq_YSHn0E7Nq-GwQ1HPks5uud7WgaJpZM4YaMHS>
.
|
Unfortunately llvm-objcopy is not fully command-line compatible with objcopy. |
It would be great to include llvm-objcopy and llvm-strip in r19 (and leave objcopy and strip there as well), and encourage users to use that if they choose to use lld (at least the ones who use custom build systems like us can start to transition) |
Good to know. This isn't as much of a problem as it is for strip since it isn't used by gradle (it's used indirectly via ndk-build, but we can fix our use of it easily enough). Given that it's a less frequently used tool (at least in my experience), I'm hoping this won't be a big issue. Depending on the differences, we may be able to fix them. |
Looks like this is already done, btw. It's in my build of master anyway and I'm pretty sure that's still the same version of the Clang tools as we have in r19 beta 1. |
But it also looks like Definitely something that will need to be resolved before llvm-strip is viable. |
On Tue, Nov 13, 2018 at 4:25 PM Dan Albert ***@***.***> wrote:
But it also looks like llvm-strip does not do as well at actually
producing small binaries. At least with --strip-unneeded (which is what
ndk-build uses by default), binaries stripped by llvm-strip are larger than
those stripped by binutils strip. For lld linked binaries, which have
*much* larger unstripped intermediates, this is significant (an
executable with an empty main is ~150KB instead of 12KB).
Dan, do you have some examples to show that lld produced much larger
binaries?
Maybe we used different flags, last time I checked lld outputs have similar
size.
I have counted some AOSP files at go/USE_CLANG_LLD.
…-- chh
Definitely something that will need to be resolved before llvm-strip is
viable.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#843 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQ5CvKzD8zvWM4hFcyGtLE-nmbBpAs9Rks5uu2LwgaJpZM4YaMHS>
.
|
The platform passes this flag to lld for arm64, but it doesn't happen automatically with the NDK:
|
@chih-hung: I'd filed http://b/119522392, which I just duped into http://b/79162664 (apparently this was known and actually had been assigned to me for feedback and I missed the email).
That's the problem then. Adding these "defaults" to the platcform build system does nothing to help the NDK. The NDK doesn't have control over all the build systems that use it, so this needs to be fixed either in the Clang driver or LLD itself. I can add a note to our build system maintainers doc for now, but this will need to be fixed before it becomes the NDK's default. |
The lld fix mentioned above is in the compiler that we'll have for r21, so I need to re-investigate the other issues with strip. |
LLD and ... but Gradle will need to be fixed separately since it performs its own stripping. AGP version 3.6+ (presumably, I sent the patch but it isn't submitted yet) will be needed to fix this for most users. |
Using binutils strip with lld breaks RelRO. Switch to llvm-strip to avoid this issue. This doesn't affect Gradle users because the Android Gradle Plugin performs its own stripping. Gradle users will need to upgrade to AGP 3.6 or newer (the change to fix the plugin has not yet been submitted, but is in review). Test: ./checkbuild.py && ./run_tests.py Test: Compare sizes of all test outputs before and after, no changes Bug: android/ndk#843 Change-Id: I6710d0bc5dbbdc53bc3a66acccc6ba3d9c9a00f6
The NDK side of this is fixed, so moving out of the r21 bucket. |
I'm seeing incomplete stripping happening again. Stripping a binary with
About 100kb larger when llvm-strip is used (a 30% increase compared to GNU strip). |
However, it looks like |
Also note that From llvm-strip:
|
Gradle side of this is submitted now. It'll be in 4.0. |
The ndk-build/CMake change for this got reverted due to #1083, and unfortunately I forgot to revert the revert before r21 was cut. Changing those tools out so late in the release cycle will effectively mean we need to restart the beta process, and I don't think we should be delaying r21 that much longer. ndk-build and CMake will be fixed in r22, and llvm-strip is at least fixed to actually strip as much as binutils strip is now. I should also mention that the NDK side of this change doesn't affect Gradle builds. Those will need AGP 4.0 regardless. The lack of this fix in r21 only affects ndk-build and CMake users that are not using Gradle. |
This reverts commit 9f292c2. Test: ./checkbuild.py && ./run_tests.py Bug: android/ndk#843 Change-Id: Iefb6108bc61ed24cd911860b1f75b266574ddd2d
update Android Gradle plugin to 4.1.0 and Gradle to 6.5, with no change of targetSdkVersion Android Gradle plugin 4.0+ is required to avoid strip bug (android/ndk#843)
NDK version: r18b
Architecture: tested on aarch64 (probably others as well)
Host OS: tested on Linux (probably others as well)
This bug is most probably caused by https://sourceware.org/bugzilla/show_bug.cgi?id=22829
To reproduce, compile an executable (or shared library) with lld and relro enabled then strip or objcopy it. This last step will disable relro by deleting the GNU_RELRO segment.
Possible solutions:
Example file and command to reproduce:
The text was updated successfully, but these errors were encountered: