You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HELP WANTED:Clang toolchain compile with -fopenmp cause so size increase nearly 400K #742
As descripted in title, the latest ndk r17 set clang as the default toolchain, the -fopenmp command cause shared library size increase as much as nearly 400Kb, but gcc in the previous version, the -fopenmp only cause increasing about 30Kb, what's the difference between gcc & clang?
int g[1024];
int main() {
int i;
#pragma omp parallel
for (i = 0; i < 1024; i ++)
g[i] = i*i;
return 0;
}
With OpenMP, executable from GCC is 40K, while the one from Clang is 380K. This seemed to have been worse with r16, where the Clang generated binary was ~800K.
There are far too many functions in the text section and symbol table with Clang than with GCC. I'll see why this is and if we can trim this down. If it helps in the meantime, adding '-Wl,--exclude-libs,libomp.a' reduces the binary to 350K. The savings are mostly from a smaller symbol table. The text section is still big.
Using -ffunction-sections when building the libomp runtime and passing -Wl,--gc-sections while linking (which, according to @DanAlbert, is passed by ndk-build and CMake by default) helps shave a further 100k from my test. With this change, the clang-build with openmp is ~250K, which is still higher than the 40K from gcc.
This is all I can think of from a black box perspective. I'll kick off an email to openmp-dev asking for their opinion.
I've attached libomp.a.zip for arm64 built with -ffunction-sections for experimentation. Just drop it into your NDK installation.
changed the title [-]Clang toolchain compile with -fopenmp cause so size increase nearly 400K[/-][+]HELP WANTED:Clang toolchain compile with -fopenmp cause so size increase nearly 400K[/+]on Jul 27, 2018
@pirama-arumuga-nainar After replace the libomp.a, clang still cause increase ~250K ,this is still inexplicable, which force me to revert to R14 with GCC, so ,I hope it will be resolved before NDK R18 released.
I hope it will be resolved before NDK R18 released.
If we find out that we're just building something wrong then that's possible, but if it's something that will require changes upstream then unfortunately that won't happen. It takes quite a bit of time to get changes made, merged to LLVM, pulled back to Android, tested, and then finally released.
Has anyone looked to see if the same size issues are present with prior NDKs? We've had openmp support for Clang for over a year but this bug was only opened about two weeks ago.
There's no upstream bug. We'd need steps to reproduce before reporting in upstream - so if we can reproduce for any Linux target, that'd be best. It'd also help us understand if this is an issue with how we're building for Android.
Isn't #742 (comment) a repro case? I'll check rq to see if this is still a problem on r21. I sort of wonder if the problem was actually just that gcc was using a shared openmp and we didn't have that for Clang until r21...
$ du -sh a.out
548K
$ strip a.out && du -sh a.out
468K
gold produces a 464K binary.
Adding -fvisibility=hidden -ffunction-sections -fdata-sections to C, CXX flags, and -Wl,--gc-sections,
the unstripped binary is 2.2M but the stripped binary is 344K.
Activity
cocodark commentedon Jul 17, 2018
@pirama-arumuga-nainar Any suggestions?
pirama-arumuga-nainar commentedon Jul 17, 2018
I am able to reproduce this with a simple case.
With OpenMP, executable from GCC is 40K, while the one from Clang is 380K. This seemed to have been worse with r16, where the Clang generated binary was ~800K.
There are far too many functions in the text section and symbol table with Clang than with GCC. I'll see why this is and if we can trim this down. If it helps in the meantime, adding '-Wl,--exclude-libs,libomp.a' reduces the binary to 350K. The savings are mostly from a smaller symbol table. The text section is still big.
cocodark commentedon Jul 18, 2018
@pirama-arumuga-nainar As Gcc will be removed in r18, this bug cause a lot trouble to us
pirama-arumuga-nainar commentedon Jul 18, 2018
Using -ffunction-sections when building the libomp runtime and passing -Wl,--gc-sections while linking (which, according to @DanAlbert, is passed by ndk-build and CMake by default) helps shave a further 100k from my test. With this change, the clang-build with openmp is ~250K, which is still higher than the 40K from gcc.
This is all I can think of from a black box perspective. I'll kick off an email to openmp-dev asking for their opinion.
I've attached libomp.a.zip for arm64 built with -ffunction-sections for experimentation. Just drop it into your NDK installation.
pirama-arumuga-nainar commentedon Jul 18, 2018
https://android-review.googlesource.com/c/toolchain/llvm_android/+/719087 passes ffunction-sections when building the runtimes. This should be a part of r19 or whenever the NDK clang gets updated past the one in r18.
cocodark commentedon Jul 27, 2018
@pirama-arumuga-nainar
Is there any progress?
[-]Clang toolchain compile with -fopenmp cause so size increase nearly 400K[/-][+]HELP WANTED:Clang toolchain compile with -fopenmp cause so size increase nearly 400K[/+]pirama-arumuga-nainar commentedon Jul 30, 2018
@cocodark did this help?
I have to ask upstream OpenMP developers about this - and for that I need to recreate my experiment with a newer gcc. I'll do that this week.
cocodark commentedon Jul 31, 2018
@pirama-arumuga-nainar After replace the libomp.a, clang still cause increase ~250K ,this is still inexplicable, which force me to revert to R14 with GCC, so ,I hope it will be resolved before NDK R18 released.
DanAlbert commentedon Jul 31, 2018
If we find out that we're just building something wrong then that's possible, but if it's something that will require changes upstream then unfortunately that won't happen. It takes quite a bit of time to get changes made, merged to LLVM, pulled back to Android, tested, and then finally released.
Has anyone looked to see if the same size issues are present with prior NDKs? We've had openmp support for Clang for over a year but this bug was only opened about two weeks ago.
DanAlbert commentedon Oct 17, 2018
As far as I know this has not been resolved upstream, so moving to r20.
2 remaining items
DanAlbert commentedon Sep 4, 2019
Still no changes upstream afaik.
I don't suppose the original problem was that the GCC build used for comparison was using a shared libomp whereas Clang was using a static one?
nickdesaulniers commentedon Sep 20, 2019
@DanAlbert what's the upstream bug link?
DanAlbert commentedon Sep 20, 2019
@pirama-arumuga-nainar might know. I've just been asking him iirc.
pirama-arumuga-nainar commentedon Sep 20, 2019
There's no upstream bug. We'd need steps to reproduce before reporting in upstream - so if we can reproduce for any Linux target, that'd be best. It'd also help us understand if this is an issue with how we're building for Android.
DanAlbert commentedon Sep 20, 2019
Isn't #742 (comment) a repro case? I'll check rq to see if this is still a problem on r21. I sort of wonder if the problem was actually just that gcc was using a shared openmp and we didn't have that for Clang until r21...
DanAlbert commentedon Sep 20, 2019
(no, we never had a shared omp runtime for gcc)
pirama-arumuga-nainar commentedon Sep 20, 2019
Huh? IIRC, when adding openmp runtimes for Clang, we added static openmp for compatibility with gcc.
DanAlbert commentedon Sep 20, 2019
Sorry, I mean't we never had a shared omp runtime. Caffeine hasn't made it to my blood stream yet.
DanAlbert commentedon Sep 20, 2019
I do still see a fairly significant increase in size when using openmp:
For the test case above:
without -fopenmp: 8.0K
with -fopenmp: 280K
Our openmp runtime doesn't seem to link properly on my debian machine. Pirama is looking...
pirama-arumuga-nainar commentedon Sep 23, 2019
The 8K number was slightly misleading because the
foo.cppfrom earlier turned out to be a no-op forgcc/libgomp.I looked at it briefly and filed an upstream bug. Here's the content from there for cross reference:
This was originally reported a while ago in the Android NDK bug tracker as #742.
Statically-linking libomp.a for a simple OpenMP hello world program, https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c, produces a 468K binary (after strip). gcc + libgomp.a, in comparison, produces a binary of size 128K.
I want a sanity check if this is expected behavior or if the runtime can be better organized for static linking.
Steps to reproduce:
Build OpenMP statically with:
-DLIBOMP_ENABLE_SHARED=OFF -DCMAKE_BUILD_TYPE=Releasegold produces a 464K binary.
Adding -fvisibility=hidden -ffunction-sections -fdata-sections to C, CXX flags, and -Wl,--gc-sections,
the unstripped binary is 2.2M but the stripped binary is 344K.
Bloaty [https://github.com/google/bloaty]:
Update git submodules