ndk
ndk copied to clipboard
NDK best practices documentation
https://github.com/android-ndk/ndk/issues/748#issuecomment-411862124 had this:
I agree with the first suggestion to use the -f*-sections only for the static library.
As for the defaults, I don't think -fdata-sections is universally useful. If a function refers to multiple global data, each global needs its own section start address. Without -fdata-sections, there'd just be a reference to the data section and two offsets into it. https://stackoverflow.com/a/29951897 has a more detailed explanation. However, the flag is useful or a wash for libc++ since it has few, if any, global data.
So -ffunction-sections, while ensuring that --gc-sections is passed to the linker, seems like a good default.
OTOH, I could also make the case for not setting either and leaving the user to consider the trade-offs and opt into whatever behavior they want. Granted there's greater potential benefit (in terms of size) with setting this flag and a smaller potential disadvantage (in terms of execution speed).
I guess it all comes down to informed choice - if there's a best-practices guide for the NDK, this trade-off should be mentioned there.
we should probably have a best practices doc, and add stuff like this.
https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md covers some aspects of this, but we can definitely do better.