Regd LLVM BOLT Optimization

350 views
Skip to first unread message

Priyanka Bose

unread,
Aug 1, 2019, 5:30:14 AM8/1/19
to android-llvm
Hi,

I am using latest AOSP master code base in our development system.
We want to experiment as to how we can use the BOLT optimization from LLVM for some performance analysis with Apps

We referred to wiki from Facebook speaking of Bolt and how to integrate but I am bit confused on few areas:
1. It speaks to use the perf.data generated after running our application with llvm-bolt command .
2. Based on the perf.data  report generated we plan to optimize the libc.so , so we use something like :
=>  llvm-bolt libc.so -o libc.bolt -data=perf.fdata ....

3. So now if we want to use this optimized libc.so bolt lib, is there anyway currently android aosp framework supports or any
suggestions on how we can integrate in complete aosp build after we have this bolt optimized binary ?

As we have seen in PGO , we have the framework to use the prof.data file with the respective modules while compiling the aosp build 
by editing its corresponding Android.bp files . 
So is there any way we can use the bolt optimized modules in the aosp builds ?

Best Regards
Priyanka

Priyanka Bose

unread,
Aug 3, 2019, 11:02:53 AM8/3/19
to android-llvm
Can anyone have suggestion or is there any support in the aosp framework now to use the llvm bolt optimized binary ?

Best Regards
Priyanka

Pirama Arumuga Nainar

unread,
Aug 5, 2019, 12:25:23 AM8/5/19
to Priyanka Bose, android-llvm
There is no support currently.  One possible way to implement the build support would be similar to PGO: the instrumentation/profile-collection mode will add '--emit-relocs' to the linker flags, and the regular build will invoke llvm-bolt post-link and use the perf data.  This post-link step can be performed in soong's TransformObjToDynamicBinary.

--
You received this message because you are subscribed to the Google Groups "android-llvm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-llvm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-llvm/9141e00e-6500-43f9-bf13-820cab258871%40googlegroups.com.

Priyanka Bose

unread,
Aug 9, 2019, 1:56:22 AM8/9/19
to android-llvm
Thanks for the info !

So I was using now the linker flag : "Wl,--emit-relocs"  in the instrumented mode to compile
But the build fails with the llvm clang toolchain :
============================
FAILED: out/soong/.intermediates/bionic/libc/libc/android_x86_core_shared/libc.so prebuilts/clang/host/linux-x86/clang-4691093/bin/clang++ 
.....
.....
-Wl,--no-undefined -Wl,--hash-style=gnu -Wl,--emit-relocs -Wl,--hash-style=both -m32 -Wl,--version-script,bionic/libc/libc.x86.map                                                                                           
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/x86_64-linux-android/bin/ld: internal error in do_layout, at /buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.27/gold/object.cc:1821                                                 
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)  
==============================

Does the clang based llvm compiler do not support relocation mode ?
I am using android clang prebuilts : "clang-4691093" ...

Best Regards
Priyanka

To unsubscribe from this group and stop receiving emails from it, send an email to androi...@googlegroups.com.

Pirama Arumuga Nainar

unread,
Aug 9, 2019, 2:26:25 PM8/9/19
to Priyanka Bose, android-llvm
This is a linker flag and both ld.gold and lld support it.  If there's an issue with how LLVM emits relocations, my suggestion would be to try a newer Clang, and also to try lld instead of gold.

To unsubscribe from this group and stop receiving emails from it, send an email to android-llvm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-llvm/81a8ffca-1d08-481c-8d06-e1e1ebbc2beb%40googlegroups.com.

Priyanka Bose

unread,
Aug 20, 2019, 1:59:43 AM8/20/19
to android-llvm
Hi,

Unfortunately it did not work out.
I used now the latest AOSP build master (Android R) , clang ,though it compiled successfully the libc module with the  "-Wl,--emit-relocs", but when i check the section headers of the libc.so generated , I do not see .rela.text section .
===========
[310/318] prebuilts/clang/host/linux-x86/clang-r353983d/bin/clang++  @out/soong/.intermediates/bionic/libc/libc/android_x86_x86_64_core_shared_10000/unstripped/libc.so.rsp   -o out/soong/.intermediates/bionic/libc/libc/android_x86_x86_64_core_shared_10000/unstripped/libc.so -nostdlib -Wl,--gc-sections -shared -Wl,-soname,libc.so -target i686-linux-android -Bprebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/x86_64-linux-android/bin -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -fuse-ld=lld -Wl,--pack-dyn-relocs=none -Wl,--no-undefined -Wl,--hash-style=gnu -Wl,-z,muldefs -Wl,--emit-relocs -Wl,--hash-style=both -m32 -Wl,--version-script,out/soong/.intermediates/bionic/libc/libc/android_x86_x86_64_core_shared_10000/gen/stub.map
======================

So it looks like even with the latest clang , though the builds passed but there was no relocation section in the generated binary.

Regards,
Priyanka

Pirama Arumuga Nainar

unread,
Aug 28, 2019, 6:34:14 PM8/28/19
to Priyanka Bose, android-llvm
Can you try a different library than libc?  It's possible that bionic does not need any relocations.

Android also uses packed relocations (see build/soong/cc/linker.go: -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags).  Can you try without these flags?  It is also possible that the linker support for --emit-relocs doesn't handle packed relocations.

Whether BOLT can read/support for Android relocations must be confirmed as well.

Thanks,
-Pirama

To unsubscribe from this group and stop receiving emails from it, send an email to android-llvm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-llvm/96cc195b-7e7b-49e9-9331-7201ab4ea1b6%40googlegroups.com.

Tranquilizing Smoke

unread,
Aug 28, 2019, 6:40:17 PM8/28/19
to android-llvm

Tranquilizing Smoke

unread,
Aug 28, 2019, 6:40:30 PM8/28/19
to android-llvm
El jueves, 1 de agosto de 2019, 4:30:14 (UTC-5), Priyanka Bose escribió:
Reply all
Reply to author
Forward
0 new messages