Over the years, there have been many who have wanted to compile the Android platform with the Snapdragon LLVM Compiler, which has several performance enhancements for Snapdragon chipsets, such as improved Krait targeting and enhanced auto-vectorization for the NEON SIMD. With Qualcomm's release of Android Nougat repos, it is now possible to compile target modules with their optimized compiler. Please see the commits in the following repository for more information: https://source.codeaurora.org/quic/la/platform/build/log/?h=LA.BF64.1.2....
In order to use the Qualcomm Compiler to build Android for Snapdragon chipsets, please follow the steps below. Please note that Darwin (Mac OS X) is not supported at this time.
1. Download the Qualcomm LLVM Compiler here: https://developer.qualcomm.com/download/sdllvm/snapdragon-llvm-compiler-...
2. Extract Snapdragon-llvm-3.8.4-toolchain.tar.gz
3. Move toolchains\llvm-Snapdragon_LLVM_for_Android_3.8\prebuilt\linux-x86_64 to prebuilts/clang/linux-x86/host/sdclang-3.8 within your Android build environment.
4. Add the following lines to your device's BoardConfig:
ifneq ($(HOST_OS),darwin)
SDCLANG := true
SDCLANG_PATH := prebuilts/clang/linux-x86/host/sdclang-3.8/bin
SDCLANG_LTO_DEFS := device/qcom/common/sdllvm-lto-defs.mk
endif
5. Compile Android
Please post your results here. Many have reported improved scrolling and animation frame rates.
How to solve this error:
Segmentation fault (core dumped) clang++: error: linker command failed due to signal
It doesn't look like you're using the Snapdragon LLVM toolchain.
Please send the version number from running the following command (from your ouput log):
prebuilts/misc/linux-x86/ccache/ccache prebuilts/clang/host/linux-x86/clang-2690385/bin/clang++ -v
Hi,
I tried to set it up as you explained but every time I try to compile I face this error:
Cache is wiped and I guess I didn't do any mistakes setting it up. Thus I don't know what I'm doin' wrong. I'd appreciate any recommendation. Thanks a lot!
Sincerely
Nico
Hi Nico,
The static library file 'libatomic.a' should be part of the Android tree in the prebuilts directory and the path should be expanded similar to what is done for libgcc.a in your command line --> prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/7.0.0/libgcc.a.
Please run your failed command line and add the '-v' flag and send us the output. Run the command from the build root. like this:
cd /home/nico/beanstalk
/bin/bash -c "/usr/bin/ccache prebuilts/clang/linux-x86/host/sdclang-3.8/bin/clang++ -Wno-vectorizer-no-neon -nostdlib -Wl,-soname,libdl.so -Wl,--gc-sections -shared -L/home/nico/beanstalk/out/target/product/pme/obj/lib /home/nico/beanstalk/out/target/product/pme/obj/lib/crtbegin_so.o /home/nico/beanstalk/out/target/product/pme/obj/SHARED_LIBRARIES/libdl_intermediates/libdl.o -Wl,--whole-archive -Wl,--no-whole-archive /home/nico/beanstalk/out/target/product/pme/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a libatomic.a prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/7.0.0/libgcc.a -o /home/nico/beanstalk/out/target/product/pme/obj/SHARED_LIBRARIES/libdl_intermediates/LINKED/libdl.so -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,-maarch64linux -Wl,--hash-style=gnu -Wl,--fix-cortex-a53-843419 -fuse-ld=gold -Wl,--icf=safe -Wl,--no-undefined-version -Wl,--allow-shlib-undefined -target aarch64-linux-android -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -Wl,--exclude-libs=libgcc.a -Wl,--version-script=bionic/libdl/libdl.arm64.map /home/nico/beanstalk/out/target/product/pme/obj/lib/crtend_so.o -v"
Thanks, Paul
Thanks a lot for the reply. That's my output:
I hope it'll help :)
I checked a couple of recent builds and the full path to libatomic.a is always present in the link line.
And, I see that the full path is there in the earlier post on this thread on Sat, 2017-01-14 12:48.
Here's the path it shows:
prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.4/libatomic.a
Hi there! So I'm trying to build LOS with sdClang. I've successfully built a rom with sdClang enabled, but it seems in LOS, it keeps failing. The error starts here:
Hi jhayzt,
The "Exec format error" typically means that the host OS doesn't recognize or is incompatible with the binary format of the executable, which is "prebuilts/clang/linux-x86/host/sdclang-3.8/bin/clang".
You should be running on a Ubuntu OS with a version of 10.04 or later.
Do the following from your host build machine and post here:
Paul
Hey there pstrong!
First of all, thanks for replying. Here are the details you need:
I am building android 8.0 for msm8996 this is the log when full build is done
Hi jk.menon,
Please provide your build steps/recipe so we can debug your build issue...
Thanks, Paul
Hi paul,
Thanks for the response,
First of all my host is ubuntu 16.04 xenial and i was able to build 7.1 for the same chip from this host ,so i guess there is no problem with the environment setup .
openjdk version is "1.8.0_151"
These are the steps that i followed:
$ export PATH=~/bin:$PATH
i have downloaded the source code from here https://wiki.codeaurora.org/xwiki/bin/QAEP/release
repo init -u git://codeaurora.org/platform/manifest.git -b release -m LA.UM.6.5.r1-04000-8x96.0.xml --repo url=git://codeaurora.org/tools/repo.git
repo sync
source build/envsetup.h
lunch msm8996-userdebug
make -j4
i am not sure if its something related to setting up the path to sdclang compiler ,
it would be great if you could figure out the issue.
Thanks,
Jayakrishnan
I have THE SAME EXACT PROBLEM as you. And I've been building for 7.1 too (just Snapdragon Camera for my own purposes) without problems. It turns out that this time following instructions is not enough.
Hi ,
For me the issue of sdclangvars () got disappeared when i commented out the set sdclang vars() in global.go file , but i am getting another issue : ninja: no work to do.
SDClang now expects a json such as this one in 8.0 https://github.com/OnePlusOSS/android_vendor_qcom_cobalt/blob/oneplus/QC...
You're correct that the BT file doesn't exist in OSS. Try this commit: https://github.com/AOSPA/android_system_bt/commit/c78c34cdbd6d7163ad9345...
@pstrong, I see that 4.0 breaks certain functionality such as camera and I suspect that is why 3.9 is used by vendors such as OnePlus. Is 4.0 expected to be fixed for full builds soon?
If you are building Android O with vendor/qcom/proprietary (also known as the BSP), you do not need to follow the instructions I posted in the OP and you do not need to download the compiler from Qualcomm Developer Network. There are compilers in vendor/qcom/proprietary/llvm-arm-toolchain-ship, which are likely newer than the latest versions available here. When they are not, you can replace them and update vendor/qcom/proprietary/common/config/sdclang.json.
In sdclang.json, you can also check the default options for your platform. Some targets enable sdclang by default, others do not, you can define specific flags or compiler paths for each SoC.
Hi,
I tried to set it up as you explained but it seems that I did not compile the source code using the specified clang (sdclang).
When I was compiling, I saw that my process was still using clang-2690385 compilation, like this:
This problem is solved. But there are may errors in compilation. Maybe LineageOS is not suitable for Snapdragon LLVM Compiler?
Which version of the Snapdragon LLVM Compiler are you using? For Nougat, the 4.0 release will not work, so you will need the 3.8 version.
Great! It works as you say. Thanks a lot!
I'm trying to use this toolchain with OxygenOS 8.0 OREO, but I don't have the same file structure. I have: prebuilts/clang/host/linux-x86/(No sdclang-3.8) folder, so I can't implement this toolchain.
Without this toolchain though, I'm getting close to the same error as someone else in this thread, so I'm hoping someone can help me solve it.
Just FYI, OnePlus does not release the code for Oxygen OS. They do however, release source for a "AOSP" build based on Qualcomm's Code Aurora source, so builds you make will be missing the features of Oxygen OS.
Anyway, not sure which device you have, but OnePlus already inherits the sdclang json file, so it is already enabled as you can see here for OnePlus 5: https://github.com/OnePlusOSS/android_build/commit/666b51c4b116f58b176d0... or here for OnePlus 3: https://github.com/OnePlusOSS/android_build/commit/59ed0009ce3775fcfbe1d...
For the build error, it seems as though you don't have com.qualcomm.qti.Camera.jar, but they have it for 8996 here, which seems to be the target you're building: https://github.com/OnePlusOSS/android_vendor_oneplus_8996O/blob/oneplus/... so it looks like you may be missing some things in the vendor source.
For Nougat/Android 7.0 - we could confirm SDCLANG was used to compile the rom by entering below in a terminal window on the android device;
strings /system/lib/libeffects.so|grep -i 'gcc'
How do we check this for Oreo/Android 8.0?Thanks for the advice.
What is the proper set up required to compile with SDCLANG for ANY Oreo/Android 8.0 rom? Have tried configuring/copying sdclang.json to device folder and to vendor/qcom/proprietary/common/config/ and still found only default CLANG used.
That only works if your target name is the same as the board name, such as if you build the standard QC device trees. If you use your own naming, you need to add a rule for your device in sdclang.json or change the default settings in it.
Please who can help me !
Im compiling crDoid Oreo 8.1 rom but has problem:
When vendor apks set LOCAL_CERTIFICATE := platform => rom booloop
I must set to LOCAL_CERTIFICATE := PRESIGNED => rom boot complate but VoLTE brocken
What's problem ? Compiled RR work everything with LOCAL_CERTIFICATE := platform but others No
Thanks
How I can fix this? I am try compile msm8916_64 oreo.
im compiling 8.1 oreo. the build is successful with no error. so i grep libc for clang/snapdragon:
I set up the LLVM version 3.8.4 as stated in the first post and I can confirm that the build process is working if it's done without the Snapdragon LLVM.
Could you please help me to solve this issue?
Does Qualcomm provide a link to download versions of the Snapdragon LLVM older than 4.0.2 (which is the current at the time of writing)?
Thank you in advance
Snapdragon LLVM ARM 3.8.4 is an old version (from Oct 2016) that is no longer supported.
Please move to the latest, supported SDLLVM toolchain availabe on QDN, which is version 4.0.2.
https://developer.qualcomm.com/download/software
Paul
Dear Paul,
Thanks for your reply!
I moved to 4.0.2 version as you suggested and I got these errors:
As you may notice, these are the same errors in which @x565178035 ran into, as described in this post https://developer.qualcomm.com/comment/14087#comment-14087. That's why I thought that the version 4.0.2 was somehow incompatible with Android 7.1.2.
Could you please help me to undestand how to solve these errors?
Thank you for your advice,
Joseph
Hi Joseph,
We can take a look at your original failure (fatal error: error in backend), which is using SDLLVM 3.8.4. We look to see if there's a workaround, etc. No guarantees. To get started, we need the pre-processed file from the failed compile command. Please run the failing compile command and add '-save-temps' to the end of the command. This will generate a preprocesed file (*.i). Please send that to us and we'll take a look.
Thanks, Paul
-----
/bin/bash -c "(PWD=/proc/self/cwd /usr/bin/ccache prebuilts/clang/linux-x86/host/sdclang-3.8/bin/clang -Wno-vectorizer-no-neon -I device/oneplus/oneplus2/include -I bionic/libc/include -I external/ffmpeg/libavcodec/../android/include -I external/ffmpeg/libavcodec/../ -I external/zlib -I external/ffmpeg/libavcodec
...
...
-o /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.o external/ffmpeg/libavcodec/vp9dsp_8bpp.c ) -save-temps
Dear Paul,
First of all I would like to thank you for your reply.
I issued the failing command with the -save-temps option at the end, as you described, but I can't find the preprocessed file with the usual .i extension. I thought these kind of file were put in the output directory, such as the dependencies .d files, but when I searched for them in /android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/ I couldn't find any .i file. I also made a research in all the /lineage subfolders with the same result.
That's how I issued the command:
Since I wasn't sure if I had to issue the command including only the first part of the string (the part before the &&), I also tried in this way:
(I just added the " to close the string and then the -save-temps option.)
Finally I checked out the /tmp directory as the final part of the error points out:
Hi Joseph,
You will need to add the -save-temps option at the end of the compile command, just after the source file name (vp9dsp_8bpp.c ), like below.
The *.i file will be in the same directory that you 're in when running the compile command. Let me know if this works
Thanks, Paul
/bin/bash -c "(PWD=/proc/self/cwd /usr/bin/ccache prebuilts/clang/linux-x86/host/sdclang-3.8/bin/clang -Wno-vectorizer-no-neon -I device/oneplus/oneplus2/include -I bionic/libc/include -I external/ffmpeg/libavcodec/../android/include -I external/ffmpeg/libavcodec/../ -I external/zlib -I external/ffmpeg/libavcodec -I /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates -I /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/gen/SHARED_LIBRARIES/libavcodec_intermediates -I libnativehelper/include/nativehelper \$(cat /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/import_includes) -isystem system/core/include -isystem system/media/audio/include -isystem hardware/libhardware/include -isystem hardware/libhardware_legacy/include -isystem libnativehelper/include -isystem frameworks/native/include -isystem frameworks/native/opengl/include -isystem frameworks/av/include -isystem frameworks/base/include -isystem hardware/ril/include -isystem /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/include -isystem bionic/libc/arch-arm64/include -isystem bionic/libc/kernel/uapi -isystem bionic/libc/kernel/common -isystem bionic/libc/kernel/uapi/asm-arm64 -isystem bionic/libm/include -isystem bionic/libm/include/arm64 -c -fno-exceptions -Wno-multichar -fno-strict-aliasing -fstack-protector-strong -ffunction-sections -fdata-sections -funwind-tables -Wa,--noexecstack -Werror=format-security -D_FORTIFY_SOURCE=2 -fno-short-enums -no-canonical-prefixes -mcpu=cortex-a53 -Werror=pointer-to-int-cast -Werror=int-to-pointer-cast -Werror=implicit-function-declaration -DQCOM_HARDWARE -DQCOM_BSP -DQTI_BSP -DHAS_EXTRA_FLAC_METADATA -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Werror=date-time -DNDEBUG -O2 -g -Wstrict-aliasing=2 -DNDEBUG -UDEBUG -D__compiler_offsetof=__builtin_offsetof -Werror=int-conversion -Wno-reserved-id-macro -Wno-format-pedantic -Wno-unused-command-line-argument -fcolor-diagnostics -nostdlibinc -target aarch64-linux-android -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -std=gnu99 -DANDROID_SDK_VERSION=25 -DTARGET_CONFIG=\\\"config-armv8-a.h\\\" -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DPIC -O3 -std=c99 -fno-math-errno -fno-signed-zeros -fomit-frame-pointer -Wno-pointer-to-int-cast -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -Wno-unused-parameter -Wno-unknown-attributes -Wno-missing-field-initializers -Wno-sign-compare -Werror=format-security -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type -Werror=vla -Wformat -fPIC -fPIC -D_USING_LIBCXX -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -Werror=address-of-temporary -Werror=null-dereference -Werror=return-type -MD -MF /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.d -o /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.o external/ffmpeg/libavcodec/vp9dsp_8bpp.c -save-temps) && (cp /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.d /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.P; sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\\\\$//' -e '/^\$/ d' -e 's/\$/ :/' < /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.d >> /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.P; rm -f /media/giuseppe/Dati/LineageOS14.1_ARM64/android/lineage/out/target/product/oneplus2/obj/SHARED_LIBRARIES/libavcodec_intermediates/vp9dsp_8bpp.d )"
Dear Paul,
It worked great as you wrote!
The following is the content of the vp9dsp_8bpp.i file:
Dear Paul,
Thanks for you precious advice and for all the time spent on that file. Just to be sure: are you suggesting me to try to issue the build command with the 4.0.2 compiler set, plus adding the -Wno-error=expansion-to-defined option?
I'll check this out as soon as I can and post here my results.
Sincerely,
Joseph
Yes, I'm suggesting that you switch back to the SDLLVM 4.0.2 toolchain and use the '-Wno-error=xxx' flags to see if you can get further in the build experiment.
Paul
Dear Paul,
I changed my build environment and I built LineageOS 15.1, wich is based on Android 8.1, with the 4.0.2 LLVM set. The result is a working build, compiled without errors. However, how can I check if the OS was actually compiled with the QC LLVM?
Sincerely,
Joseph
Hi Joseph,
If you are buiding with the verbose option turned on, i.e., make showcommands, then you can verify by searching for the path to the Snapdragon LLVM compiler in the build log.
If you didn't build with 'showcommands', you can also run the following command to verify the compiler version used on a representative OS '.o' or '.so' file.
$ readelf -p .comment out/target/product/...../libjpeg.so | grep "Snapdragon"
[ 1] Snapdragon LLVM ARM Compiler 4.0.2 for Android NDK (based on llvm.org 4.0)
Paul
Hi Paul,
After some time spent trying to undestand if the LLVM was used in the build process, I couldn't find any trace both in the .so and .o files or in the log file of the build. I don't truly undestand why LineageOS 15.1 ignores the compiler.
I would like to thank you for your support and for all the time you dedicated to my efforts. Guess that I'm going to pause this project for some time.
Sincerely,
Joseph
Hello,
With respect to this topic, I have used Snapdragon Qualcomm LLVM/clang in building Andrioid Linux ARM(32-bit) hammerhead kernel for my Nexus 5 smartphone and I have succeeded in building it as well as bringing it up on the same Nexus 5. For the interested ones, I have shared my successful research and accomplishment details here : Success: Bring-up of LLVM/clang-built Linux ARM(32-bit) kernel for Android - Nexus 5
Cheers
Pages